Skip to content

Commit

Permalink
feat(authorization): first implementation to fix broken authz graph
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Sep 8, 2023
1 parent c72f481 commit abb0f97
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions modules/authorization/src/controllers/index.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ export class IndexController {
for (const permission of permissions) {
const roles = objectDefinition.permissions[permission];
for (const role of roles) {
// no index needed for "allowAll" permissions
// or for self modification
if (role === '*' || role.indexOf('->') === -1) {
await this.createOrUpdateObject(
object + '#' + permission,
role === '*' ? `*` : `${object}#${role}`,
);
} else {
if (role.indexOf('->') === -1) {
await this.createOrUpdateObject(object + '#' + permission, `${object}#${role}`);
} else if (role !== '*') {
const [relatedSubject, action] = role.split('->');
if (relation !== relatedSubject) continue;
const possibleConnections = await ObjectIndex.getInstance().findMany({
Expand All @@ -78,6 +73,17 @@ export class IndexController {
}
}
}
const actors = await ActorIndex.getInstance().findMany({
subject: object,
});
if (actors.length === 0) return;
for (const actor of actors) {
await this.constructRelationIndex(
actor.subject,
actor.relation,
actor.entity.split('#')[0],
);
}
}

async removeRelation(subject: string, relation: string, object: string) {
Expand Down

0 comments on commit abb0f97

Please sign in to comment.