Skip to content

Commit

Permalink
Add getAllAgentAccess()
Browse files Browse the repository at this point in the history
  • Loading branch information
helamanl0424 authored Apr 3, 2024
1 parent b5dfb47 commit 5e80466
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,25 @@ const removeFolder = krl.Action(["containerURL"], async function(containerURL :
this.log.debug('Container deleted successfully!\n');
});

const getAllAgentAccess = krl.Function(["resourceURL"], async function(resourceURL: string) {
const accessByAgent : any = await universalAccess.getAgentAccessAll(resourceURL, { fetch: authFetch });
let agents : string[] = [];
for (const [agent, agentAccess] of Object.entries(accessByAgent)) {
console.log(`For resource::: ${resourceURL}`);
agents.push(agent);
if (agentAccess === null) {
console.log(`Could not load ${agent}'s access details.`);
} else {
console.log(`${agent}'s Access:: ${JSON.stringify(agentAccess)}`);
}
}
return agents;
});

const grantAgentAccess = krl.Action(["resourceURL", "webID"], async function(resourceURL : string, webID : string) {
universalAccess.setAgentAccess(
resourceURL, // resource
webID, // agent
// sample: {"read":false,"write":false,"append":false,"controlRead":false,"controlWrite":false}
{ read: true, write: false },
{ fetch: authFetch } // fetch function from authenticated session
).then((agentAccess) => {
Expand All @@ -514,7 +528,7 @@ const removeAgentAccess = krl.Action(["resourceURL", "webID"], async function(re
universalAccess.setAgentAccess(
resourceURL, // resource
webID, // agent
{ read: false, write: false },
{ read: false, write: false},
{ fetch: authFetch } // fetch function from authenticated session
).then((agentAccess) => {
this.log.debug(`For resource::: ${resourceURL}`);
Expand Down Expand Up @@ -592,6 +606,7 @@ const pods: krl.Module = {
getAccessTokenReceiveTime : getAccessTokenReceiveTime, //Mostly private KRL helper function, but exported since developer may want to know about the token

authenticate: authenticate,
getAllAgentAccess: getAllAgentAccess,
grantAgentAccess: grantAgentAccess,
removeAgentAccess: removeAgentAccess,
getAccess: getAccess,
Expand Down

0 comments on commit 5e80466

Please sign in to comment.