← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/archive-getallpermissions into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/archive-getallpermissions into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1030936 in Launchpad itself: "The API should expose a Archive.getAllPermissions method"
  https://bugs.launchpad.net/launchpad/+bug/1030936

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/archive-getallpermissions/+merge/117606

== Summary ==

Bug 1030936: The Ubuntu Developer Membership Board would like to be able to correlate the list of permissions granted on the Ubuntu archive against the membership of the ~ubuntu-dev team.  Unfortunately, due to the variety of possible permission types and targets, it's prohibitively expensive to get such a list using the current API.

== Proposed fix ==

Add an exported Archive.getAllPermissions method, amounting to ArchivePermission.selectBy(archive=archive).

== LOC Rationale ==

+50.  I have 3911 lines of credit; this should come out in the wash.

== Tests ==

bin/test -vvct lib/lp/soyuz/stories/webservice/xx-archive.txt

== Demo and Q/A ==

Look through the contents of lp.distributions["ubuntu"].main_archive.getAllPermissions() on qastaging.

== Lint ==

One pre-existing false positive and some pre-existing doctest cruft which I don't think is worth attempting to fix here:

./lib/lp/soyuz/model/archive.py
     346: redefinition of function 'private' from line 342
./lib/lp/soyuz/stories/webservice/xx-archive.txt
      43: want exceeds 78 characters.
      47: want exceeds 78 characters.
     173: want exceeds 78 characters.
     190: want exceeds 78 characters.
     207: want exceeds 78 characters.
     224: want exceeds 78 characters.
     397: want exceeds 78 characters.
     458: want exceeds 78 characters.
     589: want exceeds 78 characters.
     648: want exceeds 78 characters.
-- 
https://code.launchpad.net/~cjwatson/launchpad/archive-getallpermissions/+merge/117606
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/archive-getallpermissions into lp:launchpad.
=== modified file 'lib/lp/_schema_circular_imports.py'
--- lib/lp/_schema_circular_imports.py	2012-07-25 04:35:35 +0000
+++ lib/lp/_schema_circular_imports.py	2012-08-01 10:25:22 +0000
@@ -393,6 +393,7 @@
 patch_collection_property(IArchive, 'dependencies', IArchiveDependency)
 patch_collection_property(
     IArchive, 'enabled_restricted_families', IProcessorFamily)
+patch_collection_return_type(IArchive, 'getAllPermissions', IArchivePermission)
 patch_collection_return_type(
     IArchive, 'getPermissionsForPerson', IArchivePermission)
 patch_collection_return_type(

=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py	2012-07-30 16:48:37 +0000
+++ lib/lp/soyuz/interfaces/archive.py	2012-08-01 10:25:22 +0000
@@ -1155,6 +1155,16 @@
             could not be found.
         """
 
+    # Really IArchivePermission, set below to avoid circular import.
+    @operation_returns_collection_of(Interface)
+    @export_read_operation()
+    @operation_for_version("devel")
+    def getAllPermissions():
+        """Return all `IArchivePermission` records for this archive.
+
+        :return: A list of `IArchivePermission` records.
+        """
+
     @operation_parameters(person=Reference(schema=IPerson))
     # Really IArchivePermission, set below to avoid circular import.
     @operation_returns_collection_of(Interface)

=== modified file 'lib/lp/soyuz/interfaces/archivepermission.py'
--- lib/lp/soyuz/interfaces/archivepermission.py	2012-06-07 10:28:07 +0000
+++ lib/lp/soyuz/interfaces/archivepermission.py	2012-08-01 10:25:22 +0000
@@ -160,6 +160,12 @@
         authenticated in that context.
         """
 
+    def allPermissions(archive):
+        """All `ArchivePermission` records for the archive.
+
+        :param archive: An `IArchive`.
+        """
+
     def permissionsForPerson(person, archive):
         """All `ArchivePermission` records for the person.
 

=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2012-07-30 16:48:37 +0000
+++ lib/lp/soyuz/model/archive.py	2012-08-01 10:25:22 +0000
@@ -1057,6 +1057,11 @@
         permission_set = getUtility(IArchivePermissionSet)
         return permission_set.checkAuthenticated(user, self, perm_type, item)
 
+    def getAllPermissions(self):
+        """See `IArchive`."""
+        permission_set = getUtility(IArchivePermissionSet)
+        return permission_set.allPermissions(self)
+
     def getPermissionsForPerson(self, person):
         """See `IArchive`."""
         permission_set = getUtility(IArchivePermissionSet)

=== modified file 'lib/lp/soyuz/model/archivepermission.py'
--- lib/lp/soyuz/model/archivepermission.py	2012-06-07 10:28:07 +0000
+++ lib/lp/soyuz/model/archivepermission.py	2012-08-01 10:25:22 +0000
@@ -212,6 +212,10 @@
                 ISourcePackageNameSet)[sourcepackagename]
         return sourcepackagename
 
+    def allPermissions(self, archive):
+        """See `IArchivePermissionSet`."""
+        return ArchivePermission.selectBy(archive=archive)
+
     def permissionsForPerson(self, archive, person):
         """See `IArchivePermissionSet`."""
         store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)

=== modified file 'lib/lp/soyuz/stories/webservice/xx-archive.txt'
--- lib/lp/soyuz/stories/webservice/xx-archive.txt	2012-06-14 03:22:43 +0000
+++ lib/lp/soyuz/stories/webservice/xx-archive.txt	2012-08-01 10:25:22 +0000
@@ -229,14 +229,7 @@
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Permission collections can be retrieved with custom operations on the
-archive.
-
-`getPermissionsForPerson` returns all the permissions that a user has.
-
-    >>> ubuntu_team = user_webservice.get("/~ubuntu-team").jsonBody()
-    >>> permissions = user_webservice.named_get(
-    ...     ubuntutest['main_archive_link'], 'getPermissionsForPerson',
-    ...     person=ubuntu_team['self_link']).jsonBody()
+archive.  First, define some general helper functions.
 
     >>> def permission_entry_sort_key(entry):
     ...      return (entry['permission'],
@@ -254,6 +247,40 @@
     ...         print entry['source_package_name']
     ...         print entry['pocket']
 
+`getAllPermissions` returns all permissions on the archive.
+
+    >>> ubuntu_devel = user_webservice.get(
+    ...     '/distros', api_version='devel').jsonBody()['entries'][0]
+
+    >>> def show_all_permissions(archive):
+    ...     permissions = user_webservice.get(
+    ...         '%s?ws.op=getAllPermissions&ws.size=50' % archive,
+    ...         api_version='devel').jsonBody()
+    ...     show_permission_entries(permissions)
+
+    >>> show_all_permissions(ubuntu_devel['main_archive_link'])
+    Archive Upload Rights ...~carlos None mozilla-firefox None
+    Archive Upload Rights ...~ubuntu-team main None None
+    Archive Upload Rights ...~ubuntu-team restricted None None
+    Archive Upload Rights ...~ubuntu-team universe None None
+    Queue Administration Rights ...~name12 main None None
+    Queue Administration Rights ...~name12 multiverse None None
+    Queue Administration Rights ...~name12 restricted None None
+    Queue Administration Rights ...~name12 universe None None
+    Queue Administration Rights ...~no-team-memberships multiverse None None
+    Queue Administration Rights ...~no-team-memberships universe None None
+    Queue Administration Rights ...~ubuntu-team main None None
+    Queue Administration Rights ...~ubuntu-team partner None None
+    Queue Administration Rights ...~ubuntu-team restricted None None
+    Queue Administration Rights ...~ubuntu-team universe None None
+
+`getPermissionsForPerson` returns all the permissions that a user has.
+
+    >>> ubuntu_team = user_webservice.get("/~ubuntu-team").jsonBody()
+    >>> permissions = user_webservice.named_get(
+    ...     ubuntutest['main_archive_link'], 'getPermissionsForPerson',
+    ...     person=ubuntu_team['self_link']).jsonBody()
+
     >>> show_permission_entries(permissions)
     Archive Upload Rights ...~ubuntu-team main None None
     Archive Upload Rights ...~ubuntu-team universe None None
@@ -588,9 +615,6 @@
 getUploadersForPocket returns all the permissions where someone can upload
 to a particular pocket:
 
-    >>> ubuntu_devel = webservice.get(
-    ...     '/distros', api_version='devel').jsonBody()['entries'][0]
-
     >>> def show_pocket_permissions(pocket):
     ...     permissions = user_webservice.named_get(
     ...         ubuntu_devel['main_archive_link'], 'getUploadersForPocket',


Follow ups