From d830c5a4c1dc7f39a1a52fdcf42ae69cb5dde792 Mon Sep 17 00:00:00 2001 From: Luca Falavigna Date: Thu, 19 Feb 2009 23:59:12 +0100 Subject: [PATCH] Add per-package upload permission checks. --- debian/changelog | 8 +++++++- requestsync | 10 +++++++++- ubuntutools/lp/functions.py | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 46e8e3d..43f39d6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,7 +6,13 @@ ubuntu-dev-tools (0.65) UNRELEASED; urgency=low [ Jonathan Davies ] * requestsync: Only check existing reports if the --lp flag is used. - -- Jonathan Davies Mon, 16 Feb 2009 15:06:16 +0000 + [ Luca Falavigna ] + * Add per-package upload permission checks: + - ubuntutools/lp/functions.py: implement isPerPackageUploader. + - requestsync: check if submitter has per-package upload permission + using isPerPackageUploader function and adjust report accordingly. + + -- Luca Falavigna Thu, 19 Feb 2009 23:55:04 +0100 ubuntu-dev-tools (0.64) jaunty; urgency=low diff --git a/requestsync b/requestsync index 7a6a972..914ca45 100755 --- a/requestsync +++ b/requestsync @@ -78,6 +78,11 @@ def checkNeedsSponsorship(component): teamMember = lp_functions.isLPTeamMember(team) if not teamMember: + + # Check if they have a per-package upload permission. + if lp_functions.isPerPackageUploader(args[0]): + return "perpackageupload" + print "You are not a member (direct or indirect) of the '%s' " \ "team on Launchpad." % team print "Your sync request shall require an approval by a member of " \ @@ -526,7 +531,7 @@ if __name__ == '__main__': # Generate bug report. subscribe = 'ubuntu-archive' status = 'confirmed' - if sponsorship: + if sponsorship == True: status = 'new' if component in ['main', 'restricted']: subscribe = 'ubuntu-main-sponsors' @@ -550,6 +555,9 @@ if __name__ == '__main__': report += 'Explanation of the Ubuntu delta and why it can be dropped:\n' + \ '>>> ENTER_EXPLANATION_HERE <<<\n\n' + if sponsorship == 'perpackageupload': + report += 'Note that I have per-package upload permissions for %s.\n\n' % srcpkg + uidx = base_ver.find('build') if uidx > 0: base_ver = base_ver[:uidx] diff --git a/ubuntutools/lp/functions.py b/ubuntutools/lp/functions.py index 2f01f5f..f9a46af 100644 --- a/ubuntutools/lp/functions.py +++ b/ubuntutools/lp/functions.py @@ -22,6 +22,9 @@ import cookie import urlopener as lp_urlopener import urllib2 import sys +import libsupport as lp_libsupport +import launchpadlib +from re import findall def isLPTeamMember(team): """ Checks if the user is a member of a certain team on Launchpad. @@ -53,3 +56,18 @@ def isLPTeamMember(team): return False return True + +def isPerPackageUploader(package): + # Checks if the user has upload privileges for a certain package. + + launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools") + me = findall('~(\S+)', '%s' % launchpad.me)[0] + main_archive = launchpad.distributions["ubuntu"].main_archive + try: + perms = main_archive.getUploadersForPackage(source_package_name=package) + except launchpadlib.errors.HTTPError: + return False + for perm in perms: + if perm.person.name == me: + return True +