mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
ubuntutools/lp/lpapicache.py: use the new LP API function archive.checkUpload() to check upload permissions
This commit is contained in:
parent
3b54c5b956
commit
924f910335
@ -408,11 +408,9 @@ class PersonTeam(BaseWrapper):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
# Don't share _upload_{pkg,comp} between different PersonTeams
|
# Don't share _upload between different PersonTeams
|
||||||
if '_upload_pkg' not in self.__dict__:
|
if '_upload' not in self.__dict__:
|
||||||
self._upload_pkg = dict()
|
self._upload = dict()
|
||||||
if '_upload_comp' not in self.__dict__:
|
|
||||||
self._upload_comp = dict()
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'%s (%s)' % (self.display_name, self.name)
|
return u'%s (%s)' % (self.display_name, self.name)
|
||||||
@ -440,12 +438,11 @@ class PersonTeam(BaseWrapper):
|
|||||||
'''
|
'''
|
||||||
return any(t.name == team for t in self.super_teams)
|
return any(t.name == team for t in self.super_teams)
|
||||||
|
|
||||||
def canUploadPackage(self, archive, distroseries, package, component):
|
def canUploadPackage(self, archive, distroseries, package, component, pocket='Release'):
|
||||||
'''Check if the person or team has upload rights for the source
|
'''Check if the person or team has upload rights for the source
|
||||||
package to the specified 'archive' and 'distrorelease' either
|
package to the specified 'archive' and 'distrorelease'.
|
||||||
through package sets, component or or per-package upload rights.
|
|
||||||
Either a source package name or a component has the specified.
|
|
||||||
|
|
||||||
|
A source package name and a component have to be specified.
|
||||||
'archive' has to be a Archive object.
|
'archive' has to be a Archive object.
|
||||||
'distroseries' has to be an DistroSeries object.
|
'distroseries' has to be an DistroSeries object.
|
||||||
'''
|
'''
|
||||||
@ -459,35 +456,22 @@ class PersonTeam(BaseWrapper):
|
|||||||
raise TypeError('A component name expected.')
|
raise TypeError('A component name expected.')
|
||||||
if package is None and component is None:
|
if package is None and component is None:
|
||||||
raise ValueError('Either a source package name or a component has to be specified.')
|
raise ValueError('Either a source package name or a component has to be specified.')
|
||||||
|
if pocket not in ('Release', 'Security', 'Updates', 'Proposed', 'Backports'):
|
||||||
|
raise PocketDoesNotExistError("Pocket '%s' does not exist." % pocket)
|
||||||
|
|
||||||
upload_comp = self._upload_comp.get((archive, component))
|
canUpload = self._upload.get((archive, distroseries, pocket, package, component))
|
||||||
upload_pkg = self._upload_pkg.get((archive, package))
|
|
||||||
|
|
||||||
if upload_comp is None and upload_pkg is None:
|
if canUpload is None:
|
||||||
# archive.isSourceUploadAllowed() checks only package sets permission
|
canUpload = archive.checkUpload(
|
||||||
if package is not None and archive.isSourceUploadAllowed(
|
component=component,
|
||||||
distroseries=distroseries(), person=self(), sourcepackagename=package):
|
distroseries=distroseries(),
|
||||||
# TODO: also cache the release it applies to
|
person=self(),
|
||||||
self._upload_pkg[(archive, package)] = True
|
pocket=pocket,
|
||||||
return True
|
sourcepackagename=package,
|
||||||
# check for component or per-package upload rights
|
)
|
||||||
for perm in archive.getPermissionsForPerson(person=self()):
|
self._upload[(archive, distroseries, pocket, package, component)] = canUpload
|
||||||
if perm.permission != 'Archive Upload Rights':
|
|
||||||
continue
|
return canUpload
|
||||||
if component and perm.component_name == component:
|
|
||||||
self._upload_comp[(archive, component)] = True
|
|
||||||
return True
|
|
||||||
if package and perm.source_package_name == package:
|
|
||||||
self._upload_pkg[(archive, package)] = True
|
|
||||||
return True
|
|
||||||
# don't have upload rights
|
|
||||||
if package:
|
|
||||||
self._upload_pkg[(archive, package)] = False
|
|
||||||
if component:
|
|
||||||
self._upload_comp[(archive, component)] = False
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return upload_comp or upload_pkg
|
|
||||||
|
|
||||||
|
|
||||||
class Build(BaseWrapper):
|
class Build(BaseWrapper):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user