mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-19 08:26:23 -07:00
Add button to clear hits for a filter (admin only)
This commit is contained in:
parent
bfbca50f81
commit
ec92e056fd
3 changed files with 39 additions and 20 deletions
|
@ -650,3 +650,10 @@ func GetFilterHits(filterID int) ([]FilterHit, error) {
|
|||
}
|
||||
return hits, rows.Close()
|
||||
}
|
||||
|
||||
// ClearFilterHits deletes the recorded match events for the given filter ID
|
||||
func ClearFilterHits(filterID int) error {
|
||||
const clearSQL = `DELETE FROM DBPREFIXfilter_hits WHERE filter_id = ?`
|
||||
_, err := ExecTimeoutSQL(nil, clearSQL, filterID)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ func appealsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
return manageAppealsBuffer.String(), err
|
||||
}
|
||||
|
||||
func filterHitsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staff, _ bool, _, errEv *zerolog.Event) (output any, err error) {
|
||||
func filterHitsCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, infoEv, errEv *zerolog.Event) (output any, err error) {
|
||||
params, _ := request.Context().Value(requestContextKey{}).(bunrouter.Params)
|
||||
filterIDStr := params.ByName("filterID")
|
||||
filterID, err := strconv.Atoi(filterIDStr)
|
||||
|
@ -185,6 +185,18 @@ func filterHitsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.S
|
|||
return nil, err
|
||||
}
|
||||
errEv.Int("filterID", filterID)
|
||||
fmt.Println("filterID:", filterID)
|
||||
if request.Method == http.MethodPost && request.PostFormValue("clearhits") == "Clear hits" {
|
||||
if staff.Rank < 3 {
|
||||
writer.WriteHeader(http.StatusForbidden)
|
||||
return nil, ErrInsufficientPermission
|
||||
}
|
||||
if err = gcsql.ClearFilterHits(filterID); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return nil, errors.New("unable to clear filter hits")
|
||||
}
|
||||
infoEv.Int("filterID", filterID)
|
||||
}
|
||||
|
||||
hits, err := gcsql.GetFilterHits(filterID)
|
||||
if err != nil {
|
||||
|
@ -212,6 +224,8 @@ func filterHitsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.S
|
|||
}
|
||||
var buf bytes.Buffer
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageFilterHits, map[string]any{
|
||||
"staff": staff,
|
||||
"filterID": filterID,
|
||||
"hits": hits,
|
||||
"hitsJSON": hitsJSON,
|
||||
}, &buf, "text/html"); err != nil {
|
||||
|
@ -792,11 +806,10 @@ func registerModeratorPages() {
|
|||
RegisterManagePage("bans", "Bans", ModPerms, NoJSON, bansCallback)
|
||||
RegisterManagePage("appeals", "Ban appeals", ModPerms, OptionalJSON, appealsCallback)
|
||||
RegisterManagePage("filters", "Post filters", ModPerms, NoJSON, filtersCallback)
|
||||
server.GetRouter().GET(config.WebPath("/manage/filters/hits/:filterID"), setupManageFunction(&Action{
|
||||
ID: "filters/hits",
|
||||
Title: "Filter hits",
|
||||
Callback: filterHitsCallback,
|
||||
}))
|
||||
|
||||
hitsFunc := setupManageFunction(&Action{ID: "filters/hits", Title: "Filter hits", Callback: filterHitsCallback})
|
||||
server.GetRouter().GET(config.WebPath("/manage/filters/hits/:filterID"), hitsFunc)
|
||||
server.GetRouter().POST(config.WebPath("/manage/filters/hits/:filterID"), hitsFunc)
|
||||
RegisterManagePage("ipsearch", "IP Search", ModPerms, NoJSON, ipSearchCallback)
|
||||
RegisterManagePage("reports", "Reports", ModPerms, OptionalJSON, reportsCallback)
|
||||
RegisterManagePage("threadattrs", "View/Update Thread Attributes", ModPerms, OptionalJSON, threadAttrsCallback)
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
<a href="{{webPath `/manage/filters/`}}">Back to filter list</a><br/>
|
||||
{{with .hits}}
|
||||
<a href="{{webPath `/manage/filters/`}}">Back to filter list</a> |
|
||||
<a href="{{webPath `/manage/filters/`}}?edit={{$.filterID}}">Edit filter</a><br/>
|
||||
{{- with .hits -}}
|
||||
{{if eq $.staff.Rank 3 -}}
|
||||
<form action="{{webPath `/manage/filters/hits`}}/{{$.filterID}}" method="POST">
|
||||
<input type="submit" name="clearhits" value="Clear hits" onclick="return confirm('Are you sure you want to clear this filter\'s hits?')" />
|
||||
</form>
|
||||
{{- end}}
|
||||
<table class="mgmt-table filterhitslist">
|
||||
<colgroup>
|
||||
<col class="filter-id">
|
||||
<col class="row-date">
|
||||
<col class="match-data">
|
||||
</colgroup>
|
||||
<tr><th>Filter ID</th><th>Match time</th><th>Post data</th></tr>
|
||||
{{range $h, $hit := .}}
|
||||
<tr>
|
||||
<td><a href="{{webPath `/manage/filters`}}?edit={{$hit.FilterID}}">{{$hit.FilterID}}</a></td>
|
||||
<td>{{formatTimestamp $hit.MatchTime}}</td>
|
||||
<td>{{index $.hitsJSON $h}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
<tr><th>Match time</th><th>Post data</th></tr>
|
||||
{{- range $h, $hit := . -}}
|
||||
<tr><td>{{formatTimestamp $hit.MatchTime}}</td><td>{{index $.hitsJSON $h}}</td></tr>
|
||||
{{- end -}}
|
||||
</table>
|
||||
{{else}}
|
||||
<i>No hits</i>
|
||||
{{end}}
|
||||
{{- else}}<i>No hits</i>{{end}}
|
Loading…
Add table
Add a link
Reference in a new issue