Skip to content

Commit

Permalink
Merge pull request #54 from osoc24/34-permission-sidebar
Browse files Browse the repository at this point in the history
Permission sidebar
  • Loading branch information
Zelzahn authored Jul 24, 2024
2 parents 33c00cf + 30bba57 commit c8a6add
Show file tree
Hide file tree
Showing 14 changed files with 2,119 additions and 2,206 deletions.
29 changes: 27 additions & 2 deletions controller/src/index-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import {
saveFileInContainer,
} from "@inrupt/solid-client";
import { Session } from "@inrupt/solid-client-authn-browser";
import { Index, IndexItem, Permission, url, UserTypeObject } from "./types";
import {
Index,
IndexItem,
Permission,
Type,
url,
UserTypeObject,
} from "./types";
import {
setAgentAccess,
setPublicAccess,
Expand Down Expand Up @@ -102,7 +109,7 @@ export async function editPermissions(
const itemIndex = index.items.findIndex(({ id }) => id === itemId);

if (itemIndex === -1) {
throw new Error("Element not found");
throw new Error("Item is not found, is it present in the index file?");
}

const item = index.items[itemIndex];
Expand Down Expand Up @@ -130,6 +137,24 @@ export async function editPermissions(
return index;
}

export function getItemId(index: Index, resource: url, user: string) {
if (user === "public") {
return index.items.find(
(indexItem) =>
indexItem.resources.includes(resource) &&
indexItem.userType === undefined
)?.id;
}

return index.items.find(
(indexItem) =>
indexItem.resources.includes(resource) &&
indexItem.userType &&
indexItem.userType.type === Type.WebID &&
indexItem.userType.url === user
)?.id;
}

async function updateACL(
session: Session,
resources: url[],
Expand Down
20 changes: 12 additions & 8 deletions controller/src/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ async function listThings(
): Promise<FormattedThing[]> {
const dataset = await getSolidDataset(url, { fetch: session.fetch });
return Promise.all(
getThingAll(dataset).map(async (t) => ({
url: t.url,
properties: getPropertyAll(t),
accessModes: await getAccessModes(session, t.url),
}))
getThingAll(dataset)
// For some reason the appointments container is utterly borked permissions-wise
.filter((t) => !t.url.includes("appointments"))
.map(async (t) => ({
url: t.url,
properties: getPropertyAll(t),
accessModes: await getAccessModes(session, t.url),
}))
);
}

Expand Down Expand Up @@ -80,8 +83,8 @@ async function getAccessModes(
function accessModesToPermissions(
record: Record<url, AccessModes>
): Record<url, Permission[]> {
const result: {
[agent: string]: Permission[]
const result: {
[agent: string]: Permission[];
} = {};
// List -> Set -> List is done to filter out possible duplicate Permission.Control's
const mapToPermission = (accessModes: [string, boolean][]) => [
Expand Down Expand Up @@ -210,5 +213,6 @@ export async function getAppointments(
};
};

return fetchResources(session, `${url}/appointments/`, mapAppointment);
// As the appointments folder is borked, cooltoinments is used as a back-up.
return fetchResources(session, `${url}/cooltoinments/`, mapAppointment);
}
Loading

0 comments on commit c8a6add

Please sign in to comment.