From b8d23eab00b9a196033c3a0074a83b9a50ffbb77 Mon Sep 17 00:00:00 2001 From: thiloho <123883702+thiloho@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:08:34 +0200 Subject: [PATCH] Update collab permission tests and minor fixes --- .../20240814175120_full_text_search.sql | 4 + ...40827090504_categories_and_publication.sql | 2 + ...828132309_adjust_website_overview_view.sql | 2 + .../20240829085258_docs_articles_weight.sql | 2 + ...20240829095918_adjust_website_overview.sql | 2 + ...ite_overview_categorized_articles_sort.sql | 2 + ...240830062353_optional_publication_date.sql | 7 + ...112106_website_view_publication_status.sql | 2 + web-app/playwright.config.ts | 4 +- .../routes/(authenticated)/+page.server.ts | 21 +- .../src/routes/(authenticated)/+page.svelte | 12 +- .../[websiteId]/articles/+page.server.ts | 5 + .../[websiteId]/collaborators/+page.server.ts | 2 +- web-app/tests/account.spec.ts | 68 +- web-app/tests/collaborator.spec.ts | 688 +++++++++++------- web-app/tests/website.spec.ts | 591 +++++++-------- 16 files changed, 804 insertions(+), 610 deletions(-) diff --git a/rest-api/db/migrations/20240814175120_full_text_search.sql b/rest-api/db/migrations/20240814175120_full_text_search.sql index 839533a..7a8e3a3 100644 --- a/rest-api/db/migrations/20240814175120_full_text_search.sql +++ b/rest-api/db/migrations/20240814175120_full_text_search.sql @@ -84,3 +84,7 @@ FROM ALTER TABLE internal.website DROP COLUMN title_search; +GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user; + +GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user; + diff --git a/rest-api/db/migrations/20240827090504_categories_and_publication.sql b/rest-api/db/migrations/20240827090504_categories_and_publication.sql index 2789d68..a44ab59 100644 --- a/rest-api/db/migrations/20240827090504_categories_and_publication.sql +++ b/rest-api/db/migrations/20240827090504_categories_and_publication.sql @@ -103,6 +103,8 @@ SELECT FROM internal.article; +GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user; + DROP VIEW api.docs_category; ALTER TABLE internal.article diff --git a/rest-api/db/migrations/20240828132309_adjust_website_overview_view.sql b/rest-api/db/migrations/20240828132309_adjust_website_overview_view.sql index 57b7f65..75d7865 100644 --- a/rest-api/db/migrations/20240828132309_adjust_website_overview_view.sql +++ b/rest-api/db/migrations/20240828132309_adjust_website_overview_view.sql @@ -104,3 +104,5 @@ FROM JOIN internal.home ho ON w.id = ho.website_id JOIN internal.footer f ON w.id = f.website_id; +GRANT SELECT ON api.website_overview TO authenticated_user; + diff --git a/rest-api/db/migrations/20240829085258_docs_articles_weight.sql b/rest-api/db/migrations/20240829085258_docs_articles_weight.sql index f7407e9..f61f7f2 100644 --- a/rest-api/db/migrations/20240829085258_docs_articles_weight.sql +++ b/rest-api/db/migrations/20240829085258_docs_articles_weight.sql @@ -52,3 +52,5 @@ FROM ALTER TABLE internal.article DROP COLUMN article_weight; +GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user; + diff --git a/rest-api/db/migrations/20240829095918_adjust_website_overview.sql b/rest-api/db/migrations/20240829095918_adjust_website_overview.sql index 3b98031..27583fd 100644 --- a/rest-api/db/migrations/20240829095918_adjust_website_overview.sql +++ b/rest-api/db/migrations/20240829095918_adjust_website_overview.sql @@ -136,3 +136,5 @@ FROM JOIN internal.home ho ON w.id = ho.website_id JOIN internal.footer f ON w.id = f.website_id; +GRANT SELECT ON api.website_overview TO authenticated_user; + diff --git a/rest-api/db/migrations/20240829180521_adjust_website_overview_categorized_articles_sort.sql b/rest-api/db/migrations/20240829180521_adjust_website_overview_categorized_articles_sort.sql index 5148839..e62b2b1 100644 --- a/rest-api/db/migrations/20240829180521_adjust_website_overview_categorized_articles_sort.sql +++ b/rest-api/db/migrations/20240829180521_adjust_website_overview_categorized_articles_sort.sql @@ -136,3 +136,5 @@ FROM JOIN internal.home ho ON w.id = ho.website_id JOIN internal.footer f ON w.id = f.website_id; +GRANT SELECT ON api.website_overview TO authenticated_user; + diff --git a/rest-api/db/migrations/20240830062353_optional_publication_date.sql b/rest-api/db/migrations/20240830062353_optional_publication_date.sql index 855351a..8ab6c0b 100644 --- a/rest-api/db/migrations/20240830062353_optional_publication_date.sql +++ b/rest-api/db/migrations/20240830062353_optional_publication_date.sql @@ -3,6 +3,13 @@ ALTER TABLE internal.article ALTER COLUMN publication_date DROP NOT NULL; -- migrate:down +UPDATE + internal.article +SET + publication_date = CURRENT_DATE +WHERE + publication_date IS NULL; + ALTER TABLE internal.article ALTER COLUMN publication_date SET NOT NULL; diff --git a/rest-api/db/migrations/20240830112106_website_view_publication_status.sql b/rest-api/db/migrations/20240830112106_website_view_publication_status.sql index a632944..c305909 100644 --- a/rest-api/db/migrations/20240830112106_website_view_publication_status.sql +++ b/rest-api/db/migrations/20240830112106_website_view_publication_status.sql @@ -33,3 +33,5 @@ SELECT FROM internal.website; +GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user; + diff --git a/web-app/playwright.config.ts b/web-app/playwright.config.ts index f7cce26..ff4cb3d 100644 --- a/web-app/playwright.config.ts +++ b/web-app/playwright.config.ts @@ -6,10 +6,12 @@ const config: PlaywrightTestConfig = { url: "http://localhost:4173" }, use: { - baseURL: "http://localhost:4173" + baseURL: "http://localhost:4173", + video: "retain-on-failure" }, testDir: "tests", testMatch: /(.+\.)?(test|spec)\.ts/, + retries: 3, // Firefox and Webkit are not packaged yet, see https://github.com/NixOS/nixpkgs/issues/288826 projects: [ { diff --git a/web-app/src/routes/(authenticated)/+page.server.ts b/web-app/src/routes/(authenticated)/+page.server.ts index ead6df1..cf3391a 100644 --- a/web-app/src/routes/(authenticated)/+page.server.ts +++ b/web-app/src/routes/(authenticated)/+page.server.ts @@ -5,33 +5,16 @@ import { join } from "node:path"; export const load: PageServerLoad = async ({ fetch, cookies, url, locals }) => { const searchQuery = url.searchParams.get("website_search_query"); - const sortBy = url.searchParams.get("website_sort"); const filterBy = url.searchParams.get("website_filter"); const params = new URLSearchParams(); - const baseFetchUrl = `${API_BASE_PREFIX}/website`; + const baseFetchUrl = `${API_BASE_PREFIX}/website?order=last_modified_at.desc,created_at.desc`; if (searchQuery) { params.append("title_search", `wfts(english).${searchQuery}`); } - switch (sortBy) { - case null: - case "creation-time": - params.append("order", "created_at.desc"); - break; - case "last-modified": - params.append("order", "last_modified_at.desc"); - break; - case "title-a-to-z": - params.append("order", "title.asc"); - break; - case "title-z-to-a": - params.append("order", "title.desc"); - break; - } - switch (filterBy) { case "creations": params.append("user_id", `eq.${locals.user.id}`); @@ -41,7 +24,7 @@ export const load: PageServerLoad = async ({ fetch, cookies, url, locals }) => { break; } - const constructedFetchUrl = `${baseFetchUrl}?${params.toString()}`; + const constructedFetchUrl = `${baseFetchUrl}&${params.toString()}`; const totalWebsitesData = await fetch(baseFetchUrl, { method: "HEAD", diff --git a/web-app/src/routes/(authenticated)/+page.svelte b/web-app/src/routes/(authenticated)/+page.svelte index 7ac662b..e2e8c7d 100644 --- a/web-app/src/routes/(authenticated)/+page.svelte +++ b/web-app/src/routes/(authenticated)/+page.svelte @@ -54,7 +54,7 @@
- Search & Sort & Filter + Search & Filter
-