xssbook2/db/rest/comment/api_comment_delete.sql

31 lines
613 B
PL/PgSQL

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();