Coverage for dak/dakdb/update91.py: 100%
1 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
1"""
2per-queue NEW comments and permissions
4@contact: Debian FTP Master <ftpmaster@debian.org>
5@copyright: 2012 Ansgar Burchardt <ansgar@debian.org>
6@license: GNU General Public License version 2 or later
7"""
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23################################################################################
25statements = [
26 """
27ALTER TABLE new_comments
28ADD COLUMN policy_queue_id INTEGER REFERENCES policy_queue(id)
29""",
30 """
31UPDATE new_comments
32SET policy_queue_id = (SELECT id FROM policy_queue WHERE queue_name = 'new')
33""",
34 """
35ALTER TABLE new_comments ALTER COLUMN policy_queue_id SET NOT NULL
36""",
37 """
38CREATE OR REPLACE FUNCTION trigger_check_policy_queue_permission() RETURNS TRIGGER
39SET search_path = public, pg_temp
40LANGUAGE plpgsql
41AS $$
42DECLARE
43 v_row RECORD;
44 v_suite_id suite.id%TYPE;
45 v_policy_queue_name policy_queue.queue_name%TYPE;
46BEGIN
48 CASE TG_OP
49 WHEN 'INSERT', 'UPDATE' THEN
50 v_row := NEW;
51 WHEN 'DELETE' THEN
52 v_row := OLD;
53 ELSE
54 RAISE EXCEPTION 'Unexpected TG_OP (%)', TG_OP;
55 END CASE;
57 IF TG_OP = 'UPDATE' AND OLD.policy_queue_id != NEW.policy_queue_id THEN
58 RAISE EXCEPTION 'Cannot change policy_queue_id';
59 END IF;
61 SELECT suite_id, queue_name INTO STRICT v_suite_id, v_policy_queue_name
62 FROM policy_queue WHERE id = v_row.policy_queue_id;
63 IF NOT has_suite_permission(TG_OP, v_suite_id) THEN
64 RAISE EXCEPTION 'Not allowed to % in %', TG_OP, v_policy_queue_name;
65 END IF;
67 RETURN v_row;
69END;
70$$
71""",
72 """
73CREATE CONSTRAINT TRIGGER trigger_new_comments_permission
74 AFTER INSERT OR UPDATE OR DELETE
75 ON new_comments
76 FOR EACH ROW
77 EXECUTE PROCEDURE trigger_check_policy_queue_permission()
78""",
79]