Merge lp:~cjwatson/launchpad/git-repository-delete-access into lp:launchpad

Proposed by Colin Watson on 2015-05-23
Status: Merged
Merged at revision: 17523
Proposed branch: lp:~cjwatson/launchpad/git-repository-delete-access
Merge into: lp:launchpad
Diff against target: 53 lines (+25/-0)
2 files modified
lib/lp/code/model/gitrepository.py (+5/-0)
lib/lp/code/model/tests/test_gitrepository.py (+20/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-repository-delete-access
Reviewer Review Type Date Requested Status
William Grant code 2015-05-23 Approve on 2015-05-23
Review via email: mp+260009@code.launchpad.net

Commit message

Fix deletion of Git repositories with access grants.

Description of the change

Fix deletion of Git repositories with access grants. I hope I got the access code right since I'm not as familiar with the model as I perhaps should be ...

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

That's the right thing to do. See, for example, what reconcile_access_for_artifact does in the public case.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/gitrepository.py'
2--- lib/lp/code/model/gitrepository.py 2015-05-19 11:29:24 +0000
3+++ lib/lp/code/model/gitrepository.py 2015-05-23 16:48:17 +0000
4@@ -884,6 +884,10 @@
5 operation()
6 Store.of(self).flush()
7
8+ def _deleteRepositoryAccessGrants(self):
9+ """Delete access grants for this repository prior to deleting it."""
10+ getUtility(IAccessArtifactSource).delete([self])
11+
12 def _deleteRepositorySubscriptions(self):
13 """Delete subscriptions for this repository prior to deleting it."""
14 subscriptions = Store.of(self).find(
15@@ -918,6 +922,7 @@
16 "Cannot delete Git repository: %s" % self.unique_name)
17
18 self.refs.remove()
19+ self._deleteRepositoryAccessGrants()
20 self._deleteRepositorySubscriptions()
21 self._deleteJobs()
22
23
24=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
25--- lib/lp/code/model/tests/test_gitrepository.py 2015-05-19 11:29:24 +0000
26+++ lib/lp/code/model/tests/test_gitrepository.py 2015-05-23 16:48:17 +0000
27@@ -341,6 +341,26 @@
28 self.user, BranchSubscriptionNotificationLevel.NOEMAIL, None,
29 CodeReviewNotificationLevel.NOEMAIL, self.user)
30 self.assertTrue(self.repository.canBeDeleted())
31+ repository_id = self.repository.id
32+ self.repository.destroySelf()
33+ self.assertIsNone(
34+ getUtility(IGitLookup).get(repository_id),
35+ "The repository has not been deleted.")
36+
37+ def test_private_subscription_does_not_disable_deletion(self):
38+ # A private repository that has a subscription can be deleted.
39+ self.repository.transitionToInformationType(
40+ InformationType.USERDATA, self.repository.owner,
41+ verify_policy=False)
42+ self.repository.subscribe(
43+ self.user, BranchSubscriptionNotificationLevel.NOEMAIL, None,
44+ CodeReviewNotificationLevel.NOEMAIL, self.user)
45+ self.assertTrue(self.repository.canBeDeleted())
46+ repository_id = self.repository.id
47+ self.repository.destroySelf()
48+ self.assertIsNone(
49+ getUtility(IGitLookup).get(repository_id),
50+ "The repository has not been deleted.")
51
52 def test_landing_target_disables_deletion(self):
53 # A repository with a landing target cannot be deleted.