[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>
This commit is contained in:
tobi
2022-11-15 10:19:32 +01:00
committed by GitHub
parent 4cd00d546c
commit a39a664525
10 changed files with 167 additions and 44 deletions

View File

@ -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)