Show logs and usernames for deleted users and remove svg mimetype for client side

This commit is contained in:
thiloho
2024-09-14 15:12:08 +02:00
parent 79d1c9f5c7
commit 5f38500b9c
11 changed files with 119 additions and 95 deletions

View File

@@ -2,19 +2,32 @@
CREATE FUNCTION internal.update_last_modified ()
RETURNS TRIGGER
AS $$
DECLARE
_user_id UUID := (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id')::UUID;
BEGIN
NEW.last_modified_at = CLOCK_TIMESTAMP();
NEW.last_modified_by = (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id')::UUID;
IF (NOT EXISTS (
SELECT
id
FROM
internal.user
WHERE
id = _user_id)) THEN
RETURN COALESCE(NEW, OLD);
END IF;
IF TG_OP != 'DELETE' THEN
NEW.last_modified_at = CLOCK_TIMESTAMP();
NEW.last_modified_by = _user_id;
END IF;
IF TG_TABLE_NAME != 'website' THEN
UPDATE
internal.website
SET
last_modified_at = CLOCK_TIMESTAMP(),
last_modified_by = (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id')::UUID
last_modified_by = _user_id
WHERE
id = COALESCE(NEW.website_id, OLD.website_id);
END IF;
RETURN NEW;
RETURN COALESCE(NEW, OLD);
END;
$$
LANGUAGE plpgsql;