diff --git a/internal/api/client/admin/domainpermissiondraftsget.go b/internal/api/client/admin/domainpermissiondraftsget.go index dd3315857..d63179afc 100644 --- a/internal/api/client/admin/domainpermissiondraftsget.go +++ b/internal/api/client/admin/domainpermissiondraftsget.go @@ -147,16 +147,12 @@ func (m *Module) DomainPermissionDraftsGETHandler(c *gin.Context) { return } - permType := c.Query(apiutil.DomainPermissionPermTypeKey) - switch permType { - case "", "block", "allow": - // No problem. - - default: - // Invalid. + permTypeStr := c.Query(apiutil.DomainPermissionPermTypeKey) + permType := gtsmodel.ParseDomainPermissionType(permTypeStr) + if permType == gtsmodel.DomainPermissionUnknown { text := fmt.Sprintf( "permission_type %s not recognized, valid values are empty string, block, or allow", - permType, + permTypeStr, ) errWithCode := gtserror.NewErrorBadRequest(errors.New(text), text) apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) @@ -173,7 +169,7 @@ func (m *Module) DomainPermissionDraftsGETHandler(c *gin.Context) { c.Request.Context(), c.Query(apiutil.DomainPermissionSubscriptionIDKey), c.Query(apiutil.DomainPermissionDomainKey), - gtsmodel.NewDomainPermissionType(permType), + permType, page, ) if errWithCode != nil { diff --git a/internal/api/client/notifications/notificationsget.go b/internal/api/client/notifications/notificationsget.go index 7caadbe7d..b530c515d 100644 --- a/internal/api/client/notifications/notificationsget.go +++ b/internal/api/client/notifications/notificationsget.go @@ -169,8 +169,8 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) { ctx, authed, page, - ParseNotificationTypes(ctx, c.QueryArray(TypesKey)), // Include types. - ParseNotificationTypes(ctx, c.QueryArray(ExcludeTypesKey)), // Exclude types. + parseNotificationTypes(ctx, c.QueryArray(TypesKey)), // Include types. + parseNotificationTypes(ctx, c.QueryArray(ExcludeTypesKey)), // Exclude types. ) if errWithCode != nil { apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) @@ -184,9 +184,9 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) { apiutil.JSON(c, http.StatusOK, resp.Items) } -// ParseNotificationTypes converts the given slice of string values +// parseNotificationTypes converts the given slice of string values // to gtsmodel notification types, logging + skipping unknown types. -func ParseNotificationTypes( +func parseNotificationTypes( ctx context.Context, values []string, ) []gtsmodel.NotificationType { @@ -196,10 +196,10 @@ func ParseNotificationTypes( ntypes := make([]gtsmodel.NotificationType, 0, len(values)) for _, value := range values { - ntype := gtsmodel.NewNotificationType(value) + ntype := gtsmodel.ParseNotificationType(value) if ntype == gtsmodel.NotificationUnknown { // Type we don't know about (yet), log and ignore it. - log.Debugf(ctx, "ignoring unknown type %s", value) + log.Warnf(ctx, "ignoring unknown type %s", value) continue } diff --git a/internal/db/bundb/migrations/20230828101322_admin_action_locking.go b/internal/db/bundb/migrations/20230828101322_admin_action_locking.go index b72976cc9..29c29a747 100644 --- a/internal/db/bundb/migrations/20230828101322_admin_action_locking.go +++ b/internal/db/bundb/migrations/20230828101322_admin_action_locking.go @@ -77,7 +77,7 @@ func init() { UpdatedAt: oldAction.UpdatedAt, TargetCategory: gtsmodel.AdminActionCategoryAccount, TargetID: oldAction.TargetAccountID, - Type: gtsmodel.NewAdminActionType(string(oldAction.Type)), + Type: gtsmodel.ParseAdminActionType(string(oldAction.Type)), AccountID: oldAction.AccountID, Text: oldAction.Text, SendEmail: util.Ptr(oldAction.SendEmail), diff --git a/internal/gtsmodel/adminaction.go b/internal/gtsmodel/adminaction.go index e8b82e495..5ca8244a0 100644 --- a/internal/gtsmodel/adminaction.go +++ b/internal/gtsmodel/adminaction.go @@ -19,6 +19,7 @@ package gtsmodel import ( "path" + "strings" "time" ) @@ -46,8 +47,8 @@ func (c AdminActionCategory) String() string { } } -func NewAdminActionCategory(in string) AdminActionCategory { - switch in { +func ParseAdminActionCategory(in string) AdminActionCategory { + switch strings.ToLower(in) { case "account": return AdminActionCategoryAccount case "domain": @@ -96,8 +97,8 @@ func (t AdminActionType) String() string { } } -func NewAdminActionType(in string) AdminActionType { - switch in { +func ParseAdminActionType(in string) AdminActionType { + switch strings.ToLower(in) { case "disable": return AdminActionDisable case "reenable": diff --git a/internal/gtsmodel/domainpermission.go b/internal/gtsmodel/domainpermission.go index 3d1ee873f..f1db4de59 100644 --- a/internal/gtsmodel/domainpermission.go +++ b/internal/gtsmodel/domainpermission.go @@ -17,7 +17,10 @@ package gtsmodel -import "time" +import ( + "strings" + "time" +) // DomainPermission models a domain permission // entry -- block / allow / draft / exclude. @@ -62,8 +65,8 @@ func (p DomainPermissionType) String() string { } } -func NewDomainPermissionType(in string) DomainPermissionType { - switch in { +func ParseDomainPermissionType(in string) DomainPermissionType { + switch strings.ToLower(in) { case "block": return DomainPermissionBlock case "allow": diff --git a/internal/gtsmodel/notification.go b/internal/gtsmodel/notification.go index 47bf7daa5..1ef805081 100644 --- a/internal/gtsmodel/notification.go +++ b/internal/gtsmodel/notification.go @@ -87,8 +87,8 @@ func (t NotificationType) String() string { } } -// NewNotificationType returns a notification type from the given value. -func NewNotificationType(in string) NotificationType { +// ParseNotificationType returns a notification type from the given value. +func ParseNotificationType(in string) NotificationType { switch strings.ToLower(in) { case "follow": return NotificationFollow diff --git a/internal/processing/admin/accountaction.go b/internal/processing/admin/accountaction.go index 7fd1047c4..59d4b420e 100644 --- a/internal/processing/admin/accountaction.go +++ b/internal/processing/admin/accountaction.go @@ -40,7 +40,7 @@ func (p *Processor) AccountAction( return "", gtserror.NewErrorInternalError(err) } - switch gtsmodel.NewAdminActionType(request.Type) { + switch gtsmodel.ParseAdminActionType(request.Type) { case gtsmodel.AdminActionSuspend: return p.accountActionSuspend(ctx, adminAcct, targetAcct, request.Text) diff --git a/test.out b/test.out new file mode 100644 index 000000000..08d3b115b --- /dev/null +++ b/test.out @@ -0,0 +1,154 @@ +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/account [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/media/prune [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/trans [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/media [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/debug/config [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/server [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/testrig [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/process-emoji [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action [no test files] +? github.com/superseriousbusiness/gotosocial/cmd/process-media [no test files] +? github.com/superseriousbusiness/gotosocial/docs [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/activitypub/publickey [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/ap 8.763s +ok github.com/superseriousbusiness/gotosocial/internal/api/activitypub/emoji 10.517s +? github.com/superseriousbusiness/gotosocial/internal/api/client/apps [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/blocks [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/conversations [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/customemojis [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/featuredtags [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/api/activitypub/users 28.645s +ok github.com/superseriousbusiness/gotosocial/internal/api/auth 13.964s +? github.com/superseriousbusiness/gotosocial/internal/api/client/interactionpolicies [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/interactionrequests [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/markers [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/preferences [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/client/timelines [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/health [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/metrics [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/nodeinfo [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/wellknown/hostmeta [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/model [no test files] +? github.com/superseriousbusiness/gotosocial/internal/api/wellknown/nodeinfo [no test files] +? github.com/superseriousbusiness/gotosocial/internal/cache [no test files] +? github.com/superseriousbusiness/gotosocial/internal/cache/headerfilter [no test files] +? github.com/superseriousbusiness/gotosocial/internal/config/gen [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20211113114307_init [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20220214175650_media_cleanup [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20220315160814_admin_account_actions [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20220905150505_custom_emoji_updates [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240126064004_add_filters [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240318115336_account_settings [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240620074530_interaction_policy [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240715204203_media_pipeline_improvements [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20240904084406_fedi_api_reject_interaction [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20231002153327_add_status_polls [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20230328203024_migration_fix [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20241121121623_enum_strings_to_ints [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/test [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/postgres [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/sqlite [no test files] +? github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20230521105850_emoji_empty_domain_fix [no test files] +? github.com/superseriousbusiness/gotosocial/internal/filter/interaction [no test files] +? github.com/superseriousbusiness/gotosocial/internal/filter/status [no test files] +? github.com/superseriousbusiness/gotosocial/internal/filter/usermute [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/api/client/accounts 115.038s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/admin 68.928s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/bookmarks 18.391s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/exports 13.495s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/favourites 14.555s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/filters/v1 53.654s +? github.com/superseriousbusiness/gotosocial/internal/gtscontext [no test files] +? github.com/superseriousbusiness/gotosocial/internal/gtsmodel [no test files] +? github.com/superseriousbusiness/gotosocial/internal/headerfilter [no test files] +? github.com/superseriousbusiness/gotosocial/internal/id [no test files] +? github.com/superseriousbusiness/gotosocial/internal/iotools [no test files] +? github.com/superseriousbusiness/gotosocial/internal/media/ffmpeg [no test files] +? github.com/superseriousbusiness/gotosocial/internal/metrics [no test files] +? github.com/superseriousbusiness/gotosocial/internal/oidc [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/advancedmigrations [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/common [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/fedi [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/filters/v1 [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/filters/v2 [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/list [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/markers [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/api/client/filters/v2 134.694s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/followedtags 14.964s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/followrequests 29.937s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/import 16.076s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/instance 40.109s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/lists 22.328s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/media 24.149s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/mutes 17.946s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/notifications 19.233s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/polls 19.553s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/reports 49.345s +? github.com/superseriousbusiness/gotosocial/internal/processing/report [no test files] +? github.com/superseriousbusiness/gotosocial/internal/processing/search [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/api/client/search 91.868s +? github.com/superseriousbusiness/gotosocial/internal/processing/tags [no test files] +? github.com/superseriousbusiness/gotosocial/internal/queue [no test files] +? github.com/superseriousbusiness/gotosocial/internal/regexes [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/api/client/statuses 105.293s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/streaming 17.060s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/tags 32.038s +ok github.com/superseriousbusiness/gotosocial/internal/api/client/user 39.114s +ok github.com/superseriousbusiness/gotosocial/internal/api/fileserver 32.111s +ok github.com/superseriousbusiness/gotosocial/internal/api/util 0.026s +ok github.com/superseriousbusiness/gotosocial/internal/api/wellknown/webfinger 32.587s +ok github.com/superseriousbusiness/gotosocial/internal/cache/domain 0.003s +ok github.com/superseriousbusiness/gotosocial/internal/cleaner 41.137s +ok github.com/superseriousbusiness/gotosocial/internal/config 20.233s +? github.com/superseriousbusiness/gotosocial/internal/scheduler [no test files] +? github.com/superseriousbusiness/gotosocial/internal/state [no test files] +? github.com/superseriousbusiness/gotosocial/internal/storage [no test files] +? github.com/superseriousbusiness/gotosocial/internal/stream [no test files] +? github.com/superseriousbusiness/gotosocial/internal/tracing [no test files] +? github.com/superseriousbusiness/gotosocial/internal/trans/model [no test files] +? github.com/superseriousbusiness/gotosocial/internal/uris [no test files] +? github.com/superseriousbusiness/gotosocial/internal/web [no test files] +? github.com/superseriousbusiness/gotosocial/internal/workers [no test files] +? github.com/superseriousbusiness/gotosocial/testrig [no test files] +ok github.com/superseriousbusiness/gotosocial/internal/db/bundb 176.042s +ok github.com/superseriousbusiness/gotosocial/internal/email 20.292s +ok github.com/superseriousbusiness/gotosocial/internal/federation 65.695s +ok github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing 86.735s +ok github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb 38.448s +ok github.com/superseriousbusiness/gotosocial/internal/filter/spam 21.883s +ok github.com/superseriousbusiness/gotosocial/internal/filter/visibility 43.203s +ok github.com/superseriousbusiness/gotosocial/internal/gtserror 0.021s +ok github.com/superseriousbusiness/gotosocial/internal/httpclient 0.022s +ok github.com/superseriousbusiness/gotosocial/internal/language 0.008s +ok github.com/superseriousbusiness/gotosocial/internal/log 20.521s +ok github.com/superseriousbusiness/gotosocial/internal/media 67.780s +ok github.com/superseriousbusiness/gotosocial/internal/messages 20.570s +ok github.com/superseriousbusiness/gotosocial/internal/middleware 38.017s +ok github.com/superseriousbusiness/gotosocial/internal/oauth 23.867s +ok github.com/superseriousbusiness/gotosocial/internal/paging 0.034s +ok github.com/superseriousbusiness/gotosocial/internal/processing 32.586s +ok github.com/superseriousbusiness/gotosocial/internal/processing/account 64.810s +ok github.com/superseriousbusiness/gotosocial/internal/processing/admin 57.986s +ok github.com/superseriousbusiness/gotosocial/internal/processing/conversations 34.642s +ok github.com/superseriousbusiness/gotosocial/internal/processing/interactionrequests 28.893s +ok github.com/superseriousbusiness/gotosocial/internal/processing/media 36.640s +ok github.com/superseriousbusiness/gotosocial/internal/processing/polls 24.968s +ok github.com/superseriousbusiness/gotosocial/internal/processing/status 44.098s +ok github.com/superseriousbusiness/gotosocial/internal/processing/stream 26.390s +ok github.com/superseriousbusiness/gotosocial/internal/processing/timeline 26.855s +ok github.com/superseriousbusiness/gotosocial/internal/processing/user 28.167s +ok github.com/superseriousbusiness/gotosocial/internal/processing/workers 128.199s +ok github.com/superseriousbusiness/gotosocial/internal/router 0.026s +ok github.com/superseriousbusiness/gotosocial/internal/text 49.493s +ok github.com/superseriousbusiness/gotosocial/internal/timeline 26.620s +ok github.com/superseriousbusiness/gotosocial/internal/trans 16.179s +ok github.com/superseriousbusiness/gotosocial/internal/transport 19.149s +ok github.com/superseriousbusiness/gotosocial/internal/transport/delivery 1.146s +ok github.com/superseriousbusiness/gotosocial/internal/typeutils 73.032s +ok github.com/superseriousbusiness/gotosocial/internal/util 11.216s +ok github.com/superseriousbusiness/gotosocial/internal/util/xslices 0.006s +ok github.com/superseriousbusiness/gotosocial/internal/validate 0.017s