Skip to content

Commit

Permalink
[bugfix] Filter fixes (superseriousbusiness#2971)
Browse files Browse the repository at this point in the history
* Add Filter.Expired convenience method, consistent with mutes

* Add missing Swagger for filter keyword/status delete and for 403s on moved accounts
  • Loading branch information
VyrCossont authored and nyarla committed Jun 19, 2024
1 parent c482da9 commit c1862fc
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 2 deletions.
72 changes: 72 additions & 0 deletions docs/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6342,6 +6342,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand Down Expand Up @@ -6494,6 +6496,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand Down Expand Up @@ -9241,6 +9245,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand Down Expand Up @@ -9380,6 +9386,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand Down Expand Up @@ -9471,6 +9479,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand Down Expand Up @@ -9552,6 +9562,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand All @@ -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:
Expand Down Expand Up @@ -9641,6 +9682,8 @@ paths:
description: bad request
"401":
description: unauthorized
"403":
description: forbidden to moved accounts
"404":
description: not found
"406":
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v1/filterpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v1/filterput.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
36 changes: 36 additions & 0 deletions internal/api/client/filters/v2/filterkeyworddelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v2/filterkeywordpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v2/filterkeywordput.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v2/filterpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v2/filterput.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
36 changes: 36 additions & 0 deletions internal/api/client/filters/v2/filterstatusdelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/api/client/filters/v2/filterstatuspost.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import (
// description: bad request
// '401':
// description: unauthorized
// '403':
// description: forbidden to moved accounts
// '404':
// description: not found
// '406':
Expand Down
6 changes: 6 additions & 0 deletions internal/gtsmodel/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions internal/typeutils/internaltofrontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c1862fc

Please sign in to comment.