Skip to content

Commit

Permalink
fix: check that corresponding feature is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Nov 18, 2019
1 parent d81d24b commit 358b23f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/entities/SecurityToken/Permissions.ts
Expand Up @@ -197,14 +197,25 @@ export class Permissions extends SubModule {
securityToken: { symbol, features },
} = this;

const isPermissionsEnabled = await features.isEnabled({ feature: Feature.Permissions });
const [isPermissionsEnabled, requiredFeature] = await Promise.all([
features.isEnabled({ feature: Feature.Permissions }),
this.getFeatureFromRole({ role }),
]);
if (!isPermissionsEnabled) {
throw new PolymathError({
code: ErrorCode.FeatureNotEnabled,
message: 'You must enable the Permissions feature',
});
}

const isFeatureEnabled = await features.isEnabled({ feature: requiredFeature });
if (!isFeatureEnabled) {
throw new PolymathError({
code: ErrorCode.FeatureNotEnabled,
message: `You must enable the ${requiredFeature} feature to check delegates for role ${role}`,
});
}

const generalPermissionManager = (await contractWrappers.getAttachedModules(
{ moduleName: ModuleName.GeneralPermissionManager, symbol },
{ unarchived: true }
Expand Down
4 changes: 2 additions & 2 deletions src/procedures/AssignSecurityTokenRole.ts
Expand Up @@ -34,7 +34,7 @@ export class AssignSecurityTokenRole extends Procedure<AssignSecurityTokenRolePr
if (!permissionModule) {
throw new PolymathError({
code: ErrorCode.ProcedureValidationError,
message: 'You must enable the Permissions feature',
message: 'You must enable the Permissions feature in order to assign roles',
});
}

Expand All @@ -51,7 +51,7 @@ export class AssignSecurityTokenRole extends Procedure<AssignSecurityTokenRolePr
if (!isAvailable) {
throw new PolymathError({
code: ErrorCode.FeatureNotEnabled,
message: `You must enable the ${requiredFeature} feature`,
message: `You must enable the ${requiredFeature} feature in order to assign the ${role} role`,
});
}

Expand Down

0 comments on commit 358b23f

Please sign in to comment.