Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
core: fixed submodule permission resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
zleyyij committed Aug 27, 2023
1 parent f48075f commit 6c0493f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,30 @@ function listenForSlashCommands() {
// it's also possible to specify permissions per-submodule, and per submodule group
// checking 2 layers deep, eg `/foo bar`
if (resolutionResult.modulePath.length === 2) {
const submodulePermissionConfig =
permissionConfig.submodulePermissions ?? {};
const submodulePermissionResults =
checkInteractionAgainstPermissionConfig(
interaction,
permissionConfig.submodulePermissions[
resolutionResult.modulePath[1]
] ?? {}
submodulePermissionConfig[resolutionResult.modulePath[1]] ?? {}
);
deniedReasons = deniedReasons.concat(submodulePermissionResults);
}

// 3 layers deep, EG `/foo bar bat`
if (resolutionResult.modulePath.length === 3) {
// this nasty oneliner just makes sure that
// if a config isn't defined 3 layers deep, an error
// isn't thrown
const subSubModulePermissionConfig =
permissionConfig.submodulePermissions ??
{}[resolutionResult.modulePath[1]] ??
{submodulePermissions: {}}.submodulePermissions ??
{}[resolutionResult.modulePath[2]];
const subSubmodulePermissionResults =
checkInteractionAgainstPermissionConfig(
interaction,
permissionConfig.submodulePermissions[
resolutionResult.modulePath[1]
].submodulePermissions[resolutionResult.modulePath[2]]
subSubModulePermissionConfig
);
deniedReasons = deniedReasons.concat(subSubmodulePermissionResults);
}
Expand Down

0 comments on commit 6c0493f

Please sign in to comment.