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

Proposed by Colin Watson
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 Approve
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.
Revision history for this message
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
=== modified file 'lib/lp/code/model/gitrepository.py'
--- lib/lp/code/model/gitrepository.py 2015-05-19 11:29:24 +0000
+++ lib/lp/code/model/gitrepository.py 2015-05-23 16:48:17 +0000
@@ -884,6 +884,10 @@
884 operation()884 operation()
885 Store.of(self).flush()885 Store.of(self).flush()
886886
887 def _deleteRepositoryAccessGrants(self):
888 """Delete access grants for this repository prior to deleting it."""
889 getUtility(IAccessArtifactSource).delete([self])
890
887 def _deleteRepositorySubscriptions(self):891 def _deleteRepositorySubscriptions(self):
888 """Delete subscriptions for this repository prior to deleting it."""892 """Delete subscriptions for this repository prior to deleting it."""
889 subscriptions = Store.of(self).find(893 subscriptions = Store.of(self).find(
@@ -918,6 +922,7 @@
918 "Cannot delete Git repository: %s" % self.unique_name)922 "Cannot delete Git repository: %s" % self.unique_name)
919923
920 self.refs.remove()924 self.refs.remove()
925 self._deleteRepositoryAccessGrants()
921 self._deleteRepositorySubscriptions()926 self._deleteRepositorySubscriptions()
922 self._deleteJobs()927 self._deleteJobs()
923928
924929
=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
--- lib/lp/code/model/tests/test_gitrepository.py 2015-05-19 11:29:24 +0000
+++ lib/lp/code/model/tests/test_gitrepository.py 2015-05-23 16:48:17 +0000
@@ -341,6 +341,26 @@
341 self.user, BranchSubscriptionNotificationLevel.NOEMAIL, None,341 self.user, BranchSubscriptionNotificationLevel.NOEMAIL, None,
342 CodeReviewNotificationLevel.NOEMAIL, self.user)342 CodeReviewNotificationLevel.NOEMAIL, self.user)
343 self.assertTrue(self.repository.canBeDeleted())343 self.assertTrue(self.repository.canBeDeleted())
344 repository_id = self.repository.id
345 self.repository.destroySelf()
346 self.assertIsNone(
347 getUtility(IGitLookup).get(repository_id),
348 "The repository has not been deleted.")
349
350 def test_private_subscription_does_not_disable_deletion(self):
351 # A private repository that has a subscription can be deleted.
352 self.repository.transitionToInformationType(
353 InformationType.USERDATA, self.repository.owner,
354 verify_policy=False)
355 self.repository.subscribe(
356 self.user, BranchSubscriptionNotificationLevel.NOEMAIL, None,
357 CodeReviewNotificationLevel.NOEMAIL, self.user)
358 self.assertTrue(self.repository.canBeDeleted())
359 repository_id = self.repository.id
360 self.repository.destroySelf()
361 self.assertIsNone(
362 getUtility(IGitLookup).get(repository_id),
363 "The repository has not been deleted.")
344364
345 def test_landing_target_disables_deletion(self):365 def test_landing_target_disables_deletion(self):
346 # A repository with a landing target cannot be deleted.366 # A repository with a landing target cannot be deleted.