From 1f647374a8cdf3bc5c2d29ff8be277b027925c8c Mon Sep 17 00:00:00 2001
From: Freya Murphy <freya@freyacat.org>
Date: Sat, 30 Mar 2024 16:36:54 -0400
Subject: post comments, refactor post loading, hide load more btn

---
 db/rest/comment/api_comment_delete.sql | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 db/rest/comment/api_comment_delete.sql

(limited to 'db/rest/comment/api_comment_delete.sql')

diff --git a/db/rest/comment/api_comment_delete.sql b/db/rest/comment/api_comment_delete.sql
new file mode 100644
index 0000000..d7db8a4
--- /dev/null
+++ b/db/rest/comment/api_comment_delete.sql
@@ -0,0 +1,31 @@
+CREATE FUNCTION _api.comment_delete()
+RETURNS TRIGGER
+LANGUAGE plpgsql VOLATILE
+AS $BODY$
+DECLARE
+	_user_id INTEGER;
+BEGIN
+	_user_id = _api.get_user_id();
+
+	IF OLD.user_id <> _user_id THEN
+		PERFORM _api.raise_deny();
+	END IF;
+
+	DELETE FROM admin.comment
+	WHERE user_id = _user_id
+	AND id = OLD.id;
+END
+$BODY$;
+
+GRANT EXECUTE ON FUNCTION _api.comment_delete()
+	TO rest_user;
+GRANT DELETE ON TABLE api.comment
+	TO rest_user;
+GRANT DELETE ON TABLE admin.comment
+	TO rest_user;
+
+CREATE TRIGGER api_comment_delete_trgr
+	INSTEAD OF DELETE
+			ON api.comment
+			FOR EACH ROW
+				EXECUTE PROCEDURE _api.comment_delete();
-- 
cgit v1.2.3-freya

