diff options
author | 2024-06-06 11:16:20 -0700 | |
---|---|---|
committer | 2024-06-06 20:16:20 +0200 | |
commit | e605788b4bd624d68c6a499b943f186c9ac3ebe3 (patch) | |
tree | df25b2f67f5620ef4cd4a18195629c1b8b1bc4ad /internal | |
parent | [feature] User muting (#2960) (diff) | |
download | gotosocial-e605788b4bd624d68c6a499b943f186c9ac3ebe3.tar.xz |
[bugfix] Filter fixes (#2971)
* Add Filter.Expired convenience method, consistent with mutes
* Add missing Swagger for filter keyword/status delete and for 403s on moved accounts
Diffstat (limited to 'internal')
-rw-r--r-- | internal/api/client/filters/v1/filterpost.go | 2 | ||||
-rw-r--r-- | internal/api/client/filters/v1/filterput.go | 2 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterkeyworddelete.go | 36 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterkeywordpost.go | 2 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterkeywordput.go | 2 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterpost.go | 2 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterput.go | 2 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterstatusdelete.go | 36 | ||||
-rw-r--r-- | internal/api/client/filters/v2/filterstatuspost.go | 2 | ||||
-rw-r--r-- | internal/gtsmodel/filter.go | 6 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 3 |
11 files changed, 93 insertions, 2 deletions
diff --git a/internal/api/client/filters/v1/filterpost.go b/internal/api/client/filters/v1/filterpost.go index 9d92b9187..95a810f8b 100644 --- a/internal/api/client/filters/v1/filterpost.go +++ b/internal/api/client/filters/v1/filterpost.go @@ -117,6 +117,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/api/client/filters/v1/filterput.go b/internal/api/client/filters/v1/filterput.go index 2a81f89fc..60915624e 100644 --- a/internal/api/client/filters/v1/filterput.go +++ b/internal/api/client/filters/v1/filterput.go @@ -123,6 +123,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/api/client/filters/v2/filterkeyworddelete.go b/internal/api/client/filters/v2/filterkeyworddelete.go index 41ef12bfb..e9ba2b4c5 100644 --- a/internal/api/client/filters/v2/filterkeyworddelete.go +++ b/internal/api/client/filters/v2/filterkeyworddelete.go @@ -26,6 +26,42 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) +// FilterKeywordDELETEHandler swagger:operation DELETE /api/v2/filters/keywords/{id} filterKeywordDelete +// +// Delete a single filter keyword with the given ID. +// +// --- +// tags: +// - filters +// +// produces: +// - application/json +// +// parameters: +// - +// name: id +// type: string +// description: ID of the filter keyword +// in: path +// required: true +// +// security: +// - OAuth2 Bearer: +// - write:filters +// +// responses: +// '200': +// description: filter keyword deleted +// '400': +// description: bad request +// '401': +// description: unauthorized +// '404': +// description: not found +// '406': +// description: not acceptable +// '500': +// description: internal server error func (m *Module) FilterKeywordDELETEHandler(c *gin.Context) { authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/filters/v2/filterkeywordpost.go b/internal/api/client/filters/v2/filterkeywordpost.go index 7ec595820..fab7dc812 100644 --- a/internal/api/client/filters/v2/filterkeywordpost.go +++ b/internal/api/client/filters/v2/filterkeywordpost.go @@ -87,6 +87,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/api/client/filters/v2/filterkeywordput.go b/internal/api/client/filters/v2/filterkeywordput.go index 5ef0fe976..44667660f 100644 --- a/internal/api/client/filters/v2/filterkeywordput.go +++ b/internal/api/client/filters/v2/filterkeywordput.go @@ -84,6 +84,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/api/client/filters/v2/filterpost.go b/internal/api/client/filters/v2/filterpost.go index cbe499fa6..9e8f87fd0 100644 --- a/internal/api/client/filters/v2/filterpost.go +++ b/internal/api/client/filters/v2/filterpost.go @@ -115,6 +115,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/api/client/filters/v2/filterput.go b/internal/api/client/filters/v2/filterput.go index e24ec0b4d..24071a150 100644 --- a/internal/api/client/filters/v2/filterput.go +++ b/internal/api/client/filters/v2/filterput.go @@ -111,6 +111,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/api/client/filters/v2/filterstatusdelete.go b/internal/api/client/filters/v2/filterstatusdelete.go index e10125a32..5a03b9a7c 100644 --- a/internal/api/client/filters/v2/filterstatusdelete.go +++ b/internal/api/client/filters/v2/filterstatusdelete.go @@ -26,6 +26,42 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) +// FilterStatusDELETEHandler swagger:operation DELETE /api/v2/filters/statuses/{id} filterStatusDelete +// +// Delete a single filter status with the given ID. +// +// --- +// tags: +// - filters +// +// produces: +// - application/json +// +// parameters: +// - +// name: id +// type: string +// description: ID of the filter status +// in: path +// required: true +// +// security: +// - OAuth2 Bearer: +// - write:filters +// +// responses: +// '200': +// description: filter status deleted +// '400': +// description: bad request +// '401': +// description: unauthorized +// '404': +// description: not found +// '406': +// description: not acceptable +// '500': +// description: internal server error func (m *Module) FilterStatusDELETEHandler(c *gin.Context) { authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/filters/v2/filterstatuspost.go b/internal/api/client/filters/v2/filterstatuspost.go index 2a763197d..deef54a9c 100644 --- a/internal/api/client/filters/v2/filterstatuspost.go +++ b/internal/api/client/filters/v2/filterstatuspost.go @@ -75,6 +75,8 @@ import ( // description: bad request // '401': // description: unauthorized +// '403': +// description: forbidden to moved accounts // '404': // description: not found // '406': diff --git a/internal/gtsmodel/filter.go b/internal/gtsmodel/filter.go index b1e8f5cac..e670e6fc0 100644 --- a/internal/gtsmodel/filter.go +++ b/internal/gtsmodel/filter.go @@ -40,6 +40,12 @@ type Filter struct { ContextAccount *bool `bun:",nullzero,notnull,default:false"` // Apply filter when viewing an account profile. } +// Expired returns whether the filter has expired at a given time. +// Filters without an expiration timestamp never expire. +func (f *Filter) Expired(now time.Time) bool { + return !f.ExpiresAt.IsZero() && !f.ExpiresAt.After(now) +} + // FilterKeyword stores a single keyword to filter statuses against. type FilterKeyword struct { ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 787d8f099..f3c027316 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -838,8 +838,7 @@ func (c *Converter) statusToAPIFilterResults( // Filter doesn't apply to this context. continue } - if !filter.ExpiresAt.IsZero() && filter.ExpiresAt.Before(now) { - // Filter is expired. + if filter.Expired(now) { continue } |