[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
This commit is contained in:
parent
5e2d4fdb19
commit
e605788b4b
|
@ -6342,6 +6342,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -6494,6 +6496,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -9241,6 +9245,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -9380,6 +9386,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -9471,6 +9479,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -9552,6 +9562,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -9569,6 +9581,35 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- filters
|
- filters
|
||||||
/api/v2/filters/keywords/{id}:
|
/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:
|
get:
|
||||||
operationId: filterKeywordGet
|
operationId: filterKeywordGet
|
||||||
parameters:
|
parameters:
|
||||||
|
@ -9641,6 +9682,8 @@ paths:
|
||||||
description: bad request
|
description: bad request
|
||||||
"401":
|
"401":
|
||||||
description: unauthorized
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden to moved accounts
|
||||||
"404":
|
"404":
|
||||||
description: not found
|
description: not found
|
||||||
"406":
|
"406":
|
||||||
|
@ -9658,6 +9701,35 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- filters
|
- filters
|
||||||
/api/v2/filters/statuses/{id}:
|
/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:
|
get:
|
||||||
operationId: filterStatusGet
|
operationId: filterStatusGet
|
||||||
parameters:
|
parameters:
|
||||||
|
|
|
@ -117,6 +117,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -123,6 +123,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -26,6 +26,42 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"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) {
|
func (m *Module) FilterKeywordDELETEHandler(c *gin.Context) {
|
||||||
authed, err := oauth.Authed(c, true, true, true, true)
|
authed, err := oauth.Authed(c, true, true, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -87,6 +87,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -84,6 +84,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -115,6 +115,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -111,6 +111,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -26,6 +26,42 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"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) {
|
func (m *Module) FilterStatusDELETEHandler(c *gin.Context) {
|
||||||
authed, err := oauth.Authed(c, true, true, true, true)
|
authed, err := oauth.Authed(c, true, true, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -75,6 +75,8 @@ import (
|
||||||
// description: bad request
|
// description: bad request
|
||||||
// '401':
|
// '401':
|
||||||
// description: unauthorized
|
// description: unauthorized
|
||||||
|
// '403':
|
||||||
|
// description: forbidden to moved accounts
|
||||||
// '404':
|
// '404':
|
||||||
// description: not found
|
// description: not found
|
||||||
// '406':
|
// '406':
|
||||||
|
|
|
@ -40,6 +40,12 @@ type Filter struct {
|
||||||
ContextAccount *bool `bun:",nullzero,notnull,default:false"` // Apply filter when viewing an account profile.
|
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.
|
// FilterKeyword stores a single keyword to filter statuses against.
|
||||||
type FilterKeyword struct {
|
type FilterKeyword struct {
|
||||||
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database
|
ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database
|
||||||
|
|
|
@ -838,8 +838,7 @@ func (c *Converter) statusToAPIFilterResults(
|
||||||
// Filter doesn't apply to this context.
|
// Filter doesn't apply to this context.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !filter.ExpiresAt.IsZero() && filter.ExpiresAt.Before(now) {
|
if filter.Expired(now) {
|
||||||
// Filter is expired.
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue