2024-07-31 07:23:32 +02:00
|
|
|
-- migrate:up
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.account WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
username
|
|
|
|
|
FROM
|
|
|
|
|
internal.user
|
|
|
|
|
WHERE
|
|
|
|
|
id = (
|
|
|
|
|
CURRENT_SETTING(
|
|
|
|
|
'request.jwt.claims', TRUE
|
|
|
|
|
)::JSON ->> 'user_id')::UUID;
|
|
|
|
|
|
|
|
|
|
CREATE VIEW api.user WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
username
|
|
|
|
|
FROM
|
|
|
|
|
internal.user;
|
|
|
|
|
|
|
|
|
|
CREATE VIEW api.website WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
id,
|
2024-08-08 16:30:01 +02:00
|
|
|
user_id,
|
2024-08-03 22:06:29 +02:00
|
|
|
content_type,
|
|
|
|
|
title,
|
|
|
|
|
created_at,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.website;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.settings WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
website_id,
|
|
|
|
|
accent_color_light_theme,
|
|
|
|
|
accent_color_dark_theme,
|
|
|
|
|
favicon_image,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.settings;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.header WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
website_id,
|
|
|
|
|
logo_type,
|
|
|
|
|
logo_text,
|
|
|
|
|
logo_image,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.header;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.home WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
website_id,
|
|
|
|
|
main_content,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.home;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.article WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
website_id,
|
2024-08-07 16:25:05 +02:00
|
|
|
user_id,
|
2024-08-03 22:06:29 +02:00
|
|
|
title,
|
|
|
|
|
meta_description,
|
|
|
|
|
meta_author,
|
|
|
|
|
cover_image,
|
|
|
|
|
publication_date,
|
|
|
|
|
main_content,
|
|
|
|
|
created_at,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.article;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.footer WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
website_id,
|
|
|
|
|
additional_text,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.footer;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.collab WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
website_id,
|
|
|
|
|
user_id,
|
|
|
|
|
permission_level,
|
|
|
|
|
added_at,
|
|
|
|
|
last_modified_at,
|
|
|
|
|
last_modified_by
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.collab;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE VIEW api.change_log WITH ( security_invoker = ON
|
|
|
|
|
) AS
|
2024-08-03 22:06:29 +02:00
|
|
|
SELECT
|
|
|
|
|
website_id,
|
|
|
|
|
user_id,
|
|
|
|
|
change_summary,
|
|
|
|
|
previous_value,
|
|
|
|
|
new_value,
|
|
|
|
|
timestamp
|
2024-08-08 22:29:04 +02:00
|
|
|
FROM
|
|
|
|
|
internal.change_log;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
CREATE FUNCTION api.create_website (content_type VARCHAR(10), title VARCHAR(50), OUT website_id UUID)
|
|
|
|
|
AS $$
|
2024-07-31 07:23:32 +02:00
|
|
|
DECLARE
|
2024-07-31 10:29:46 +02:00
|
|
|
_website_id UUID;
|
2024-08-07 16:25:05 +02:00
|
|
|
_user_id UUID;
|
2024-07-31 07:23:32 +02:00
|
|
|
BEGIN
|
2024-08-08 22:29:04 +02:00
|
|
|
_user_id := (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id')::UUID;
|
2024-07-31 10:29:46 +02:00
|
|
|
INSERT INTO internal.website (content_type, title)
|
2024-08-08 22:29:04 +02:00
|
|
|
VALUES (create_website.content_type, create_website.title)
|
|
|
|
|
RETURNING
|
|
|
|
|
id INTO _website_id;
|
2024-07-31 10:29:46 +02:00
|
|
|
INSERT INTO internal.settings (website_id)
|
2024-08-08 22:29:04 +02:00
|
|
|
VALUES (_website_id);
|
2024-07-31 10:29:46 +02:00
|
|
|
INSERT INTO internal.header (website_id, logo_text)
|
2024-08-08 22:29:04 +02:00
|
|
|
VALUES (_website_id, 'archtika ' || create_website.content_type);
|
2024-07-31 10:29:46 +02:00
|
|
|
INSERT INTO internal.home (website_id, main_content)
|
2024-08-08 22:29:04 +02:00
|
|
|
VALUES (_website_id, '
|
2024-08-08 20:31:38 +02:00
|
|
|
## About
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 20:31:38 +02:00
|
|
|
archtika is a FLOSS, modern, performant and lightweight CMS (Content Mangement System) in the form of a web application. It allows you to easily create, manage and publish minimal, responsive and SEO friendly blogging and documentation websites with official, professionally designed templates.
|
|
|
|
|
|
|
|
|
|
It is also possible to add contributors to your sites, which is very useful for larger projects where, for example, several people are constantly working on the documentation.
|
|
|
|
|
|
|
|
|
|
## How it works
|
|
|
|
|
|
|
|
|
|
For the backend, PostgreSQL is used in combination with PostgREST to create a RESTful API. JSON web tokens along with row-level security control authentication and authorisation flows.
|
|
|
|
|
|
|
|
|
|
The web application uses SvelteKit with SSR (Server Side Rendering) and Svelte version 5, currently in beta.
|
|
|
|
|
|
|
|
|
|
NGINX is used to deploy the websites, serving the static site files from the `/var/www/archtika-websites` directory. The static files can be found in this directory via the path `<user_id>/<website_id>`, which is dynamically created by the web application.
|
|
|
|
|
');
|
2024-07-31 10:29:46 +02:00
|
|
|
INSERT INTO internal.footer (website_id, additional_text)
|
2024-08-08 22:29:04 +02:00
|
|
|
VALUES (_website_id, 'archtika is a free, open, modern, performant and lightweight CMS');
|
2024-07-31 10:29:46 +02:00
|
|
|
website_id := _website_id;
|
2024-07-31 07:23:32 +02:00
|
|
|
END;
|
2024-08-08 22:29:04 +02:00
|
|
|
$$
|
|
|
|
|
LANGUAGE plpgsql
|
|
|
|
|
SECURITY DEFINER;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
2024-08-08 22:29:04 +02:00
|
|
|
GRANT EXECUTE ON FUNCTION api.create_website (VARCHAR(10), VARCHAR(50)) TO authenticated_user;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
|
|
|
|
-- Security invoker only works on views if the user has access to the underlying table
|
|
|
|
|
GRANT SELECT ON internal.user TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-08-05 19:33:35 +02:00
|
|
|
GRANT SELECT ON api.account TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 07:23:32 +02:00
|
|
|
GRANT SELECT ON api.user TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE, DELETE ON internal.website TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON internal.settings TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON api.settings TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON internal.header TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON api.header TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON internal.home TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON api.home TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, INSERT, UPDATE, DELETE ON internal.article TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON internal.footer TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, UPDATE ON api.footer TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, INSERT, UPDATE, DELETE ON internal.collab TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT, INSERT, UPDATE, DELETE ON api.collab TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
GRANT SELECT ON internal.change_log TO authenticated_user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
|
|
|
|
GRANT SELECT ON api.change_log TO authenticated_user;
|
2024-07-31 07:23:32 +02:00
|
|
|
|
|
|
|
|
-- migrate:down
|
2024-08-08 22:29:04 +02:00
|
|
|
DROP FUNCTION api.create_website (VARCHAR(10), VARCHAR(50));
|
2024-07-31 10:29:46 +02:00
|
|
|
|
|
|
|
|
DROP VIEW api.change_log;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.collab;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.footer;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.home;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.article;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.header;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.settings;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
DROP VIEW api.website;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
2024-08-05 19:33:35 +02:00
|
|
|
DROP VIEW api.user;
|
2024-08-08 22:29:04 +02:00
|
|
|
|
|
|
|
|
DROP VIEW api.account;
|
|
|
|
|
|