From e96b78b7ce7a08268ed0b532ceedeb5132ebe482 Mon Sep 17 00:00:00 2001 From: thiloho <123883702+thiloho@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:09:51 +0200 Subject: [PATCH] Add OpenGraph head tags and more tests --- nix/dev-vm.nix | 1 + .../migrations/20240719071602_main_tables.sql | 1 + ...20240720132802_exposed_views_functions.sql | 2 +- .../20240724191017_row_level_security.sql | 2 +- .../migrations/20240911070907_change_log.sql | 28 ++- web-app/src/lib/db-schema.ts | 10 +- .../src/lib/templates/blog/BlogArticle.svelte | 7 +- .../src/lib/templates/blog/BlogIndex.svelte | 12 +- web-app/src/lib/templates/common/Head.svelte | 63 +++++- web-app/src/lib/templates/common/Nav.svelte | 4 +- .../src/lib/templates/docs/DocsArticle.svelte | 7 +- .../src/lib/templates/docs/DocsIndex.svelte | 12 +- .../website/[websiteId]/+page.server.ts | 3 +- .../website/[websiteId]/+page.svelte | 6 + .../[websiteId]/publish/+page.server.ts | 101 +++++---- web-app/src/routes/+layout.svelte | 1 + web-app/template-styles/common-styles.css | 205 ------------------ web-app/template-styles/variables.css | 204 +++++++++++++++++ web-app/tests/collaborator.spec.ts | 38 +++- web-app/tests/website.spec.ts | 34 +++ 20 files changed, 468 insertions(+), 273 deletions(-) create mode 100644 web-app/template-styles/variables.css diff --git a/nix/dev-vm.nix b/nix/dev-vm.nix index bbb3ceb..4e8d313 100644 --- a/nix/dev-vm.nix +++ b/nix/dev-vm.nix @@ -26,6 +26,7 @@ graphics = false; memorySize = 2048; cores = 2; + diskSize = 10240; sharedDirectories = { websites = { source = "/var/www/archtika-websites"; diff --git a/rest-api/db/migrations/20240719071602_main_tables.sql b/rest-api/db/migrations/20240719071602_main_tables.sql index 532564f..cca5554 100644 --- a/rest-api/db/migrations/20240719071602_main_tables.sql +++ b/rest-api/db/migrations/20240719071602_main_tables.sql @@ -74,6 +74,7 @@ CREATE TABLE internal.header ( CREATE TABLE internal.home ( website_id UUID PRIMARY KEY REFERENCES internal.website (id) ON DELETE CASCADE, main_content TEXT NOT NULL CHECK (TRIM(main_content) != ''), + meta_description VARCHAR(250) CHECK (TRIM(meta_description) != ''), last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(), last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL ); diff --git a/rest-api/db/migrations/20240720132802_exposed_views_functions.sql b/rest-api/db/migrations/20240720132802_exposed_views_functions.sql index 1ce0252..48aaf39 100644 --- a/rest-api/db/migrations/20240720132802_exposed_views_functions.sql +++ b/rest-api/db/migrations/20240720132802_exposed_views_functions.sql @@ -129,7 +129,7 @@ GRANT SELECT, UPDATE (logo_type, logo_text, logo_image) ON internal.header TO au GRANT SELECT, UPDATE ON api.header TO authenticated_user; -GRANT SELECT, UPDATE (main_content) ON internal.home TO authenticated_user; +GRANT SELECT, UPDATE (main_content, meta_description) ON internal.home TO authenticated_user; GRANT SELECT, UPDATE ON api.home TO authenticated_user; diff --git a/rest-api/db/migrations/20240724191017_row_level_security.sql b/rest-api/db/migrations/20240724191017_row_level_security.sql index ae41e55..5acc1a9 100644 --- a/rest-api/db/migrations/20240724191017_row_level_security.sql +++ b/rest-api/db/migrations/20240724191017_row_level_security.sql @@ -75,7 +75,7 @@ CREATE POLICY view_websites ON internal.website CREATE POLICY update_website ON internal.website FOR UPDATE - USING (internal.user_has_website_access (id, 20)); + USING (internal.user_has_website_access (id, 30)); CREATE POLICY delete_website ON internal.website FOR DELETE diff --git a/rest-api/db/migrations/20240911070907_change_log.sql b/rest-api/db/migrations/20240911070907_change_log.sql index 1011bce..cc61118 100644 --- a/rest-api/db/migrations/20240911070907_change_log.sql +++ b/rest-api/db/migrations/20240911070907_change_log.sql @@ -13,6 +13,23 @@ CREATE TABLE internal.change_log ( new_value HSTORE ); +CREATE VIEW api.change_log WITH ( security_invoker = ON +) AS +SELECT + * +FROM + internal.change_log; + +GRANT SELECT ON internal.change_log TO authenticated_user; + +GRANT SELECT ON api.change_log TO authenticated_user; + +ALTER TABLE internal.change_log ENABLE ROW LEVEL SECURITY; + +CREATE POLICY view_change_log ON internal.change_log + FOR SELECT + USING (internal.user_has_website_access (website_id, 10)); + CREATE FUNCTION internal.track_changes () RETURNS TRIGGER AS $$ @@ -109,17 +126,6 @@ CREATE TRIGGER collab_track_changes FOR EACH ROW EXECUTE FUNCTION internal.track_changes (); -CREATE VIEW api.change_log WITH ( security_invoker = ON -) AS -SELECT - * -FROM - internal.change_log; - -GRANT SELECT ON internal.change_log TO authenticated_user; - -GRANT SELECT ON api.change_log TO authenticated_user; - -- migrate:down DROP TRIGGER website_track_changes ON internal.website; diff --git a/web-app/src/lib/db-schema.ts b/web-app/src/lib/db-schema.ts index 33ae85a..4b67699 100644 --- a/web-app/src/lib/db-schema.ts +++ b/web-app/src/lib/db-schema.ts @@ -299,18 +299,26 @@ const header = { export interface Home { website_id: string; main_content: string; + meta_description: string | null; last_modified_at: Date; last_modified_by: string | null; } export interface HomeInput { website_id: string; main_content: string; + meta_description?: string | null; last_modified_at?: Date; last_modified_by?: string | null; } const home = { tableName: "home", - columns: ["website_id", "main_content", "last_modified_at", "last_modified_by"], + columns: [ + "website_id", + "main_content", + "meta_description", + "last_modified_at", + "last_modified_by" + ], requiredForInsert: ["website_id", "main_content"], primaryKey: "website_id", foreignKeys: { diff --git a/web-app/src/lib/templates/blog/BlogArticle.svelte b/web-app/src/lib/templates/blog/BlogArticle.svelte index 4a119f5..a2f334b 100644 --- a/web-app/src/lib/templates/blog/BlogArticle.svelte +++ b/web-app/src/lib/templates/blog/BlogArticle.svelte @@ -8,8 +8,10 @@ const { websiteOverview, article, - apiUrl - }: { websiteOverview: WebsiteOverview; article: Article; apiUrl: string } = $props(); + apiUrl, + websiteUrl + }: { websiteOverview: WebsiteOverview; article: Article; apiUrl: string; websiteUrl: string } = + $props();
diff --git a/web-app/src/lib/templates/blog/BlogIndex.svelte b/web-app/src/lib/templates/blog/BlogIndex.svelte index 604cb8e..a50847d 100644 --- a/web-app/src/lib/templates/blog/BlogIndex.svelte +++ b/web-app/src/lib/templates/blog/BlogIndex.svelte @@ -7,8 +7,14 @@ const { websiteOverview, apiUrl, - isLegalPage - }: { websiteOverview: WebsiteOverview; apiUrl: string; isLegalPage: boolean } = $props(); + isLegalPage, + websiteUrl + }: { + websiteOverview: WebsiteOverview; + apiUrl: string; + isLegalPage: boolean; + websiteUrl: string; + } = $props();
diff --git a/web-app/src/lib/templates/common/Head.svelte b/web-app/src/lib/templates/common/Head.svelte
index f9cd5cd..f25b977 100644
--- a/web-app/src/lib/templates/common/Head.svelte
+++ b/web-app/src/lib/templates/common/Head.svelte
@@ -1,31 +1,86 @@