From a39a664525f55846dd5eea52fcc7009867835989 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:19:32 +0100 Subject: [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 --- internal/typeutils/internaltofrontend.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'internal/typeutils/internaltofrontend.go') 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) -- cgit v1.2.3