← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:stormify-archivepermission into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:stormify-archivepermission into launchpad:master.

Commit message:
Convert ArchivePermission to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/389403
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-archivepermission into launchpad:master.
diff --git a/lib/lp/archiveuploader/tests/nascentupload-packageset.txt b/lib/lp/archiveuploader/tests/nascentupload-packageset.txt
index 7bd610f..a3b7b62 100644
--- a/lib/lp/archiveuploader/tests/nascentupload-packageset.txt
+++ b/lib/lp/archiveuploader/tests/nascentupload-packageset.txt
@@ -20,11 +20,13 @@ Let's modify the current ACL rules for ubuntu, moving the upload
 rights to all components from 'ubuntu-team' to 'mark':
 
     >>> switch_dbuser('launchpad')
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.soyuz.model.archivepermission import ArchivePermission
     >>> new_uploader = getUtility(IPersonSet).getByName('mark')
-    >>> for permission in ArchivePermission.select():
+    >>> store = IStore(ArchivePermission)
+    >>> for permission in store.find(ArchivePermission):
     ...     permission.person = new_uploader
-    ...     permission.syncUpdate()
+    >>> store.flush()
     >>> switch_dbuser('uploader')
 
 This time the upload will fail because the ACLs don't let
diff --git a/lib/lp/archiveuploader/tests/nascentupload.txt b/lib/lp/archiveuploader/tests/nascentupload.txt
index 9915e86..bbe4697 100644
--- a/lib/lp/archiveuploader/tests/nascentupload.txt
+++ b/lib/lp/archiveuploader/tests/nascentupload.txt
@@ -772,12 +772,14 @@ Both, DSC and changesfile are signed with Name16's second key.
 Let's modify the current ACL rules for ubuntu, moving the upload
 rights to all components from 'ubuntu-team' to 'mark':
 
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.soyuz.model.archivepermission import ArchivePermission
     >>> with lp_dbuser():
     ...     new_uploader = getUtility(IPersonSet).getByName('mark')
-    ...     for permission in ArchivePermission.select():
+    ...     store = IStore(ArchivePermission)
+    ...     for permission in store.find(ArchivePermission):
     ...         permission.person = new_uploader
-    ...         permission.syncUpdate()
+    ...     store.flush()
 
 This time the upload will fail because the ACLs don't let
 "name16", the key owner, upload a package.
diff --git a/lib/lp/security.py b/lib/lp/security.py
index c36a99b..599b717 100644
--- a/lib/lp/security.py
+++ b/lib/lp/security.py
@@ -1384,8 +1384,9 @@ class AdminDistroSeriesDifference(AuthorizationBase):
         # see if the user has that permission on any components
         # at all.
         archive = self.obj.derived_series.main_archive
-        return bool(
-            archive.getComponentsForQueueAdmin(user.person)) or user.in_admin
+        return (
+            not archive.getComponentsForQueueAdmin(user.person).is_empty() or
+            user.in_admin)
 
 
 class EditDistroSeriesDifference(DelegatedAuthorization):
diff --git a/lib/lp/soyuz/browser/tests/archive-views.txt b/lib/lp/soyuz/browser/tests/archive-views.txt
index 72c1392..8a800f6 100644
--- a/lib/lp/soyuz/browser/tests/archive-views.txt
+++ b/lib/lp/soyuz/browser/tests/archive-views.txt
@@ -1138,7 +1138,7 @@ When 'No Privileges Person' gets upload right to Celso's PPA ...
     >>> login('foo.bar@xxxxxxxxxxxxx')
     >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
     >>> cprov.archive.newComponentUploader(no_priv, "main")
-    <ArchivePermission ...>
+    <lp.soyuz.model.archivepermission.ArchivePermission ...>
 
 They become able to copy to the context PPA.
 
diff --git a/lib/lp/soyuz/doc/archive.txt b/lib/lp/soyuz/doc/archive.txt
index e9c2424..ad7f3d7 100644
--- a/lib/lp/soyuz/doc/archive.txt
+++ b/lib/lp/soyuz/doc/archive.txt
@@ -1168,7 +1168,7 @@ it gets listed by `getPPAsForUser`.
     PPA for No Privileges Person
 
     >>> cprov_archive.newComponentUploader(no_priv, "main")
-    <ArchivePermission ...>
+    <lp.soyuz.model.archivepermission.ArchivePermission ...>
 
     >>> for ppa in archive_set.getPPAsForUser(no_priv):
     ...     print(ppa.displayname)
@@ -1181,7 +1181,7 @@ and user and give the team access to cprov's PPA:
     >>> uploader_team = factory.makeTeam(owner=cprov, name='uploader-team')
     >>> indirect_uploader = factory.makePerson(name='indirect-uploader')
     >>> cprov_archive.newComponentUploader(uploader_team, "main")
-    <ArchivePermission ...>
+    <lp.soyuz.model.archivepermission.ArchivePermission ...>
 
 'indirect_uploader' currently can't upload to cprov's PPA:
 
diff --git a/lib/lp/soyuz/doc/archivepermission.txt b/lib/lp/soyuz/doc/archivepermission.txt
index ff14a7f..2f8a34f 100644
--- a/lib/lp/soyuz/doc/archivepermission.txt
+++ b/lib/lp/soyuz/doc/archivepermission.txt
@@ -8,6 +8,7 @@ an easy way of accessing the data through convenient helpers.
 Two main operations are supported: upload and queue administration.
 
     >>> from lp.testing import verifyObject
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.soyuz.enums import ArchivePermissionType
     >>> from lp.soyuz.interfaces.archivepermission import (
     ...     IArchivePermission, IArchivePermissionSet)
@@ -18,7 +19,7 @@ Two main operations are supported: upload and queue administration.
 The ArchivePermission context class implements the IArchivePermission
 interface.
 
-    >>> random_permission = ArchivePermission.get(1)
+    >>> random_permission = IStore(ArchivePermission).get(ArchivePermission, 1)
     >>> verifyObject(IArchivePermission, random_permission)
     True
 
diff --git a/lib/lp/soyuz/interfaces/archive.py b/lib/lp/soyuz/interfaces/archive.py
index e3f8462..407f953 100644
--- a/lib/lp/soyuz/interfaces/archive.py
+++ b/lib/lp/soyuz/interfaces/archive.py
@@ -821,7 +821,7 @@ class IArchiveView(IHasBuildRecords):
         :param person: An `IPerson`
         :param item: An `IComponent`, `ISourcePackageName`
         :param perm_type: An ArchivePermissionType enum,
-        :return: A list of `IArchivePermission` records.
+        :return: An `IResultSet` of `IArchivePermission` records.
         """
 
     def canUploadSuiteSourcePackage(person, suitesourcepackage):
diff --git a/lib/lp/soyuz/interfaces/archivepermission.py b/lib/lp/soyuz/interfaces/archivepermission.py
index 390343b..b1bd302 100644
--- a/lib/lp/soyuz/interfaces/archivepermission.py
+++ b/lib/lp/soyuz/interfaces/archivepermission.py
@@ -61,7 +61,6 @@ class IArchivePermission(Interface):
             title=_("The permission type being granted."),
             values=ArchivePermissionType, readonly=False, required=True))
 
-    personID = Attribute("DB ID for person.")
     person = exported(
         PublicPersonChoice(
             title=_("Person"),
diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py
index cb3f089..f5f711b 100644
--- a/lib/lp/soyuz/model/archive.py
+++ b/lib/lp/soyuz/model/archive.py
@@ -1233,8 +1233,8 @@ class Archive(SQLBase):
         any_perm_on_archive = Store.of(self).find(
             TeamParticipation,
             ArchivePermission.archive == self.id,
-            TeamParticipation.person == person.id,
-            TeamParticipation.teamID == ArchivePermission.personID,
+            TeamParticipation.person == person,
+            TeamParticipation.team == ArchivePermission.person_id,
             )
         return not any_perm_on_archive.is_empty()
 
@@ -1482,7 +1482,7 @@ class Archive(SQLBase):
             if source_allowed or set_allowed:
                 return None
 
-        if not self.getComponentsForUploader(person):
+        if self.getComponentsForUploader(person).is_empty():
             if self.getPackagesetsForUploader(person).is_empty():
                 return NoRightsForArchive()
             else:
@@ -1522,7 +1522,7 @@ class Archive(SQLBase):
         """Private helper method to check permissions."""
         permissions = self.getPermissions(
             user, item, permission, distroseries=distroseries)
-        return bool(permissions)
+        return not permissions.is_empty()
 
     def newPackageUploader(self, person, source_package_name):
         """See `IArchive`."""
@@ -2792,9 +2792,9 @@ class ArchiveSet:
             Archive.id,
             where=And(
                 Archive.purpose == ArchivePurpose.PPA,
-                ArchivePermission.archiveID == Archive.id,
+                ArchivePermission.archive == Archive.id,
                 TeamParticipation.person == user,
-                TeamParticipation.team == ArchivePermission.personID,
+                TeamParticipation.team == ArchivePermission.person_id,
                 ))
         return Archive.id.is_in(
             Union(direct_membership, third_party_upload_acl))
@@ -3050,10 +3050,10 @@ def get_enabled_archive_filter(user, purpose=None,
     from lp.soyuz.model.archivesubscriber import ArchiveSubscriber
 
     is_allowed = Select(
-        ArchivePermission.archiveID, where=And(
+        ArchivePermission.archive_id, where=And(
             ArchivePermission.permission == ArchivePermissionType.UPLOAD,
             ArchivePermission.component == main,
-            ArchivePermission.personID.is_in(user_teams)),
+            ArchivePermission.person_id.is_in(user_teams)),
         tables=ArchivePermission, distinct=True)
 
     is_subscribed = Select(
diff --git a/lib/lp/soyuz/model/archivepermission.py b/lib/lp/soyuz/model/archivepermission.py
index 3bf74a2..d18a587 100644
--- a/lib/lp/soyuz/model/archivepermission.py
+++ b/lib/lp/soyuz/model/archivepermission.py
@@ -13,16 +13,19 @@ __all__ = [
 from operator import attrgetter
 
 from lazr.enum import DBItem
-from sqlobject import (
-    BoolCol,
-    ForeignKey,
-    )
-from storm.expr import SQL
+import pytz
+from storm.expr import Exists
 from storm.locals import (
+    And,
+    Bool,
+    DateTime,
     Int,
+    Or,
     Reference,
+    Select,
+    SQL,
+    Store,
     )
-from storm.store import Store
 from zope.component import getUtility
 from zope.interface import (
     alsoProvides,
@@ -37,17 +40,15 @@ from lp.registry.interfaces.sourcepackagename import (
     ISourcePackageName,
     ISourcePackageNameSet,
     )
+from lp.registry.model.teammembership import TeamParticipation
 from lp.services.database.constants import UTC_NOW
-from lp.services.database.datetimecol import UtcDateTimeCol
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import (
     IMasterStore,
     IStore,
     )
-from lp.services.database.sqlbase import (
-    SQLBase,
-    sqlvalues,
-    )
+from lp.services.database.sqlbase import sqlvalues
+from lp.services.database.stormbase import StormBase
 from lp.soyuz.enums import ArchivePermissionType
 from lp.soyuz.interfaces.archive import (
     ComponentNotFound,
@@ -67,43 +68,58 @@ from lp.soyuz.interfaces.packageset import IPackageset
 
 
 @implementer(IArchivePermission)
-class ArchivePermission(SQLBase):
+class ArchivePermission(StormBase):
     """See `IArchivePermission`."""
-    _table = 'ArchivePermission'
-    _defaultOrder = 'id'
+    __storm_table__ = 'ArchivePermission'
+    __storm_order__ = 'id'
 
-    date_created = UtcDateTimeCol(
-        dbName='date_created', notNull=True, default=UTC_NOW)
+    id = Int(primary=True)
 
-    archive = ForeignKey(foreignKey='Archive', dbName='archive', notNull=True)
+    date_created = DateTime(
+        tzinfo=pytz.UTC, name='date_created', allow_none=False,
+        default=UTC_NOW)
 
-    permission = EnumCol(
-        dbName='permission', unique=False, notNull=True,
-        schema=ArchivePermissionType)
+    archive_id = Int(name='archive', allow_none=False)
+    archive = Reference(archive_id, 'Archive.id')
 
-    person = ForeignKey(foreignKey='Person', dbName='person', notNull=True)
+    permission = DBEnum(
+        name='permission', allow_none=False, enum=ArchivePermissionType)
 
-    component = ForeignKey(
-        foreignKey='Component', dbName='component', notNull=False)
+    person_id = Int(name='person', allow_none=False)
+    person = Reference(person_id, 'Person.id')
 
-    sourcepackagename = ForeignKey(
-        foreignKey='SourcePackageName', dbName='sourcepackagename',
-        notNull=False)
+    component_id = Int(name='component', allow_none=True)
+    component = Reference(component_id, 'Component.id')
+
+    sourcepackagename_id = Int(name='sourcepackagename', allow_none=True)
+    sourcepackagename = Reference(sourcepackagename_id, 'SourcePackageName.id')
 
     packageset_id = Int(name='packageset', allow_none=True)
     packageset = Reference(packageset_id, 'Packageset.id')
 
-    explicit = BoolCol(dbName='explicit', notNull=True, default=False)
-
-    pocket = EnumCol(dbName="pocket", schema=PackagePublishingPocket)
-
-    distroseries = ForeignKey(
-        foreignKey='DistroSeries', dbName='distroseries', notNull=False)
-
-    def _init(self, *args, **kw):
-        """Provide the right interface for URL traversal."""
-        SQLBase._init(self, *args, **kw)
-
+    explicit = Bool(name='explicit', allow_none=False, default=False)
+
+    pocket = DBEnum(name='pocket', enum=PackagePublishingPocket)
+
+    distroseries_id = Int(name='distroseries', allow_none=True)
+    distroseries = Reference(distroseries_id, 'DistroSeries.id')
+
+    def __init__(self, archive, permission, person, component=None,
+                 sourcepackagename=None, packageset=None, explicit=False,
+                 distroseries=None, pocket=None):
+        super(ArchivePermission, self).__init__()
+        self.archive = archive
+        self.permission = permission
+        self.person = person
+        self.component = component
+        self.sourcepackagename = sourcepackagename
+        self.packageset = packageset
+        self.explicit = explicit
+        self.distroseries = distroseries
+        self.pocket = pocket
+        self.__storm_loaded__()
+
+    def __storm_loaded__(self):
         # Provide the additional marker interface depending on what type
         # of archive this is.  See also the browser:url declarations in
         # zcml/archivepermission.zcml.
@@ -157,47 +173,32 @@ class ArchivePermissionSet:
     def checkAuthenticated(self, person, archive, permission, item,
                            distroseries=None):
         """See `IArchivePermissionSet`."""
-        clauses = ["""
-            ArchivePermission.archive = %s AND
-            ArchivePermission.permission = %s AND
-            ArchivePermission.person = TeamParticipation.team AND
-            TeamParticipation.person = %s
-            """ % sqlvalues(archive, permission, person)]
-
-        prejoins = []
+        clauses = [
+            ArchivePermission.archive == archive,
+            ArchivePermission.permission == permission,
+            ArchivePermission.person == TeamParticipation.teamID,
+            TeamParticipation.person == person,
+            ]
 
         if IComponent.providedBy(item):
-            clauses.append(
-                "ArchivePermission.component = %s" % sqlvalues(item))
-            prejoins.append("component")
+            clauses.append(ArchivePermission.component == item)
         elif ISourcePackageName.providedBy(item):
-            clauses.append(
-                "ArchivePermission.sourcepackagename = %s" % sqlvalues(item))
-            prejoins.append("sourcepackagename")
+            clauses.append(ArchivePermission.sourcepackagename == item)
         elif IPackageset.providedBy(item):
-            clauses.append(
-                "ArchivePermission.packageset = %s" % sqlvalues(item.id))
-            prejoins.append("packageset")
+            clauses.append(ArchivePermission.packageset == item)
         elif (zope_isinstance(item, DBItem) and
               item.enum.name == "PackagePublishingPocket"):
-            clauses.append("ArchivePermission.pocket = %s" % sqlvalues(item))
+            clauses.append(ArchivePermission.pocket == item)
             if distroseries is not None:
-                clauses.append(
-                    "(ArchivePermission.distroseries IS NULL OR "
-                     "ArchivePermission.distroseries = %s)" %
-                    sqlvalues(distroseries))
-                prejoins.append("distroseries")
+                clauses.append(Or(
+                    ArchivePermission.distroseries == None,
+                    ArchivePermission.distroseries == distroseries))
         else:
             raise AssertionError(
                 "'item' %r is not an IComponent, IPackageset, "
                 "ISourcePackageName or PackagePublishingPocket" % item)
 
-        query = " AND ".join(clauses)
-        auth = ArchivePermission.select(
-            query, clauseTables=["TeamParticipation"],
-            prejoins=prejoins)
-
-        return auth
+        return IStore(ArchivePermission).find(ArchivePermission, *clauses)
 
     def _nameToComponent(self, component):
         """Helper to convert a possible string component to IComponent"""
@@ -217,24 +218,24 @@ class ArchivePermissionSet:
 
     def _precachePersonsForPermissions(self, permissions):
         list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
-            set(map(attrgetter("personID"), permissions))))
+            set(map(attrgetter("person_id"), permissions))))
         return permissions
 
     def permissionsForArchive(self, archive):
         """See `IArchivePermissionSet`."""
         return self._precachePersonsForPermissions(
-            ArchivePermission.selectBy(archive=archive))
+            IStore(ArchivePermission).find(ArchivePermission, archive=archive))
 
     def permissionsForPerson(self, archive, person):
         """See `IArchivePermissionSet`."""
         return IStore(ArchivePermission).find(
-            ArchivePermission, """
-            ArchivePermission.archive = %s AND
-            EXISTS (SELECT TeamParticipation.person
-                    FROM TeamParticipation
-                    WHERE TeamParticipation.person = %s AND
-                          TeamParticipation.team = ArchivePermission.person)
-            """ % sqlvalues(archive, person))
+            ArchivePermission,
+            ArchivePermission.archive == archive,
+            Exists(Select(
+                1, tables=[TeamParticipation],
+                where=And(
+                    TeamParticipation.person == person,
+                    TeamParticipation.team == ArchivePermission.person_id))))
 
     def _componentsFor(self, archives, person, permission_type):
         """Helper function to get ArchivePermission objects."""
@@ -243,16 +244,16 @@ class ArchivePermissionSet:
         else:
             archive_ids = [archive.id for archive in archives]
 
-        return ArchivePermission.select("""
-            ArchivePermission.archive IN %s AND
-            ArchivePermission.permission = %s AND
-            ArchivePermission.component IS NOT NULL AND
-            EXISTS (SELECT TeamParticipation.person
-                    FROM TeamParticipation
-                    WHERE TeamParticipation.person = %s AND
-                          TeamParticipation.team = ArchivePermission.person)
-            """ % sqlvalues(archive_ids, permission_type, person),
-            prejoins=["component"])
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
+            ArchivePermission.archive_id.is_in(archive_ids),
+            ArchivePermission.permission == permission_type,
+            ArchivePermission.component != None,
+            Exists(Select(
+                1, tables=[TeamParticipation],
+                where=And(
+                    TeamParticipation.person == person,
+                    TeamParticipation.team == ArchivePermission.person_id))))
 
     def componentsForUploader(self, archive, person):
         """See `IArchivePermissionSet`."""
@@ -261,41 +262,39 @@ class ArchivePermissionSet:
 
     def uploadersForComponent(self, archive, component=None):
         """See `IArchivePermissionSet`."""
-        clauses = ["""
-            ArchivePermission.archive = %s AND
-            ArchivePermission.permission = %s
-            """ % sqlvalues(archive, ArchivePermissionType.UPLOAD)]
+        clauses = [
+            ArchivePermission.archive == archive,
+            ArchivePermission.permission == ArchivePermissionType.UPLOAD,
+            ]
 
         if component is not None:
             component = self._nameToComponent(component)
-            clauses.append(
-                "ArchivePermission.component = %s" % sqlvalues(component))
+            clauses.append(ArchivePermission.component == component)
         else:
-            clauses.append("ArchivePermission.component IS NOT NULL")
+            clauses.append(ArchivePermission.component != None)
 
-        query = " AND ".join(clauses)
-        return ArchivePermission.select(query, prejoins=["component"])
+        return IStore(ArchivePermission).find(ArchivePermission, *clauses)
 
     def packagesForUploader(self, archive, person):
         """See `IArchive`."""
-        return ArchivePermission.select("""
-            ArchivePermission.archive = %s AND
-            ArchivePermission.permission = %s AND
-            ArchivePermission.sourcepackagename IS NOT NULL AND
-            EXISTS (SELECT TeamParticipation.person
-                    FROM TeamParticipation
-                    WHERE TeamParticipation.person = %s AND
-                    TeamParticipation.team = ArchivePermission.person)
-            """ % sqlvalues(archive, ArchivePermissionType.UPLOAD, person),
-            prejoins=["sourcepackagename"])
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
+            ArchivePermission.archive == archive,
+            ArchivePermission.permission == ArchivePermissionType.UPLOAD,
+            ArchivePermission.sourcepackagename != None,
+            Exists(Select(
+                1, tables=[TeamParticipation],
+                where=And(
+                    TeamParticipation.person == person,
+                    TeamParticipation.team == ArchivePermission.person_id))))
 
     def uploadersForPackage(self, archive, sourcepackagename):
         """See `IArchivePermissionSet`."""
         sourcepackagename = self._nameToSourcePackageName(sourcepackagename)
-        results = ArchivePermission.selectBy(
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, permission=ArchivePermissionType.UPLOAD,
             sourcepackagename=sourcepackagename)
-        return results.prejoin(["sourcepackagename"])
 
     def _pocketsFor(self, archives, person, permission_type):
         """Helper function to get ArchivePermission objects."""
@@ -304,15 +303,16 @@ class ArchivePermissionSet:
         else:
             archive_ids = [archive.id for archive in archives]
 
-        return ArchivePermission.select("""
-            ArchivePermission.archive IN %s AND
-            ArchivePermission.permission = %s AND
-            ArchivePermission.pocket IS NOT NULL AND
-            EXISTS (SELECT TeamParticipation.person
-                    FROM TeamParticipation
-                    WHERE TeamParticipation.person = %s AND
-                          TeamParticipation.team = ArchivePermission.person)
-            """ % sqlvalues(archive_ids, permission_type, person))
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
+            ArchivePermission.archive_id.is_in(archive_ids),
+            ArchivePermission.permission == permission_type,
+            ArchivePermission.pocket != None,
+            Exists(Select(
+                1, tables=[TeamParticipation],
+                where=And(
+                    TeamParticipation.person == person,
+                    TeamParticipation.team == ArchivePermission.person_id))))
 
     def pocketsForUploader(self, archive, person):
         """See `IArchivePermissionSet`."""
@@ -320,17 +320,18 @@ class ArchivePermissionSet:
 
     def uploadersForPocket(self, archive, pocket):
         """See `IArchivePermissionSet`."""
-        return ArchivePermission.selectBy(
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, permission=ArchivePermissionType.UPLOAD,
             pocket=pocket)
 
     def queueAdminsForComponent(self, archive, component):
         """See `IArchivePermissionSet`."""
         component = self._nameToComponent(component)
-        results = ArchivePermission.selectBy(
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, permission=ArchivePermissionType.QUEUE_ADMIN,
             component=component)
-        return results.prejoin(["component"])
 
     def componentsForQueueAdmin(self, archive, person):
         """See `IArchivePermissionSet`."""
@@ -342,7 +343,8 @@ class ArchivePermissionSet:
         kwargs = {}
         if distroseries is not None:
             kwargs["distroseries"] = distroseries
-        return ArchivePermission.selectBy(
+        return IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, permission=ArchivePermissionType.QUEUE_ADMIN,
             pocket=pocket, **kwargs)
 
@@ -424,32 +426,36 @@ class ArchivePermissionSet:
     def deletePackageUploader(self, archive, person, sourcepackagename):
         """See `IArchivePermissionSet`."""
         sourcepackagename = self._nameToSourcePackageName(sourcepackagename)
-        permission = ArchivePermission.selectOneBy(
+        permission = IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, person=person,
             sourcepackagename=sourcepackagename,
-            permission=ArchivePermissionType.UPLOAD)
+            permission=ArchivePermissionType.UPLOAD).one()
         self._remove_permission(permission)
 
     def deleteComponentUploader(self, archive, person, component):
         """See `IArchivePermissionSet`."""
         component = self._nameToComponent(component)
-        permission = ArchivePermission.selectOneBy(
+        permission = IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, person=person, component=component,
-            permission=ArchivePermissionType.UPLOAD)
+            permission=ArchivePermissionType.UPLOAD).one()
         self._remove_permission(permission)
 
     def deletePocketUploader(self, archive, person, pocket):
-        permission = ArchivePermission.selectOneBy(
+        permission = IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, person=person, pocket=pocket,
-            permission=ArchivePermissionType.UPLOAD)
+            permission=ArchivePermissionType.UPLOAD).one()
         self._remove_permission(permission)
 
     def deleteQueueAdmin(self, archive, person, component):
         """See `IArchivePermissionSet`."""
         component = self._nameToComponent(component)
-        permission = ArchivePermission.selectOneBy(
+        permission = IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, person=person, component=component,
-            permission=ArchivePermissionType.QUEUE_ADMIN)
+            permission=ArchivePermissionType.QUEUE_ADMIN).one()
         self._remove_permission(permission)
 
     def deletePocketQueueAdmin(self, archive, person, pocket,
@@ -458,9 +464,10 @@ class ArchivePermissionSet:
         kwargs = {}
         if distroseries is not None:
             kwargs["distroseries"] = distroseries
-        permission = ArchivePermission.selectOneBy(
+        permission = IStore(ArchivePermission).find(
+            ArchivePermission,
             archive=archive, person=person, pocket=pocket,
-            permission=ArchivePermissionType.QUEUE_ADMIN, **kwargs)
+            permission=ArchivePermissionType.QUEUE_ADMIN, **kwargs).one()
         self._remove_permission(permission)
 
     def packagesetsForUploader(self, archive, person):