Merge lp:~stevenk/launchpad/populate-branch-ap into lp:launchpad

Proposed by Steve Kowalik on 2012-06-19
Status: Merged
Approved by: William Grant on 2012-06-20
Approved revision: no longer in the source branch.
Merged at revision: 15453
Proposed branch: lp:~stevenk/launchpad/populate-branch-ap
Merge into: lp:launchpad
Diff against target: 110 lines (+50/-0)
3 files modified
database/schema/security.cfg (+2/-0)
lib/lp/scripts/garbo.py (+22/-0)
lib/lp/scripts/tests/test_garbo.py (+26/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/populate-branch-ap
Reviewer Review Type Date Requested Status
William Grant code 2012-06-19 Approve on 2012-06-20
Review via email: mp+110950@code.launchpad.net

Commit Message

Populate Branch.access_policy via a garbo job.

Description of the Change

With the new columns of access_policy and access_grants now glued to branch, we should populate them. They should start slowly populating as branches are created or transitioned to a private information type. Let's help it along with a garbo job. This does not address AccessArtifactGrants, they will be dealt with in a later branch.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2012-06-18 02:56:14 +0000
3+++ database/schema/security.cfg 2012-06-19 05:33:01 +0000
4@@ -2194,6 +2194,8 @@
5
6 [garbo]
7 groups=script,read
8+public.accessartifact = SELECT, INSERT
9+public.accesspolicyartifact = SELECT, INSERT
10 public.account = SELECT, DELETE
11 public.answercontact = SELECT, DELETE
12 public.branch = SELECT, UPDATE
13
14=== modified file 'lib/lp/scripts/garbo.py'
15--- lib/lp/scripts/garbo.py 2012-06-12 06:08:30 +0000
16+++ lib/lp/scripts/garbo.py 2012-06-19 05:33:01 +0000
17@@ -51,6 +51,7 @@
18 MAX_SAMPLE_SIZE,
19 )
20 from lp.code.interfaces.revision import IRevisionSet
21+from lp.code.model.branch import Branch
22 from lp.code.model.codeimportevent import CodeImportEvent
23 from lp.code.model.codeimportresult import CodeImportResult
24 from lp.code.model.revision import (
25@@ -58,6 +59,7 @@
26 RevisionCache,
27 )
28 from lp.hardwaredb.model.hwdb import HWSubmission
29+from lp.registry.enums import PRIVATE_INFORMATION_TYPES
30 from lp.registry.model.person import Person
31 from lp.services.config import config
32 from lp.services.database import postgresql
33@@ -1137,6 +1139,25 @@
34 transaction.commit()
35
36
37+class PopulateBranchAccessPolicy(TunableLoop):
38+
39+ maximum_chunk_size = 5000
40+
41+ def findBranches(self):
42+ return IMasterStore(Branch).find(
43+ Branch,
44+ Branch.information_type.is_in(PRIVATE_INFORMATION_TYPES),
45+ SQL("Branch.access_policy IS NULL"))
46+
47+ def isDone(self):
48+ return self.findBranches().is_empty()
49+
50+ def __call__(self, chunk_size):
51+ for branch in self.findBranches()[:chunk_size]:
52+ branch._reconcileAccess()
53+ transaction.commit()
54+
55+
56 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
57 """Abstract base class to run a collection of TunableLoops."""
58 script_name = None # Script name for locking and database user. Override.
59@@ -1392,6 +1413,7 @@
60 DuplicateSessionPruner,
61 BugHeatUpdater,
62 BugTaskFlattener,
63+ PopulateBranchAccessPolicy,
64 ]
65 experimental_tunable_loops = []
66
67
68=== modified file 'lib/lp/scripts/tests/test_garbo.py'
69--- lib/lp/scripts/tests/test_garbo.py 2012-06-12 06:08:30 +0000
70+++ lib/lp/scripts/tests/test_garbo.py 2012-06-19 05:33:01 +0000
71@@ -55,6 +55,8 @@
72 )
73 from lp.code.model.codeimportevent import CodeImportEvent
74 from lp.code.model.codeimportresult import CodeImportResult
75+from lp.registry.enums import InformationType
76+from lp.registry.interfaces.accesspolicy import IAccessPolicyArtifactSource
77 from lp.registry.interfaces.distribution import IDistributionSet
78 from lp.registry.interfaces.person import IPersonSet
79 from lp.scripts.garbo import (
80@@ -1149,6 +1151,30 @@
81 self.runHourly()
82 self.assertEqual((task.id,), get_flat())
83
84+ def test_PopulateBranchAccessPolicy(self):
85+ # Branches without a access_policy have one set by the job.
86+ with dbuser('testadmin'):
87+ branch = self.factory.makeBranch()
88+
89+ def get_access_policy():
90+ return IMasterStore(BugTask).execute(
91+ 'SELECT access_policy FROM branch WHERE id = ?',
92+ (branch.id,)).get_one()[0]
93+
94+ # The branch is public, so running the garbo job will have no effect.
95+ self.runHourly()
96+ self.assertIs(None, get_access_policy())
97+
98+ with dbuser('testadmin'):
99+ branch.transitionToInformationType(
100+ InformationType.USERDATA, branch.owner, verify_policy=False)
101+ access_artifact = self.factory.makeAccessArtifact(concrete=branch)
102+ apas = getUtility(IAccessPolicyArtifactSource).findByArtifact(
103+ (access_artifact,))
104+ # Now it will be set.
105+ self.runHourly()
106+ self.assertEqual(apas[0].policy.id, get_access_policy())
107+
108
109 class TestGarboTasks(TestCaseWithFactory):
110 layer = LaunchpadZopelessLayer