Skip to content

Commit

Permalink
feat: revoke permission
Browse files Browse the repository at this point in the history
  • Loading branch information
trungnotchung committed Nov 13, 2024
1 parent 975722a commit da83d58
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/node/src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,40 @@ export async function grantPermission(
return;
}
if (cro.hasRole(peerId, Role.ADMIN)) {
console.error("topology::node::grantPermission", "Already an admin");
console.error("topology::node::grantPermission", "Can't grant admin role");
return;
}

cro.grantRole(peerId);
}

export async function revokePermission(
node: TopologyNode,
objectId: string,
peerId: string,
) {
const object: TopologyObject | undefined = node.objectStore.get(objectId);
if (!object) {
console.error("topology::node::revokePermission", "Object not found");
return;
}

const cro: CRO | undefined = object.cro as CRO;
if (!cro) {
console.error("topology::node::revokePermission", "CRO not found");
return;
}
if (!cro.hasRole(node.networkNode.peerId, Role.ADMIN)) {
console.error("topology::node::revokePermission", "Not an admin");
return;
}
if (cro.hasRole(peerId, Role.ADMIN)) {
console.error(
"topology::node::revokePermission",
"Can't revoke admin role",
);
return;
}

cro.revokeRole(peerId);
}
1 change: 1 addition & 0 deletions packages/object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface CRO {
mergeCallback: (operations: Operation[]) => void;
hasRole: (nodeId: string, role: number) => boolean;
grantRole: (nodeId: string) => void;
revokeRole: (nodeId: string) => void;
}

export type TopologyObjectCallback = (
Expand Down

0 comments on commit da83d58

Please sign in to comment.