summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-11-28 11:54:22 +0000
committerLibravatar GitHub <noreply@github.com>2024-11-28 12:54:22 +0100
commit312cb8b9c7e13802613fef33124a4570427e75a7 (patch)
tree68f3efe630a8e93e09be2ea34b929a14c64184eb /internal/api
parent[bugfix] Log + ignore unknown notification types (#3577) (diff)
downloadgotosocial-312cb8b9c7e13802613fef33124a4570427e75a7.tar.xz
[chore] rename New___(string) int signature functions to Parse___(string) int (#3580)
* rename New___(string) int {} signature functions to Parse___(string) int {} * remove test output
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/admin/domainpermissiondraftsget.go14
-rw-r--r--internal/api/client/notifications/notificationsget.go12
2 files changed, 11 insertions, 15 deletions
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
}