mirror of
https://codeberg.org/superseriousbusiness/gotosocial.git
synced 2024-12-20 08:01:50 +03:00
[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
This commit is contained in:
parent
65917f5bb9
commit
312cb8b9c7
7 changed files with 26 additions and 26 deletions
|
@ -147,16 +147,12 @@ func (m *Module) DomainPermissionDraftsGETHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
permType := c.Query(apiutil.DomainPermissionPermTypeKey)
|
permTypeStr := c.Query(apiutil.DomainPermissionPermTypeKey)
|
||||||
switch permType {
|
permType := gtsmodel.ParseDomainPermissionType(permTypeStr)
|
||||||
case "", "block", "allow":
|
if permType == gtsmodel.DomainPermissionUnknown {
|
||||||
// No problem.
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Invalid.
|
|
||||||
text := fmt.Sprintf(
|
text := fmt.Sprintf(
|
||||||
"permission_type %s not recognized, valid values are empty string, block, or allow",
|
"permission_type %s not recognized, valid values are empty string, block, or allow",
|
||||||
permType,
|
permTypeStr,
|
||||||
)
|
)
|
||||||
errWithCode := gtserror.NewErrorBadRequest(errors.New(text), text)
|
errWithCode := gtserror.NewErrorBadRequest(errors.New(text), text)
|
||||||
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
||||||
|
@ -173,7 +169,7 @@ func (m *Module) DomainPermissionDraftsGETHandler(c *gin.Context) {
|
||||||
c.Request.Context(),
|
c.Request.Context(),
|
||||||
c.Query(apiutil.DomainPermissionSubscriptionIDKey),
|
c.Query(apiutil.DomainPermissionSubscriptionIDKey),
|
||||||
c.Query(apiutil.DomainPermissionDomainKey),
|
c.Query(apiutil.DomainPermissionDomainKey),
|
||||||
gtsmodel.NewDomainPermissionType(permType),
|
permType,
|
||||||
page,
|
page,
|
||||||
)
|
)
|
||||||
if errWithCode != nil {
|
if errWithCode != nil {
|
||||||
|
|
|
@ -169,8 +169,8 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
|
||||||
ctx,
|
ctx,
|
||||||
authed,
|
authed,
|
||||||
page,
|
page,
|
||||||
ParseNotificationTypes(ctx, c.QueryArray(TypesKey)), // Include types.
|
parseNotificationTypes(ctx, c.QueryArray(TypesKey)), // Include types.
|
||||||
ParseNotificationTypes(ctx, c.QueryArray(ExcludeTypesKey)), // Exclude types.
|
parseNotificationTypes(ctx, c.QueryArray(ExcludeTypesKey)), // Exclude types.
|
||||||
)
|
)
|
||||||
if errWithCode != nil {
|
if errWithCode != nil {
|
||||||
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
|
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)
|
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.
|
// to gtsmodel notification types, logging + skipping unknown types.
|
||||||
func ParseNotificationTypes(
|
func parseNotificationTypes(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
values []string,
|
values []string,
|
||||||
) []gtsmodel.NotificationType {
|
) []gtsmodel.NotificationType {
|
||||||
|
@ -196,10 +196,10 @@ func ParseNotificationTypes(
|
||||||
|
|
||||||
ntypes := make([]gtsmodel.NotificationType, 0, len(values))
|
ntypes := make([]gtsmodel.NotificationType, 0, len(values))
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
ntype := gtsmodel.NewNotificationType(value)
|
ntype := gtsmodel.ParseNotificationType(value)
|
||||||
if ntype == gtsmodel.NotificationUnknown {
|
if ntype == gtsmodel.NotificationUnknown {
|
||||||
// Type we don't know about (yet), log and ignore it.
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ func init() {
|
||||||
UpdatedAt: oldAction.UpdatedAt,
|
UpdatedAt: oldAction.UpdatedAt,
|
||||||
TargetCategory: gtsmodel.AdminActionCategoryAccount,
|
TargetCategory: gtsmodel.AdminActionCategoryAccount,
|
||||||
TargetID: oldAction.TargetAccountID,
|
TargetID: oldAction.TargetAccountID,
|
||||||
Type: gtsmodel.NewAdminActionType(string(oldAction.Type)),
|
Type: gtsmodel.ParseAdminActionType(string(oldAction.Type)),
|
||||||
AccountID: oldAction.AccountID,
|
AccountID: oldAction.AccountID,
|
||||||
Text: oldAction.Text,
|
Text: oldAction.Text,
|
||||||
SendEmail: util.Ptr(oldAction.SendEmail),
|
SendEmail: util.Ptr(oldAction.SendEmail),
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,8 +47,8 @@ func (c AdminActionCategory) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAdminActionCategory(in string) AdminActionCategory {
|
func ParseAdminActionCategory(in string) AdminActionCategory {
|
||||||
switch in {
|
switch strings.ToLower(in) {
|
||||||
case "account":
|
case "account":
|
||||||
return AdminActionCategoryAccount
|
return AdminActionCategoryAccount
|
||||||
case "domain":
|
case "domain":
|
||||||
|
@ -96,8 +97,8 @@ func (t AdminActionType) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAdminActionType(in string) AdminActionType {
|
func ParseAdminActionType(in string) AdminActionType {
|
||||||
switch in {
|
switch strings.ToLower(in) {
|
||||||
case "disable":
|
case "disable":
|
||||||
return AdminActionDisable
|
return AdminActionDisable
|
||||||
case "reenable":
|
case "reenable":
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
package gtsmodel
|
package gtsmodel
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// DomainPermission models a domain permission
|
// DomainPermission models a domain permission
|
||||||
// entry -- block / allow / draft / exclude.
|
// entry -- block / allow / draft / exclude.
|
||||||
|
@ -62,8 +65,8 @@ func (p DomainPermissionType) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomainPermissionType(in string) DomainPermissionType {
|
func ParseDomainPermissionType(in string) DomainPermissionType {
|
||||||
switch in {
|
switch strings.ToLower(in) {
|
||||||
case "block":
|
case "block":
|
||||||
return DomainPermissionBlock
|
return DomainPermissionBlock
|
||||||
case "allow":
|
case "allow":
|
||||||
|
|
|
@ -87,8 +87,8 @@ func (t NotificationType) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNotificationType returns a notification type from the given value.
|
// ParseNotificationType returns a notification type from the given value.
|
||||||
func NewNotificationType(in string) NotificationType {
|
func ParseNotificationType(in string) NotificationType {
|
||||||
switch strings.ToLower(in) {
|
switch strings.ToLower(in) {
|
||||||
case "follow":
|
case "follow":
|
||||||
return NotificationFollow
|
return NotificationFollow
|
||||||
|
|
|
@ -40,7 +40,7 @@ func (p *Processor) AccountAction(
|
||||||
return "", gtserror.NewErrorInternalError(err)
|
return "", gtserror.NewErrorInternalError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch gtsmodel.NewAdminActionType(request.Type) {
|
switch gtsmodel.ParseAdminActionType(request.Type) {
|
||||||
case gtsmodel.AdminActionSuspend:
|
case gtsmodel.AdminActionSuspend:
|
||||||
return p.accountActionSuspend(ctx, adminAcct, targetAcct, request.Text)
|
return p.accountActionSuspend(ctx, adminAcct, targetAcct, request.Text)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue