Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/typescript-eslint/…
Browse files Browse the repository at this point in the history
…eslint-plugin-8.1.0
  • Loading branch information
nitrosx authored Aug 22, 2024
2 parents 04aca6f + 9a3d8d0 commit 7790e53
Show file tree
Hide file tree
Showing 29 changed files with 1,361 additions and 842 deletions.
1,579 changes: 892 additions & 687 deletions src/casl/casl-ability.factory.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/casl/decorators/check-policies.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { PolicyHandler } from "../interfaces/policy-handler.interface";

export const CHECK_POLICIES_KEY = "check_policy";

export const CheckPolicies = (...handlers: PolicyHandler[]) =>
SetMetadata(CHECK_POLICIES_KEY, handlers);
export const CheckPolicies = (endpoint: string, ...handlers: PolicyHandler[]) =>
SetMetadata(CHECK_POLICIES_KEY, { endpoint, handlers });
19 changes: 12 additions & 7 deletions src/casl/guards/policies.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ export class PoliciesGuard implements CanActivate {
) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const policyHandlers =
this.reflector.get<PolicyHandler[]>(
CHECK_POLICIES_KEY,
context.getHandler(),
) || [];
const policyData = this.reflector.get<{
endpoint: string;
handlers: PolicyHandler[];
}>(CHECK_POLICIES_KEY, context.getHandler());

if (!policyData) {
return false;
}

const policyHandlers = policyData["handlers"];
const endpoint = policyData["endpoint"];
const req = context.switchToHttp().getRequest();
const user = req.user;
const ability = this.caslAbilityFactory.createForUser(user);

const ability = this.caslAbilityFactory.endpointAccess(endpoint, user);
return policyHandlers.every((handler) =>
this.execPolicyHandler(handler, ability),
);
}

private execPolicyHandler(handler: PolicyHandler, ability: AppAbility) {
//console.log('PoliciesGuard:execPolicyHandler ', handler, ability)
if (typeof handler === "function") {
const res = handler(ability);
//console.log("PoliciesGuard:execPolicyHandler ", res);
Expand Down
11 changes: 11 additions & 0 deletions src/config/default-filters.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{ "type": "LocationFilterComponent", "visible": true },
{ "type": "PidFilterComponent", "visible": true },
{ "type": "PidFilterContainsComponent", "visible": false },
{ "type": "PidFilterStartsWithComponent", "visible": false },
{ "type": "GroupFilterComponent", "visible": true },
{ "type": "TypeFilterComponent", "visible": true },
{ "type": "KeywordFilterComponent", "visible": true },
{ "type": "DateRangeFilterComponent", "visible": true },
{ "type": "TextFilterComponent", "visible": true }
]
Loading

0 comments on commit 7790e53

Please sign in to comment.