launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #18693
[Merge] lp:~cjwatson/launchpad/git-move-personal-defaults into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/git-move-personal-defaults into lp:launchpad.
Commit message:
Clear target_default/owner_default when moving a repository to a personal namespace.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-move-personal-defaults/+merge/261041
Clear target_default/owner_default when moving a repository to a personal namespace.
I ran into this in the process of putting together an edit form for GitRepository that lets you change the target; without this it's a pain to construct a sensible UI that lets you turn a target default repository into a personal repository in a single step while also allowing the converse transformation. While it's a little bit implicit, I think it's reasonably so in this case.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-move-personal-defaults into lp:launchpad.
=== modified file 'lib/lp/code/model/gitnamespace.py'
--- lib/lp/code/model/gitnamespace.py 2015-04-28 23:25:08 +0000
+++ lib/lp/code/model/gitnamespace.py 2015-06-03 21:20:19 +0000
@@ -151,11 +151,12 @@
def validateDefaultFlags(self, repository):
"""See `IGitNamespace`."""
repository_set = getUtility(IGitRepositorySet)
- if repository.target_default and self.target != repository.target:
+ if (repository.target_default and self.has_defaults and
+ self.target != repository.target):
existing = repository_set.getDefaultRepository(self.target)
if existing is not None:
raise GitDefaultConflict(existing, self.target)
- if (repository.owner_default and
+ if (repository.owner_default and self.has_defaults and
(self.owner != repository.owner or
self.target != repository.target)):
existing = repository_set.getDefaultRepositoryForOwner(
@@ -264,6 +265,8 @@
repository.project = None
repository.distribution = None
repository.sourcepackagename = None
+ repository.target_default = False
+ repository.owner_default = False
@property
def _is_private_team(self):
=== modified file 'lib/lp/code/model/tests/test_gitnamespace.py'
--- lib/lp/code/model/tests/test_gitnamespace.py 2015-05-15 15:50:48 +0000
+++ lib/lp/code/model/tests/test_gitnamespace.py 2015-06-03 21:20:19 +0000
@@ -796,3 +796,25 @@
repository,
repository_set.getDefaultRepositoryForOwner(
another.owner, another.target))
+
+ def test_target_default_to_personal(self):
+ # Moving a target_default repository to a personal namespace is
+ # permitted, and the flag is cleared.
+ repository = self.factory.makeGitRepository()
+ repository.setTargetDefault(True)
+ namespace = get_git_namespace(repository.owner, repository.owner)
+ namespace.moveRepository(
+ repository, getUtility(ILaunchpadCelebrities).admin.teamowner)
+ self.assertNamespacesEqual(namespace, repository.namespace)
+ self.assertFalse(repository.target_default)
+
+ def test_owner_default_to_personal(self):
+ # Moving an owner_default repository to a personal namespace is
+ # permitted, and the flag is cleared.
+ repository = self.factory.makeGitRepository()
+ repository.setOwnerDefault(True)
+ namespace = get_git_namespace(repository.owner, repository.owner)
+ namespace.moveRepository(
+ repository, getUtility(ILaunchpadCelebrities).admin.teamowner)
+ self.assertNamespacesEqual(namespace, repository.namespace)
+ self.assertFalse(repository.owner_default)
Follow ups