From e7f7dcbb782e3dc737e4202caae1a5ccb60ef4c1 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 21 Jun 2023 11:26:59 +0100 Subject: [PATCH] userpage: show placeholder message card for admins --- api-userpage.go | 8 ++++++++ html/user.html | 2 +- lang/form/en-us.json | 4 +++- models.go | 19 ++++++++++--------- ts/user.ts | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/api-userpage.go b/api-userpage.go index 718741a..dd908d5 100644 --- a/api-userpage.go +++ b/api-userpage.go @@ -28,6 +28,14 @@ func (app *appContext) MyDetails(gc *gin.Context) { } resp.Username = user.Name resp.Admin = user.Policy.IsAdministrator + resp.AccountsAdmin = false + if !app.config.Section("ui").Key("allow_all").MustBool(false) { + adminOnly := app.config.Section("ui").Key("admin_only").MustBool(true) + if emailStore, ok := app.storage.GetEmailsKey(resp.Id); ok { + resp.AccountsAdmin = emailStore.Admin + } + resp.AccountsAdmin = resp.AccountsAdmin || (adminOnly && resp.Admin) + } resp.Disabled = user.Policy.IsDisabled if exp, ok := app.storage.users[user.ID]; ok { diff --git a/html/user.html b/html/user.html index d04af15..f249f37 100644 --- a/html/user.html +++ b/html/user.html @@ -85,7 +85,7 @@ {{ if index . "PageMessageEnabled" }} {{ if .PageMessageEnabled }} -
+
{{ .PageMessageContent }}
{{ end }} diff --git a/lang/form/en-us.json b/lang/form/en-us.json index 652856e..0fb3316 100644 --- a/lang/form/en-us.json +++ b/lang/form/en-us.json @@ -23,7 +23,9 @@ "welcomeUser": "Welcome, {user}!", "addContactMethod": "Add Contact Method", "editContactMethod": "Edit Contact Method", - "joinTheServer": "Join the server:" + "joinTheServer": "Join the server:", + "customMessagePlaceholderHeader": "Customize this card", + "customMessagePlaceholderContent": "Click the user page edit button in settings to customize this card, or show one on the login screen, and don't worry, the user can't see this." }, "notifications": { "errorUserExists": "User already exists.", diff --git a/models.go b/models.go index 9f3aef9..dbbb5d0 100644 --- a/models.go +++ b/models.go @@ -376,15 +376,16 @@ type ReCaptchaResponseDTO struct { // MyDetailsDTO is sent to the user page to personalize it for the user. type MyDetailsDTO struct { - Id string `json:"id"` - Username string `json:"username"` - Expiry int64 `json:"expiry"` - Admin bool `json:"admin"` - Disabled bool `json:"disabled"` - Email *MyDetailsContactMethodsDTO `json:"email,omitempty"` - Discord *MyDetailsContactMethodsDTO `json:"discord,omitempty"` - Telegram *MyDetailsContactMethodsDTO `json:"telegram,omitempty"` - Matrix *MyDetailsContactMethodsDTO `json:"matrix,omitempty"` + Id string `json:"id"` + Username string `json:"username"` + Expiry int64 `json:"expiry"` + Admin bool `json:"admin"` + AccountsAdmin bool `json:"accounts_admin"` + Disabled bool `json:"disabled"` + Email *MyDetailsContactMethodsDTO `json:"email,omitempty"` + Discord *MyDetailsContactMethodsDTO `json:"discord,omitempty"` + Telegram *MyDetailsContactMethodsDTO `json:"telegram,omitempty"` + Matrix *MyDetailsContactMethodsDTO `json:"matrix,omitempty"` } type MyDetailsContactMethodsDTO struct { diff --git a/ts/user.ts b/ts/user.ts index 071fe84..4e8b548 100644 --- a/ts/user.ts +++ b/ts/user.ts @@ -62,6 +62,7 @@ interface MyDetails { username: string; expiry: number; admin: boolean; + accounts_admin: boolean; disabled: boolean; email?: MyDetailsContactMethod; discord?: MyDetailsContactMethod; @@ -388,6 +389,23 @@ document.addEventListener("details-reload", () => { } expiryCard.expiry = details.expiry; + + + if (details.accounts_admin) { + let messageCard = document.getElementById("card-message") + if (typeof(messageCard) == "undefined" || messageCard == null) { + messageCard = document.createElement("div"); + messageCard.classList.add("card", "@low", "dark:~d_neutral", "content"); + messageCard.id = "card-message"; + contactCard.parentElement.appendChild(messageCard); + } + if (!messageCard.textContent) { + messageCard.innerHTML = ` + ${window.lang.strings("customMessagePlaceholderHeader")} ✏️ + ${window.lang.strings("customMessagePlaceholderContent")} + `; + } + } } }); });