Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission sidebar #54

Merged
merged 13 commits into from
Jul 24, 2024
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