← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/launchpad:oci-recipe-push-rules-view into launchpad:master

 

Ioana Lasc has proposed merging ~ilasc/launchpad:oci-recipe-push-rules-view into launchpad:master.

Commit message:
Add View for OCI push rules

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Add View for OCI push rules
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:oci-recipe-push-rules-view into launchpad:master.
diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
index 5fcab06..356ac1c 100644
--- a/lib/lp/oci/browser/ocirecipe.py
+++ b/lib/lp/oci/browser/ocirecipe.py
@@ -184,6 +184,15 @@ class OCIRecipeView(LaunchpadView):
     def builds(self):
         return builds_for_recipe(self.context)
 
+    @cachedproperty
+    def push_rules(self):
+        return list(
+            getUtility(IOCIPushRuleSet).findByRecipe(self.context))
+
+    @property
+    def has_push_rules(self):
+        return len(self.push_rules) > 0
+
     @property
     def person_picker(self):
         field = copy_field(
diff --git a/lib/lp/oci/interfaces/ocipushrule.py b/lib/lp/oci/interfaces/ocipushrule.py
index b889cdd..d335bd3 100644
--- a/lib/lp/oci/interfaces/ocipushrule.py
+++ b/lib/lp/oci/interfaces/ocipushrule.py
@@ -127,5 +127,8 @@ class IOCIPushRuleSet(Interface):
     def new(recipe, registry_credentials, image_name):
         """Create an `IOCIPushRule`."""
 
+    def findByRecipe(self, recipe):
+        """Find matching `IOCIPushRule`s by recipe."""
+
     def getByID(id):
         """Get a single `IOCIPushRule` by its ID."""
diff --git a/lib/lp/oci/model/ocipushrule.py b/lib/lp/oci/model/ocipushrule.py
index dbdb22e..a01afc6 100644
--- a/lib/lp/oci/model/ocipushrule.py
+++ b/lib/lp/oci/model/ocipushrule.py
@@ -69,7 +69,7 @@ class OCIPushRule(Storm):
 
     def destroySelf(self):
         """See `IOCIPushRule`."""
-        IStore(OCIPushRule).get(self.id).remove()
+        IStore(OCIPushRule).remove(self)
 
 
 @implementer(IOCIPushRuleSet)
@@ -90,3 +90,9 @@ class OCIPushRuleSet:
     def getByID(self, id):
         """See `IOCIPushRuleSet`."""
         return IStore(OCIPushRule).get(OCIPushRule, id)
+
+    def findByRecipe(self, recipe):
+        store = IStore(OCIPushRule)
+        return store.find(
+            OCIPushRule,
+            OCIPushRule.recipe == recipe)
diff --git a/lib/lp/oci/templates/ocirecipe-index.pt b/lib/lp/oci/templates/ocirecipe-index.pt
index f7df628..cf7c549 100644
--- a/lib/lp/oci/templates/ocirecipe-index.pt
+++ b/lib/lp/oci/templates/ocirecipe-index.pt
@@ -116,6 +116,33 @@
          tal:condition="link/enabled">
       <tal:request-builds replace="structure link/fmt:link"/>
     </div>
+
+
+    <h2>Recipe push rules</h2>
+    <table id="push-rules-listing" tal:condition="view/has_push_rules" class="listing"
+           style="margin-bottom: 1em; ">
+      <thead>
+        <tr>
+          <th>Registry URL</th>
+          <th>Username</th>
+          <th>Image Name</th>
+        </tr>
+      </thead>
+      <tbody>
+        <tal:recipe-push-rules repeat="item view/push_rules">
+          <tr tal:define="rule item"
+              tal:attributes="id string:rule-${rule/id}">
+            <td tal:content="rule/registry_credentials/url"/>
+            <td tal:content="rule/registry_credentials/username"/>
+            <td tal:content="rule/image_name"/>
+          </tr>
+        </tal:recipe-push-rules>
+      </tbody>
+    </table>
+    <p tal:condition="not: view/has_push_rules">
+      This OCI recipe has no push rules defined yet.
+    </p>
+
   </div>
 
 </body>