← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/registry-delete-recipes into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/registry-delete-recipes into lp:launchpad.

Commit message:
Allow registry experts to delete recipes.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/registry-delete-recipes/+merge/325806

This isn't too unreasonable a privilege given all the other things registry experts can do, and it will let us deal with at least some support requests more easily until we work out how to fix bug 1347916.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/registry-delete-recipes into lp:launchpad.
=== modified file 'lib/lp/code/configure.zcml'
--- lib/lp/code/configure.zcml	2017-05-23 12:42:38 +0000
+++ lib/lp/code/configure.zcml	2017-06-16 10:15:44 +0000
@@ -1105,6 +1105,10 @@
        set_schema="lp.code.interfaces.sourcepackagerecipe.ISourcePackageRecipeEditableAttributes"
        set_attributes="builder_recipe date_last_modified"
         />
+    <require
+       permission="launchpad.Delete"
+       interface="lp.code.interfaces.sourcepackagerecipe.ISourcePackageRecipeDelete"
+       />
   </class>
   <class
      class="bzrlib.plugins.builder.recipe.BaseRecipeBranch">

=== modified file 'lib/lp/code/interfaces/sourcepackagerecipe.py'
--- lib/lp/code/interfaces/sourcepackagerecipe.py	2016-10-14 16:16:18 +0000
+++ lib/lp/code/interfaces/sourcepackagerecipe.py	2017-06-16 10:15:44 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Interface of the `SourcePackageRecipe` content type."""
@@ -285,6 +285,10 @@
     def updateSeries(distroseries):
         """Replace this recipe's distro series."""
 
+
+class ISourcePackageRecipeDelete(Interface):
+    """ISourcePackageRecipe methods that require launchpad.Delete."""
+
     def destroySelf():
         """Remove this SourcePackageRecipe from the database.
 

=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipe.py'
--- lib/lp/code/model/tests/test_sourcepackagerecipe.py	2016-10-14 16:16:18 +0000
+++ lib/lp/code/model/tests/test_sourcepackagerecipe.py	2017-06-16 10:15:44 +0000
@@ -68,6 +68,7 @@
 from lp.testing import (
     admin_logged_in,
     ANONYMOUS,
+    celebrity_logged_in,
     launchpadlib_for,
     login,
     login_person,
@@ -649,6 +650,22 @@
         self.assertIs(None, build.recipe)
         transaction.commit()
 
+    def test_destroySelf_permissions(self):
+        # Only the owner, registry experts, or admins can delete recipes.
+        owner = self.factory.makePerson()
+        recipe = self.makeSourcePackageRecipe(owner=owner)
+        self.assertRaises(Unauthorized, getattr, recipe, "destroySelf")
+        with person_logged_in(self.factory.makePerson()):
+            self.assertRaises(Unauthorized, getattr, recipe, "destroySelf")
+        with person_logged_in(owner):
+            recipe.destroySelf()
+        recipe = self.makeSourcePackageRecipe(owner=owner)
+        with celebrity_logged_in("registry_experts"):
+            recipe.destroySelf()
+        recipe = self.makeSourcePackageRecipe(owner=owner)
+        with admin_logged_in():
+            recipe.destroySelf()
+
     def test_findStaleDailyBuilds(self):
         # Stale recipe not built daily.
         self.makeSourcePackageRecipe()

=== modified file 'lib/lp/security.py'
--- lib/lp/security.py	2017-04-10 11:17:52 +0000
+++ lib/lp/security.py	2017-06-16 10:15:44 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Security policies for using content objects."""
@@ -2833,6 +2833,17 @@
         return self.obj.getReferencedBranches()
 
 
+class DeleteSourcePackageRecipe(AuthorizationBase):
+
+    permission = "launchpad.Delete"
+    usedfor = ISourcePackageRecipe
+
+    def checkAuthenticated(self, user):
+        return (
+            user.isOwner(self.obj) or
+            user.in_registry_experts or user.in_admin)
+
+
 class ViewSourcePackageRecipeBuild(DelegatedAuthorization):
 
     permission = "launchpad.View"


Follow ups