From 65470fd582aa620427bf0ec3770e0991687828d1 Mon Sep 17 00:00:00 2001 From: Akanksh Saxena Date: Thu, 16 Dec 2021 12:00:35 +0100 Subject: [PATCH] fix(permissions): allow dynamic group names This allows to pass a regex through the ENV var which is then used to test against the group name. --- frontend/app/services/account.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/app/services/account.js b/frontend/app/services/account.js index 85283521..a2bd05e5 100644 --- a/frontend/app/services/account.js +++ b/frontend/app/services/account.js @@ -21,13 +21,15 @@ export default class AccountService extends Service { return this.session.data.authenticated?.userinfo.groups ?? []; } - isInGroup(group) { - return this.groups.includes(group); + isInGroup(groupRegex) { + return this.groups.some((group) => new RegExp(groupRegex).test(group)); } - isInGroups(amount, groups) { + isInGroups(amount, groupsRegex) { const method = amount === "one" ? "some" : "every"; - return this.groups[method]((group) => groups.includes(group)); + return this.groups[method]((group) => + groupsRegex.some((groupRegex) => new RegExp(groupRegex).test(group)) + ); } async fetchCurrentUser() {