← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:snap-privacy-move-all-the-things-at-once into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:snap-privacy-move-all-the-things-at-once into launchpad:master.

Commit message:
Set information type before update

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/402812

Allow setting snap privacy and team ownership at the same time.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:snap-privacy-move-all-the-things-at-once into launchpad:master.
diff --git a/lib/lp/snappy/browser/snap.py b/lib/lp/snappy/browser/snap.py
index ac7925c..c7b0ea3 100644
--- a/lib/lp/snappy/browser/snap.py
+++ b/lib/lp/snappy/browser/snap.py
@@ -835,6 +835,10 @@ class BaseSnapEditView(SnapAuthorizeMixin, SnapInformationTypeMixin,
             if 'store_channels' in data:
                 del data['store_channels']
         need_store_reauth = self._needStoreReauth(data)
+        info_type = data.get('information_type')
+        if info_type and info_type != self.context.information_type:
+            self.context.information_type = info_type
+            del data['information_type']
         self.updateContextFromData(data)
         if need_store_reauth:
             self.requestAuthorization(self.context)
diff --git a/lib/lp/snappy/browser/tests/test_snap.py b/lib/lp/snappy/browser/tests/test_snap.py
index 486e586..2780467 100644
--- a/lib/lp/snappy/browser/tests/test_snap.py
+++ b/lib/lp/snappy/browser/tests/test_snap.py
@@ -1150,6 +1150,36 @@ class TestSnapEditView(BaseTestSnapView):
             "A public snap cannot have a private owner.",
             extract_text(find_tags_by_class(browser.contents, "message")[1]))
 
+    def test_edit_public_snap_make_private_in_one_go(self):
+        # Move a public snap to a private owner and mark it private in one go
+        series = self.factory.makeUbuntuDistroSeries()
+        with admin_logged_in():
+            snappy_series = self.factory.makeSnappySeries(
+                usable_distro_series=[series])
+        login_person(self.person)
+        private_project = self.factory.makeProduct(
+            name='private-project',
+            owner=self.person, registrant=self.person,
+            information_type=InformationType.PROPRIETARY,
+            branch_sharing_policy=BranchSharingPolicy.PROPRIETARY)
+        snap = self.factory.makeSnap(
+            registrant=self.person, owner=self.person, distroseries=series,
+            store_series=snappy_series, project=private_project)
+        private_team = self.factory.makeTeam(
+            owner=self.person, visibility=PersonVisibility.PRIVATE)
+        private_team_name = private_team.name
+
+        browser = self.getViewBrowser(snap, user=self.person)
+        browser.getLink("Edit snap package").click()
+        #browser.getControl(name="field.project").value = "private-project"
+        browser.getControl("Owner").value = [private_team_name]
+        browser.getControl(name="field.information_type").value = (
+            "PROPRIETARY")
+        browser.getControl("Update snap package").click()
+
+        login_admin()
+        self.assertEqual(InformationType.PROPRIETARY, snap.information_type)
+
     def test_edit_public_snap_private_branch(self):
         series = self.factory.makeUbuntuDistroSeries()
         with admin_logged_in():