diff --git a/.configref b/.configref index a695856d7..a43af86d8 100644 --- a/.configref +++ b/.configref @@ -1 +1 @@ -18915 \ No newline at end of file +18934 \ No newline at end of file diff --git a/package.json b/package.json index 51e330ab1..fcb048aaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reactmap", - "version": "1.9.8", + "version": "1.9.9", "description": "React based frontend map.", "main": "ReactMap.js", "author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>", diff --git a/server/src/configs/custom-environment-variables.json b/server/src/configs/custom-environment-variables.json index 485650aaf..bd71d88e7 100644 --- a/server/src/configs/custom-environment-variables.json +++ b/server/src/configs/custom-environment-variables.json @@ -1135,6 +1135,10 @@ "__name": "AUTHENTICATION_ALWAYS_ENABLED_PERMS", "__format": "json" }, + "aliases": { + "__name": "AUTHENTICATION_ALIASES", + "__format": "json" + }, "perms": { "map": { "enabled": { diff --git a/server/src/configs/default.json b/server/src/configs/default.json index 39d8c223c..24f69319b 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -630,6 +630,7 @@ "areaRestrictions": [], "excludeFromTutorial": [], "alwaysEnabledPerms": [], + "aliases": [], "perms": { "map": { "enabled": true, diff --git a/server/src/configs/local.example.json b/server/src/configs/local.example.json index fa36426d3..c7c4edf16 100644 --- a/server/src/configs/local.example.json +++ b/server/src/configs/local.example.json @@ -1,4 +1,5 @@ { + "READ_ME": "https://github.com/WatWowMap/ReactMap/wiki/04.-Full-Config-Explanation", "interface": "0.0.0.0", "port": 8080, "packageSource": "git/docker", @@ -137,6 +138,16 @@ "areas": [] } ], + "aliases": [ + { + "role": "123415123541", + "name": "verified" + }, + { + "role": "897581458191", + "name": "supporter" + } + ], "alwaysEnabledPerms": [], "perms": { "map": { diff --git a/server/src/services/config.js b/server/src/services/config.js index 156d49abe..4046114d0 100644 --- a/server/src/services/config.js +++ b/server/src/services/config.js @@ -423,6 +423,41 @@ if (hasLittle) { : { little: false, cap: 500 } } +const aliasObj = Object.fromEntries( + config.authentication.aliases.map((alias) => [alias.name, alias.role]), +) + +const replaceAliases = (role) => aliasObj[role] ?? role + +Object.keys(config.authentication.perms).forEach((perm) => { + config.authentication.perms[perm].roles = + config.authentication.perms[perm].roles.map(replaceAliases) +}) + +config.authentication.areaRestrictions = + config.authentication.areaRestrictions.map(({ roles, areas }) => ({ + roles: roles.map(replaceAliases), + areas, + })) + +config.authentication.strategies = config.authentication.strategies.map( + (strategy) => ({ + ...strategy, + allowedGuilds: Array.isArray(strategy.allowedGuilds) + ? strategy.allowedGuilds.map(replaceAliases) + : undefined, + blockedGuilds: Array.isArray(strategy.blockedGuilds) + ? strategy.blockedGuilds.map(replaceAliases) + : undefined, + groups: Array.isArray(strategy.groups) + ? strategy.groups.map(replaceAliases) + : undefined, + allowedUsers: Array.isArray(strategy.allowedUsers) + ? strategy.allowedUsers.map(replaceAliases) + : undefined, + }), +) + if ( !config.authentication.strategies.length || !config.authentication.strategies.find((strategy) => strategy.enabled)