discord: fix admin-check for /inv
it was being checked in the EmailAddress record, only set if Jellyfin login is disabled, or "access jfa-go" is checked for a non-Jellyfin-admin user in Accounts. Instead, i've factored out the actual auth code into a "canAccessAdminPage"-ish function, which is called for this too. Should fix #378.
This commit is contained in:
@@ -165,6 +165,31 @@ func (app *appContext) decodeValidateLoginHeader(gc *gin.Context, userpage bool)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *appContext) canAccessAdminPage(user mediabrowser.User, emailStore EmailAddress) bool {
|
||||||
|
// 1. "Allow all" is enabled, so simply being a user implies access.
|
||||||
|
if app.config.Section("ui").Key("allow_all").MustBool(false) && user.ID != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// 2. You've been made an "accounts admin" from the accounts tab.
|
||||||
|
if emailStore.Admin {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// 3. (Jellyfin) "Admins only" is enabled, and you're one.
|
||||||
|
if app.config.Section("ui").Key("admin_only").MustBool(true) && user.ID != "" && user.Policy.IsAdministrator {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *appContext) canAccessAdminPageByID(jfID string) bool {
|
||||||
|
user, err := app.jf.UserByID(jfID, false)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
emailStore, _ := app.storage.GetEmailsKey(jfID)
|
||||||
|
return app.canAccessAdminPage(user, emailStore)
|
||||||
|
}
|
||||||
|
|
||||||
func (app *appContext) validateJellyfinCredentials(username, password string, gc *gin.Context, userpage bool) (user mediabrowser.User, ok bool) {
|
func (app *appContext) validateJellyfinCredentials(username, password string, gc *gin.Context, userpage bool) (user mediabrowser.User, ok bool) {
|
||||||
ok = false
|
ok = false
|
||||||
user, err := app.authJf.Authenticate(username, password)
|
user, err := app.authJf.Authenticate(username, password)
|
||||||
@@ -220,18 +245,12 @@ func (app *appContext) getTokenLogin(gc *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
jfID = user.ID
|
jfID = user.ID
|
||||||
if !app.config.Section("ui").Key("allow_all").MustBool(false) {
|
emailStore, _ := app.storage.GetEmailsKey(jfID)
|
||||||
accountsAdmin := false
|
accountsAdmin := app.canAccessAdminPage(user, emailStore)
|
||||||
adminOnly := app.config.Section("ui").Key("admin_only").MustBool(true)
|
if !accountsAdmin {
|
||||||
if emailStore, ok := app.storage.GetEmailsKey(jfID); ok {
|
app.authLog(fmt.Sprintf(lm.NonAdminUser, username))
|
||||||
accountsAdmin = emailStore.Admin
|
respond(401, "Unauthorized", gc)
|
||||||
}
|
return
|
||||||
accountsAdmin = accountsAdmin || (adminOnly && user.Policy.IsAdministrator)
|
|
||||||
if !accountsAdmin {
|
|
||||||
app.authLog(fmt.Sprintf(lm.NonAdminUser, username))
|
|
||||||
respond(401, "Unauthorized", gc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// New users are only added when using jellyfinLogin.
|
// New users are only added when using jellyfinLogin.
|
||||||
userID = shortuuid.New()
|
userID = shortuuid.New()
|
||||||
|
|||||||
+9
-4
@@ -612,11 +612,16 @@ func (d *DiscordDaemon) cmdInvite(s *dg.Session, i *dg.InteractionCreate, lang s
|
|||||||
//if mins > 0 {
|
//if mins > 0 {
|
||||||
// expmin = mins
|
// expmin = mins
|
||||||
//}
|
//}
|
||||||
// Check whether requestor is linked to the admin account
|
// We want the same criteria for running this command as accessing the admin page (i.e. an "admin" of some sort)
|
||||||
requesterEmail, ok := d.app.storage.GetEmailsKey(requester.JellyfinID)
|
if !(d.app.canAccessAdminPageByID(requester.JellyfinID)) {
|
||||||
if !(ok && requesterEmail.Admin) {
|
|
||||||
d.app.err.Printf(lm.FailedGenerateInvite, fmt.Sprintf(lm.NonAdminUser, requester.JellyfinID))
|
d.app.err.Printf(lm.FailedGenerateInvite, fmt.Sprintf(lm.NonAdminUser, requester.JellyfinID))
|
||||||
// FIXME: add response message
|
s.InteractionRespond(i.Interaction, &dg.InteractionResponse{
|
||||||
|
Type: dg.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &dg.InteractionResponseData{
|
||||||
|
Content: d.app.storage.lang.Telegram[lang].Strings.get("noPermission"),
|
||||||
|
Flags: 64, // Ephemeral
|
||||||
|
},
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"languageSet": "Language set to {language}.",
|
"languageSet": "Language set to {language}.",
|
||||||
"discordDMs": "Please check your DMs for a response.",
|
"discordDMs": "Please check your DMs for a response.",
|
||||||
"sentInvite": "Sent invite.",
|
"sentInvite": "Sent invite.",
|
||||||
"sentInviteFailure": "Failed to send invite, check logs."
|
"sentInviteFailure": "Failed to send invite, check logs.",
|
||||||
|
"noPermission": "You do not have permissions for this action."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user