1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

userpage: show placeholder message card for admins

This commit is contained in:
Harvey Tindall 2023-06-21 11:26:59 +01:00
parent cc4a97db28
commit e7f7dcbb78
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
5 changed files with 40 additions and 11 deletions

View File

@ -28,6 +28,14 @@ func (app *appContext) MyDetails(gc *gin.Context) {
} }
resp.Username = user.Name resp.Username = user.Name
resp.Admin = user.Policy.IsAdministrator 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 resp.Disabled = user.Policy.IsDisabled
if exp, ok := app.storage.users[user.ID]; ok { if exp, ok := app.storage.users[user.ID]; ok {

View File

@ -85,7 +85,7 @@
</div> </div>
{{ if index . "PageMessageEnabled" }} {{ if index . "PageMessageEnabled" }}
{{ if .PageMessageEnabled }} {{ if .PageMessageEnabled }}
<div class="card @low dark:~d_neutral content"> <div class="card @low dark:~d_neutral content" id="card-message">
{{ .PageMessageContent }} {{ .PageMessageContent }}
</div> </div>
{{ end }} {{ end }}

View File

@ -23,7 +23,9 @@
"welcomeUser": "Welcome, {user}!", "welcomeUser": "Welcome, {user}!",
"addContactMethod": "Add Contact Method", "addContactMethod": "Add Contact Method",
"editContactMethod": "Edit 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": { "notifications": {
"errorUserExists": "User already exists.", "errorUserExists": "User already exists.",

View File

@ -376,15 +376,16 @@ type ReCaptchaResponseDTO struct {
// MyDetailsDTO is sent to the user page to personalize it for the user. // MyDetailsDTO is sent to the user page to personalize it for the user.
type MyDetailsDTO struct { type MyDetailsDTO struct {
Id string `json:"id"` Id string `json:"id"`
Username string `json:"username"` Username string `json:"username"`
Expiry int64 `json:"expiry"` Expiry int64 `json:"expiry"`
Admin bool `json:"admin"` Admin bool `json:"admin"`
Disabled bool `json:"disabled"` AccountsAdmin bool `json:"accounts_admin"`
Email *MyDetailsContactMethodsDTO `json:"email,omitempty"` Disabled bool `json:"disabled"`
Discord *MyDetailsContactMethodsDTO `json:"discord,omitempty"` Email *MyDetailsContactMethodsDTO `json:"email,omitempty"`
Telegram *MyDetailsContactMethodsDTO `json:"telegram,omitempty"` Discord *MyDetailsContactMethodsDTO `json:"discord,omitempty"`
Matrix *MyDetailsContactMethodsDTO `json:"matrix,omitempty"` Telegram *MyDetailsContactMethodsDTO `json:"telegram,omitempty"`
Matrix *MyDetailsContactMethodsDTO `json:"matrix,omitempty"`
} }
type MyDetailsContactMethodsDTO struct { type MyDetailsContactMethodsDTO struct {

View File

@ -62,6 +62,7 @@ interface MyDetails {
username: string; username: string;
expiry: number; expiry: number;
admin: boolean; admin: boolean;
accounts_admin: boolean;
disabled: boolean; disabled: boolean;
email?: MyDetailsContactMethod; email?: MyDetailsContactMethod;
discord?: MyDetailsContactMethod; discord?: MyDetailsContactMethod;
@ -388,6 +389,23 @@ document.addEventListener("details-reload", () => {
} }
expiryCard.expiry = details.expiry; 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 = `
<span class="heading mb-2">${window.lang.strings("customMessagePlaceholderHeader")} </span>
<span class="block">${window.lang.strings("customMessagePlaceholderContent")}</span>
`;
}
}
} }
}); });
}); });