← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:oci-project-admin-ui into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:oci-project-admin-ui into launchpad:master.

Commit message:
Add UI for editing Distribution.oci_project_admin

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1847444 in Launchpad itself: "Support OCI image building"
  https://bugs.launchpad.net/launchpad/+bug/1847444

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/382606
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:oci-project-admin-ui into launchpad:master.
diff --git a/lib/lp/registry/browser/configure.zcml b/lib/lp/registry/browser/configure.zcml
index a397a9b..2fdc177 100644
--- a/lib/lp/registry/browser/configure.zcml
+++ b/lib/lp/registry/browser/configure.zcml
@@ -2258,6 +2258,13 @@
         template="../../app/templates/generic-edit.pt"
         />
     <browser:page
+        name="+select-oci-project-admins"
+        for="lp.registry.interfaces.distribution.IDistribution"
+        class="lp.registry.browser.distribution.DistributionChangeOCIProjectAdminView"
+        permission="launchpad.Edit"
+        template="../../app/templates/generic-edit.pt"
+        />
+    <browser:page
         name="+pubconf"
         for="lp.registry.interfaces.distribution.IDistribution"
         class="lp.registry.browser.distribution.DistributionPublisherConfigView"
diff --git a/lib/lp/registry/browser/distribution.py b/lib/lp/registry/browser/distribution.py
index 5d13b7a..4b3b18c 100644
--- a/lib/lp/registry/browser/distribution.py
+++ b/lib/lp/registry/browser/distribution.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2019 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Browser views for distributions."""
@@ -13,6 +13,7 @@ __all__ = [
     'DistributionArchivesView',
     'DistributionChangeMembersView',
     'DistributionChangeMirrorAdminView',
+    'DistributionChangeOCIProjectAdminView',
     'DistributionCountryArchiveMirrorsView',
     'DistributionDisabledMirrorsView',
     'DistributionEditView',
@@ -328,6 +329,7 @@ class DistributionOverviewMenu(ApplicationMenu, DistributionLinksMixin):
         'search',
         'members',
         'mirror_admin',
+        'oci_project_admin',
         'reassign',
         'addseries',
         'series',
@@ -416,6 +418,11 @@ class DistributionOverviewMenu(ApplicationMenu, DistributionLinksMixin):
         enabled = self.context.supports_mirrors
         return Link('+selectmirroradmins', text, enabled=enabled, icon='edit')
 
+    @enabled_with_permission('launchpad.Edit')
+    def oci_project_admin(self):
+        text = 'Change OCI project admins'
+        return Link('+select-oci-project-admins', text, icon='edit')
+
     def search(self):
         text = 'Search packages'
         return Link('+search', text, icon='search')
@@ -684,6 +691,21 @@ class DistributionView(PillarViewMixin, HasAnnouncementsView, FeedsMixin):
             edit_view='+selectmirroradmins', null_display_value=empty_value,
             step_title='Select a new mirror administrator')
 
+    @property
+    def oci_project_admin_widget(self):
+        if canWrite(self.context, 'oci_project_admin'):
+            empty_value = ' Specify an OCI project administrator'
+        else:
+            empty_value = 'None'
+        return InlinePersonEditPickerWidget(
+            self.context, IDistribution['oci_project_admin'],
+            format_link(
+                self.context.oci_project_admin, empty_value=empty_value),
+            header='Change the OCI project administrator',
+            edit_view='+select-oci-project-admins',
+            null_display_value=empty_value,
+            step_title='Select a new OCI project administrator')
+
     def linkedMilestonesForSeries(self, series):
         """Return a string of linkified milestones in the series."""
         # Listify to remove repeated queries.
@@ -1056,6 +1078,18 @@ class DistributionChangeMirrorAdminView(RegistryEditFormView):
         return "Change the %s mirror administrator" % self.context.displayname
 
 
+class DistributionChangeOCIProjectAdminView(RegistryEditFormView):
+    """A view to change the OCI project administrator."""
+    schema = IDistribution
+    field_names = ['oci_project_admin']
+
+    @property
+    def label(self):
+        """See `LaunchpadFormView`."""
+        return "Change the %s OCI project administrator" % (
+            self.context.displayname)
+
+
 class DistributionChangeMembersView(RegistryEditFormView):
     """A view to change the members team."""
     schema = IDistribution
diff --git a/lib/lp/registry/browser/tests/distribution-views.txt b/lib/lp/registry/browser/tests/distribution-views.txt
index 5fdb281..810f118 100644
--- a/lib/lp/registry/browser/tests/distribution-views.txt
+++ b/lib/lp/registry/browser/tests/distribution-views.txt
@@ -210,6 +210,55 @@ Only admins and owners can access the view.
     False
 
 
+Changing a distribution OCI project administrator
+-------------------------------------------------
+
+The +select-oci-project-admins view allows the owner or admin to change the
+OCI project administrator.
+
+    >>> login("admin@xxxxxxxxxxxxx")
+    >>> view = create_view(distribution, '+select-oci-project-admins')
+    >>> print(view.label)
+    Change the YoUbuntu OCI project administrator
+
+    >>> print(view.page_title)
+    Change the YoUbuntu OCI project administrator
+
+    >>> print(view.cancel_url)
+    http://launchpad.test/youbuntu
+
+The view accepts the oci_project_admin field.
+
+    >>> print(distribution.oci_project_admin)
+    None
+
+    >>> view.field_names
+    ['oci_project_admin']
+
+    >>> form = {
+    ...     'field.oci_project_admin': 'no-priv',
+    ...     'field.actions.change': 'Change',
+    ...     }
+    >>> view = create_initialized_view(
+    ...     distribution, '+select-oci-project-admins', form=form)
+    >>> view.errors
+    []
+    >>> print(view.next_url)
+    http://launchpad.test/youbuntu
+
+    >>> print(distribution.oci_project_admin.name)
+    no-priv
+
+Only admins and owners can access the view.
+
+    >>> check_permission('launchpad.Edit', view)
+    True
+
+    >>> login('no-priv@xxxxxxxxxxxxx')
+    >>> check_permission('launchpad.Edit', view)
+    False
+
+
 Changing a distribution members team
 ------------------------------------
 
diff --git a/lib/lp/registry/configure.zcml b/lib/lp/registry/configure.zcml
index f3bcd9f..1c73f4b 100644
--- a/lib/lp/registry/configure.zcml
+++ b/lib/lp/registry/configure.zcml
@@ -1831,6 +1831,7 @@
                 members
                 mirror_admin
                 mugshot
+                oci_project_admin
                 official_answers
                 official_blueprints
                 official_malone
diff --git a/lib/lp/registry/templates/distribution-details.pt b/lib/lp/registry/templates/distribution-details.pt
index 955e52c..1d2b0cf 100644
--- a/lib/lp/registry/templates/distribution-details.pt
+++ b/lib/lp/registry/templates/distribution-details.pt
@@ -26,6 +26,11 @@
       <dt>Mirror admins:</dt>
       <dd tal:content="structure view/mirror_admin_widget" />
     </dl>
+
+    <dl id="oci-project-admins">
+      <dt>OCI project admins:</dt>
+      <dd tal:content="structure view/oci_project_admin_widget" />
+    </dl>
   </div>
 
   <dl id="uploaders" style="clear:left">