From 9bba037eabdf7336325fcfdfecbe24134ae8fde2 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 5 Jun 2023 16:29:18 +0200 Subject: [PATCH] feat: add admin badge on profiles --- backend/db/user.go | 6 +++++ backend/routes/user/get_user.go | 5 +++++ frontend/src/lib/api/entities.ts | 1 + frontend/src/routes/@[username]/+page.svelte | 6 +++-- .../routes/@[username]/badges/Admin.svelte | 22 +++++++++++++++++++ .../routes/@[username]/badges/Badges.svelte | 20 +++++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 frontend/src/routes/@[username]/badges/Admin.svelte create mode 100644 frontend/src/routes/@[username]/badges/Badges.svelte diff --git a/backend/db/user.go b/backend/db/user.go index cdde3c4..ccb0965 100644 --- a/backend/db/user.go +++ b/backend/db/user.go @@ -113,6 +113,12 @@ func (u User) NumProviders() (numProviders int) { return numProviders } +type Badge int32 + +const ( + BadgeAdmin Badge = 1 << 0 +) + // usernames must match this regex var usernameRegex = regexp.MustCompile(`^[\w-.]{2,40}$`) diff --git a/backend/routes/user/get_user.go b/backend/routes/user/get_user.go index fe1bece..f6a9aae 100644 --- a/backend/routes/user/get_user.go +++ b/backend/routes/user/get_user.go @@ -27,6 +27,7 @@ type GetUserResponse struct { Fields []db.Field `json:"fields"` CustomPreferences db.CustomPreferences `json:"custom_preferences"` Flags []db.UserFlag `json:"flags"` + Badges db.Badge `json:"badges"` } type GetMeResponse struct { @@ -82,6 +83,10 @@ func dbUserToResponse(u db.User, fields []db.Field, members []db.Member, flags [ Flags: flags, } + if u.IsAdmin { + resp.Badges |= db.BadgeAdmin + } + resp.Members = make([]PartialMember, len(members)) for i := range members { resp.Members[i] = PartialMember{ diff --git a/frontend/src/lib/api/entities.ts b/frontend/src/lib/api/entities.ts index 4086f5b..61c5c92 100644 --- a/frontend/src/lib/api/entities.ts +++ b/frontend/src/lib/api/entities.ts @@ -13,6 +13,7 @@ export interface User { avatar: string | null; links: string[]; member_title: string | null; + badges: number; names: FieldEntry[]; pronouns: Pronoun[]; diff --git a/frontend/src/routes/@[username]/+page.svelte b/frontend/src/routes/@[username]/+page.svelte index 5b04ace..65230c7 100644 --- a/frontend/src/routes/@[username]/+page.svelte +++ b/frontend/src/routes/@[username]/+page.svelte @@ -4,6 +4,7 @@ import { Alert, + Badge, Button, ButtonGroup, Icon, @@ -42,6 +43,7 @@ import { addToast } from "$lib/toast"; import ProfileFlag from "./ProfileFlag.svelte"; import IconButton from "$lib/components/IconButton.svelte"; + import Badges from "./badges/Badges.svelte"; export let data: PageData; @@ -160,11 +162,11 @@
{#if data.display_name}
-

{data.display_name}

+

{data.display_name}

@{data.name}

{:else} -

@{data.name}

+

@{data.name}

{/if} {#if profileEmpty && $userStore?.id === data.id}
diff --git a/frontend/src/routes/@[username]/badges/Admin.svelte b/frontend/src/routes/@[username]/badges/Admin.svelte new file mode 100644 index 0000000..0c979f7 --- /dev/null +++ b/frontend/src/routes/@[username]/badges/Admin.svelte @@ -0,0 +1,22 @@ + + +This user is an admin + +
+ +
+ + diff --git a/frontend/src/routes/@[username]/badges/Badges.svelte b/frontend/src/routes/@[username]/badges/Badges.svelte new file mode 100644 index 0000000..5b61c9c --- /dev/null +++ b/frontend/src/routes/@[username]/badges/Badges.svelte @@ -0,0 +1,20 @@ + + +
+ {#if isAdmin} + + {/if} +
+ +