summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-11-15 10:19:32 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-15 10:19:32 +0100
commita39a664525f55846dd5eea52fcc7009867835989 (patch)
tree33ba8c86bff8ea31853c1f52a92260d2909edcd4 /internal/typeutils/internaltofrontend.go
parent[feature] Allow newly uploaded emojis to be placed in categories (#939) (diff)
downloadgotosocial-a39a664525f55846dd5eea52fcc7009867835989.tar.xz
[feature] Serialize local account role via API, and show it via web view (#1045)
* [feature] Add 'role' field to api serialization of local accounts * [chore] Add a bit of license text while I'm here * [frogend] render account role on same line as username in web view of profile * style tweaking on role badges, general profile header layout * profile stats wrapping * don't render standard 'user' role on web view Co-authored-by: f0x <f0x@cthu.lu>
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index ac834f78d..9c55a55f4 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -185,13 +185,30 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
emojis = append(emojis, apiEmoji)
}
- var acct string
+ var (
+ acct string
+ role = model.AccountRoleUnknown
+ )
+
if a.Domain != "" {
// this is a remote user
- acct = fmt.Sprintf("%s@%s", a.Username, a.Domain)
+ acct = a.Username + "@" + a.Domain
} else {
// this is a local user
acct = a.Username
+ user, err := c.db.GetUserByAccountID(ctx, a.ID)
+ if err != nil {
+ return nil, fmt.Errorf("AccountToAPIAccountPublic: error getting user from database for account id %s: %s", a.ID, err)
+ }
+
+ switch {
+ case *user.Admin:
+ role = model.AccountRoleAdmin
+ case *user.Moderator:
+ role = model.AccountRoleModerator
+ default:
+ role = model.AccountRoleUser
+ }
}
var suspended bool
@@ -222,6 +239,7 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
Suspended: suspended,
CustomCSS: a.CustomCSS,
EnableRSS: *a.EnableRSS,
+ Role: role,
}
c.ensureAvatar(accountFrontend)