summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2024-06-06 11:16:20 -0700
committerLibravatar GitHub <noreply@github.com>2024-06-06 20:16:20 +0200
commite605788b4bd624d68c6a499b943f186c9ac3ebe3 (patch)
treedf25b2f67f5620ef4cd4a18195629c1b8b1bc4ad
parent[feature] User muting (#2960) (diff)
downloadgotosocial-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
-rw-r--r--docs/api/swagger.yaml72
-rw-r--r--internal/api/client/filters/v1/filterpost.go2
-rw-r--r--internal/api/client/filters/v1/filterput.go2
-rw-r--r--internal/api/client/filters/v2/filterkeyworddelete.go36
-rw-r--r--internal/api/client/filters/v2/filterkeywordpost.go2
-rw-r--r--internal/api/client/filters/v2/filterkeywordput.go2
-rw-r--r--internal/api/client/filters/v2/filterpost.go2
-rw-r--r--internal/api/client/filters/v2/filterput.go2
-rw-r--r--internal/api/client/filters/v2/filterstatusdelete.go36
-rw-r--r--internal/api/client/filters/v2/filterstatuspost.go2
-rw-r--r--internal/gtsmodel/filter.go6
-rw-r--r--internal/typeutils/internaltofrontend.go3
12 files changed, 165 insertions, 2 deletions
diff --git a/docs/api/swagger.yaml b/docs/api/swagger.yaml
index 05f127d55..3946a37ce 100644
--- a/docs/api/swagger.yaml
+++ b/docs/api/swagger.yaml
@@ -6342,6 +6342,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -6494,6 +6496,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -9241,6 +9245,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -9380,6 +9386,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -9471,6 +9479,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -9552,6 +9562,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -9569,6 +9581,35 @@ paths:
tags:
- filters
/api/v2/filters/keywords/{id}:
+ delete:
+ operationId: filterKeywordDelete
+ parameters:
+ - description: ID of the filter keyword
+ in: path
+ name: id
+ required: true
+ type: string
+ produces:
+ - application/json
+ 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
+ security:
+ - OAuth2 Bearer:
+ - write:filters
+ summary: Delete a single filter keyword with the given ID.
+ tags:
+ - filters
get:
operationId: filterKeywordGet
parameters:
@@ -9641,6 +9682,8 @@ paths:
description: bad request
"401":
description: unauthorized
+ "403":
+ description: forbidden to moved accounts
"404":
description: not found
"406":
@@ -9658,6 +9701,35 @@ paths:
tags:
- filters
/api/v2/filters/statuses/{id}:
+ delete:
+ operationId: filterStatusDelete
+ parameters:
+ - description: ID of the filter status
+ in: path
+ name: id
+ required: true
+ type: string
+ produces:
+ - application/json
+ 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
+ security:
+ - OAuth2 Bearer:
+ - write:filters
+ summary: Delete a single filter status with the given ID.
+ tags:
+ - filters
get:
operationId: filterStatusGet
parameters:
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
}