← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:snap-authorize-link into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:snap-authorize-link into launchpad:master.

Commit message:
Add navigation link to Snap:+authorize

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This gets sent by email to the build requester when a build fails to upload to the store due to an authorization error, but email gets lost or missed and people often ask how to reauthorize a snap.  Add an explicit navigation link for this.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:snap-authorize-link into launchpad:master.
diff --git a/lib/lp/snappy/browser/snap.py b/lib/lp/snappy/browser/snap.py
index dba1b18..643e989 100644
--- a/lib/lp/snappy/browser/snap.py
+++ b/lib/lp/snappy/browser/snap.py
@@ -1,4 +1,4 @@
-# Copyright 2015-2019 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Snap views."""
@@ -143,7 +143,7 @@ class SnapNavigationMenu(NavigationMenu):
 
     facet = 'overview'
 
-    links = ('admin', 'edit', 'webhooks', 'delete')
+    links = ('admin', 'edit', 'webhooks', 'authorize', 'delete')
 
     @enabled_with_permission('launchpad.Admin')
     def admin(self):
@@ -160,6 +160,14 @@ class SnapNavigationMenu(NavigationMenu):
             enabled=bool(getFeatureFlag('webhooks.new.enabled')))
 
     @enabled_with_permission('launchpad.Edit')
+    def authorize(self):
+        if self.context.store_secrets:
+            text = 'Reauthorize store uploads'
+        else:
+            text = 'Authorize store uploads'
+        return Link('+authorize', text, icon='edit')
+
+    @enabled_with_permission('launchpad.Edit')
     def delete(self):
         return Link('+delete', 'Delete snap package', icon='trash-icon')
 
diff --git a/lib/lp/snappy/browser/tests/test_snap.py b/lib/lp/snappy/browser/tests/test_snap.py
index 0a481dc..a7a4d7b 100644
--- a/lib/lp/snappy/browser/tests/test_snap.py
+++ b/lib/lp/snappy/browser/tests/test_snap.py
@@ -1,4 +1,4 @@
-# Copyright 2015-2019 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test snap package views."""
@@ -1626,6 +1626,28 @@ class TestSnapView(BaseTestSnapView):
         self.assertEqual(
             "track/stable/fix-123, track/edge/fix-123", view.store_channels)
 
+    def test_authorize_navigation_no_store_secrets(self):
+        # A snap with no store secrets has an "Authorize store uploads"
+        # navigation link.
+        owner = self.factory.makePerson()
+        snap = self.factory.makeSnap(registrant=owner, owner=owner)
+        authorize_url = canonical_url(snap, view_name="+authorize")
+        browser = self.getViewBrowser(snap, user=owner)
+        authorize_link = browser.getLink("Authorize store uploads")
+        self.assertEqual(authorize_url, authorize_link.url)
+
+    def test_authorize_navigation_store_secrets(self):
+        # A snap with store secrets has an "Reauthorize store uploads"
+        # navigation link.
+        owner = self.factory.makePerson()
+        snap = self.factory.makeSnap(
+            registrant=owner, owner=owner,
+            store_secrets={"root": Macaroon().serialize()})
+        authorize_url = canonical_url(snap, view_name="+authorize")
+        browser = self.getViewBrowser(snap, user=owner)
+        authorize_link = browser.getLink("Reauthorize store uploads")
+        self.assertEqual(authorize_url, authorize_link.url)
+
 
 class TestSnapRequestBuildsView(BaseTestSnapView):