Add collaborator by username

This commit is contained in:
thiloho
2024-08-31 22:55:04 +02:00
parent 6c287cba46
commit 187287ec4f
3 changed files with 36 additions and 13 deletions

View File

@@ -28,6 +28,15 @@ export const actions: Actions = {
addCollaborator: async ({ request, fetch, cookies, params }) => { addCollaborator: async ({ request, fetch, cookies, params }) => {
const data = await request.formData(); const data = await request.formData();
const userData = await fetch(`${API_BASE_PREFIX}/user?username=eq.${data.get("username")}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json"
}
});
const res = await fetch(`${API_BASE_PREFIX}/collab`, { const res = await fetch(`${API_BASE_PREFIX}/collab`, {
method: "POST", method: "POST",
headers: { headers: {
@@ -36,7 +45,7 @@ export const actions: Actions = {
}, },
body: JSON.stringify({ body: JSON.stringify({
website_id: params.websiteId, website_id: params.websiteId,
user_id: data.get("user-id"), user_id: (await userData.json()).id,
permission_level: data.get("permission-level") permission_level: data.get("permission-level")
}) })
}); });

View File

@@ -35,15 +35,8 @@
}} }}
> >
<label> <label>
User id: Username:
<input <input type="text" name="username" minlength="3" maxlength="16" required />
type="text"
name="user-id"
minlength="36"
maxlength="36"
placeholder="00000000-0000-0000-0000-000000000000"
required
/>
</label> </label>
<label> <label>

View File

@@ -172,11 +172,32 @@ test.describe("Update website", () => {
}); });
test.describe("Collaborators", () => { test.describe("Collaborators", () => {
test("Add collaborator", async ({ authenticatedPage: page }) => {}); test("Add collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully added")).toBeVisible();
});
test("Update collaborator", async ({ authenticatedPage: page }) => {}); test("Update collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Update" }).click();
await page.getByRole("combobox").selectOption("20");
await page.getByRole("button", { name: "Update collaborator" }).click();
await expect(page.getByText("Successfully updated")).toBeVisible();
});
test("Delete collaborator", async ({ authenticatedPage: page }) => {}); test("Remove collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Remove" }).click();
await page.getByRole("button", { name: "Remove collaborator" }).click();
await expect(page.getByText("Successfully removed")).toBeVisible();
});
}); });
}); });