Merge lp:~wgrant/launchpad/legacy-access-type into lp:launchpad/db-devel

Proposed by William Grant on 2012-03-20
Status: Merged
Approved by: William Grant on 2012-03-21
Approved revision: no longer in the source branch.
Merged at revision: 11479
Proposed branch: lp:~wgrant/launchpad/legacy-access-type
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~stevenk/launchpad/bugs-use-information_type
Diff against target: 123 lines (+119/-0)
1 file modified
database/schema/patch-2209-11-4.sql (+119/-0)
To merge this branch: bzr merge lp:~wgrant/launchpad/legacy-access-type
Reviewer Review Type Date Requested Status
Stuart Bishop db 2012-03-20 Approve on 2012-03-20
Review via email: mp+98342@code.launchpad.net

Commit Message

The bug_mirror_legacy_access and bug_mirror_legacy_access_trig DB functions now use information_type instead of private and security_related.

Description of the Change

Bug.information_type is the new Bug.private and Bug.security_related, so the temporary access mirroring triggers need to use it instead.

This can only land once it's populated and fully in use on production.

To post a comment you must log in.
William Grant (wgrant) wrote :

http://pastebin.ubuntu.com/891784/ is a diff from 2209-11-3.

Stuart Bishop (stub) wrote :

This seems correct.

You can use 'bug%ROWTYPE' or 'bugtask%ROWTYPE' instead of 'record', but there is little practical difference apart from maybe some type checking.

review: Approve (db)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'database/schema/patch-2209-11-4.sql'
2--- database/schema/patch-2209-11-4.sql 1970-01-01 00:00:00 +0000
3+++ database/schema/patch-2209-11-4.sql 2012-03-21 05:03:20 +0000
4@@ -0,0 +1,119 @@
5+-- Copyright 2012 Canonical Ltd. This software is licensed under the
6+-- GNU Affero General Public License version 3 (see the file LICENSE).
7+
8+SET client_min_messages=ERROR;
9+
10+-- These two functions are just like 2209-11-3 except using
11+-- information_type instead of private and security_related.
12+
13+CREATE OR REPLACE FUNCTION bug_mirror_legacy_access(bug_id integer) RETURNS void
14+ LANGUAGE plpgsql SECURITY DEFINER SET search_path = public
15+ AS $$
16+DECLARE
17+ bug_row record;
18+ artifact_id integer;
19+ bugtask_row record;
20+ pillars record;
21+ access_policies integer[];
22+BEGIN
23+ SELECT * INTO bug_row FROM bug WHERE id = bug_id;
24+ SELECT id INTO artifact_id FROM AccessArtifact WHERE bug = bug_id;
25+ -- 3 == EMBARGOEDSECURITY, 4 == USERDATA, 5 == PROPRIETARY
26+ IF bug_row.information_type NOT IN (3, 4, 5) THEN
27+ IF artifact_id IS NOT NULL THEN
28+ -- Bug is public, but there are access control rows. Destroy them.
29+ DELETE FROM AccessArtifactGrant WHERE artifact = artifact_id;
30+ DELETE FROM AccessPolicyArtifact WHERE artifact = artifact_id;
31+ DELETE FROM AccessArtifact WHERE id = artifact_id;
32+ END IF;
33+ ELSE
34+ -- Bug is private. Add missing rows, remove superfluous ones.
35+
36+ -- Ensure that there's a corresponding AccessArtifact.
37+ IF artifact_id IS NULL THEN
38+ INSERT INTO AccessArtifact (bug) VALUES (bug_row.id)
39+ RETURNING id INTO artifact_id;
40+ END IF;
41+
42+ -- Ensure that the AccessArtifactGrants match BugSubscriptions.
43+ DELETE FROM AccessArtifactGrant
44+ WHERE
45+ artifact = artifact_id
46+ AND grantee NOT IN (
47+ SELECT person FROM bugsubscription WHERE bug = bug_id);
48+ INSERT INTO AccessArtifactGrant
49+ (artifact, grantee, grantor, date_created)
50+ SELECT DISTINCT ON (artifact_id, BugSubscription.person)
51+ artifact_id, BugSubscription.person,
52+ BugSubscription.subscribed_by, BugSubscription.date_created
53+ FROM
54+ BugSubscription
55+ LEFT JOIN AccessArtifactGrant
56+ ON (AccessArtifactGrant.grantee =
57+ BugSubscription.person
58+ AND AccessArtifactGrant.artifact = artifact_id)
59+ WHERE
60+ AccessArtifactGrant.grantee IS NULL
61+ AND BugSubscription.bug = bug_id
62+ ORDER BY
63+ artifact_id,
64+ BugSubscription.person,
65+ BugSubscription.date_created;
66+
67+ -- Ensure that AccessPolicyArtifacts match the implied policy
68+ -- type and the tasks' pillars.
69+ SELECT
70+ array_agg(
71+ DISTINCT COALESCE(bugtask.product, productseries.product))
72+ AS products,
73+ array_agg(
74+ DISTINCT COALESCE(bugtask.distribution,
75+ distroseries.distribution))
76+ AS distributions
77+ INTO pillars
78+ FROM
79+ bugtask
80+ LEFT JOIN productseries
81+ ON productseries.id = bugtask.productseries
82+ LEFT JOIN distroseries
83+ ON distroseries.id = bugtask.distroseries
84+ WHERE bug = bug_id;
85+ SELECT array_agg(id) FROM AccessPolicy
86+ INTO access_policies
87+ WHERE
88+ type = bug_row.information_type
89+ AND (
90+ (product IS NOT NULL AND product = ANY(pillars.products))
91+ OR (distribution IS NOT NULL
92+ AND distribution = ANY(pillars.distributions)));
93+ DELETE FROM AccessPolicyArtifact
94+ WHERE
95+ artifact = artifact_id
96+ AND policy != ALL(access_policies);
97+ INSERT INTO AccessPolicyArtifact
98+ (artifact, policy)
99+ SELECT DISTINCT artifact_id, policy
100+ FROM unnest(access_policies) AS policy
101+ EXCEPT
102+ SELECT artifact_id, policy FROM AccessPolicyArtifact
103+ WHERE artifact = artifact_id;
104+ END IF;
105+END;
106+$$;
107+
108+CREATE OR REPLACE FUNCTION bug_mirror_legacy_access_trig() RETURNS trigger
109+ LANGUAGE plpgsql
110+ AS $$
111+BEGIN
112+ IF TG_OP = 'INSERT' THEN
113+ PERFORM bug_mirror_legacy_access(NEW.id);
114+ ELSIF TG_OP = 'UPDATE' THEN
115+ IF NEW.information_type IS DISTINCT FROM OLD.information_type THEN
116+ PERFORM bug_mirror_legacy_access(OLD.id);
117+ END IF;
118+ END IF;
119+ RETURN NULL;
120+END;
121+$$;
122+
123+INSERT INTO LaunchpadDatabaseRevision VALUES (2209, 11, 4);

Subscribers

People subscribed via source and target branches

to status/vote changes: