Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate privilege for application approval #4655

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/constants/authorization/policy.rule.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export const PRIVILEGE_RULE_READ_USER_SETTINGS =
export const POLICY_RULE_COMMUNITY_INVITE_MEMBER = 'policyRule-communityInvite';
export const POLICY_RULE_COMMUNITY_ADD_VC =
'policyRule-communityAddVirtualContributor';
export const POLICY_RULE_COMMUNITY_APPROVE_APPLICATION =
'policyRule-communityApproveApplication';
1 change: 1 addition & 0 deletions src/common/enums/authorization.privilege.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum AuthorizationPrivilege {
UPDATE_INNOVATION_FLOW = 'update-innovation-flow',
COMMUNITY_JOIN = 'community-join',
COMMUNITY_APPLY = 'community-apply',
COMMUNITY_APPLY_ACCEPT = 'community-apply-accept',
COMMUNITY_INVITE = 'community-invite',
COMMUNITY_INVITE_ACCEPT = 'community-invite-accept',
COMMUNITY_ADD_MEMBER = 'community-add-member', // only for global admins
Expand Down
21 changes: 21 additions & 0 deletions src/domain/access/application/application.service.authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IAuthorizationPolicy } from '@domain/common/authorization-policy/author
import { IApplication } from './application.interface';
import { IAuthorizationPolicyRuleCredential } from '@core/authorization/authorization.policy.rule.credential.interface';
import { CREDENTIAL_RULE_COMMUNITY_USER_APPLICATION } from '@common/constants/authorization/credential.rule.constants';
import { AuthorizationPolicyRulePrivilege } from '@core/authorization/authorization.policy.rule.privilege';
import { POLICY_RULE_COMMUNITY_APPROVE_APPLICATION } from '@common/constants';

@Injectable()
export class ApplicationAuthorizationService {
Expand All @@ -24,6 +26,10 @@ export class ApplicationAuthorizationService {
parentAuthorization
);

application.authorization = this.appendPrivilegeRules(
application.authorization
);

application.authorization =
await this.extendAuthorizationPolicy(application);

Expand Down Expand Up @@ -61,4 +67,19 @@ export class ApplicationAuthorizationService {
newRules
);
}

private appendPrivilegeRules(
authorization: IAuthorizationPolicy
): IAuthorizationPolicy {
const approveApplicationPrivilege = new AuthorizationPolicyRulePrivilege(
[AuthorizationPrivilege.COMMUNITY_APPLY_ACCEPT],
AuthorizationPrivilege.GRANT,
POLICY_RULE_COMMUNITY_APPROVE_APPLICATION
);

return this.authorizationPolicyService.appendPrivilegeAuthorizationRules(
authorization,
[approveApplicationPrivilege]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const applicationLifecycleMachine: ILifecycleDefinition = {
new: {
on: {
APPROVE: {
guards: 'hasUpdatePrivilege',
guards: 'hasApplicationAcceptPrivilege',
target: ApplicationLifecycleState.APPROVING,
},
REJECT: {
Expand All @@ -72,7 +72,7 @@ export const applicationLifecycleMachine: ILifecycleDefinition = {
approving: {
on: {
APPROVED: {
guards: 'hasUpdatePrivilege',
guards: 'hasApplicationAcceptPrivilege',
target: ApplicationLifecycleState.APPROVED,
},
},
Expand Down
4 changes: 3 additions & 1 deletion src/domain/access/role-set/role.set.resolver.mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,12 @@ export class RoleSetResolverMutations {
let application = await this.applicationService.getApplicationOrFail(
eventData.applicationID
);

//toDo fix this temporary fix. Patches the immediate issue but doesn't solve the design issue of guards not being triggered on transitions
this.authorizationService.grantAccessOrFail(
agentInfo,
application.authorization,
AuthorizationPrivilege.UPDATE,
AuthorizationPrivilege.COMMUNITY_APPLY_ACCEPT,
valentinyanakiev marked this conversation as resolved.
Show resolved Hide resolved
`event on application: ${application.id}`
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export class RoleSetServiceLifecycleApplication {
AuthorizationPrivilege.UPDATE
);
},
hasApplicationAcceptPrivilege: ({ event }) => {
const agentInfo: AgentInfo = event.agentInfo;
const authorizationPolicy: IAuthorizationPolicy = event.authorization;
return this.authorizationService.isAccessGranted(
agentInfo,
authorizationPolicy,
AuthorizationPrivilege.COMMUNITY_APPLY_ACCEPT
);
},
},
});
return machine.createMachine(applicationLifecycleMachine);
Expand Down