Merge into devel : cmsg-2-425800 : Code : Launchpad itself

Merge lp://staging/~al-maisan/launchpad/cmsg-2-425800 into lp://staging/launchpad

Proposed by Muharem Hrnjadovic
Status: Merged
Merged at revision: not available
Proposed branch: lp://staging/~al-maisan/launchpad/cmsg-2-425800
Merge into: lp://staging/launchpad
Diff against target: 117 lines
2 files modified
To merge this branch: bzr merge lp://staging/~al-maisan/launchpad/cmsg-2-425800
Reviewer Review Type Date Requested Status
Abel Deuring (community) Approve
Review via email: mp+12791@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote :

Refactored the code to distinguish the following situations:

      - the uploader has no upload permissions for the archive in question.
        whatsoever
      - the uploader does have *some* upload permissions for the archive at hand
        but these are insufficient when it comes to the source package that is
        to be uploaded.

Remarks/shouting by bigjools in lieu of a pre-implementation call :-)

Tests to run:

    bin/test -t upload -t permission

Revision history for this message
Abel Deuring (adeuring) :
review: Approve

Preview Diff

Failed to fetch available diffs.

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/permission.py'
2--- lib/lp/archiveuploader/permission.py 2009-08-31 02:47:36 +0000
3+++ lib/lp/archiveuploader/permission.py 2009-10-02 15:20:28 +0000
4@@ -44,6 +44,13 @@
5 "a PPA?")
6
7
8+class InsufficientUploadRights(CannotUploadToArchive):
9+ """Raised when a person has insufficient upload rights."""
10+ _fmt = (
11+ "The signer of this package is lacking the upload rights for "
12+ "the source package, component or package set in question.")
13+
14+
15 class NoRightsForComponent(CannotUploadToArchive):
16 """Raised when a person tries to upload to a component without permission.
17 """
18@@ -67,6 +74,18 @@
19 return set(permission.component for permission in permissions)
20
21
22+def packagesets_valid_for(archive, person):
23+ """Return the package sets that 'person' can upload to 'archive'.
24+
25+ :param archive: The `IArchive` than 'person' wishes to upload to.
26+ :param person: An `IPerson` wishing to upload to an archive.
27+ :return: A `set` of `IPackageset`s that 'person' can upload to.
28+ """
29+ permission_set = getUtility(IArchivePermissionSet)
30+ permissions = permission_set.packagesetsForUploader(archive, person)
31+ return set(permission.packageset for permission in permissions)
32+
33+
34 def verify_upload(person, sourcepackagename, archive, component,
35 strict_component=True):
36 """Can 'person' upload 'sourcepackagename' to 'archive'?
37@@ -98,7 +117,10 @@
38 return None
39
40 if not components_valid_for(archive, person):
41- return NoRightsForArchive()
42+ if not packagesets_valid_for(archive, person):
43+ return NoRightsForArchive()
44+ else:
45+ return InsufficientUploadRights()
46
47 if (component is not None
48 and strict_component
49
50=== modified file 'lib/lp/archiveuploader/tests/nascentupload-packageset.txt'
51--- lib/lp/archiveuploader/tests/nascentupload-packageset.txt 2009-08-13 15:12:16 +0000
52+++ lib/lp/archiveuploader/tests/nascentupload-packageset.txt 2009-10-02 15:20:28 +0000
53@@ -78,8 +78,9 @@
54 ... ap_set.packagesetsForSourceUploader(
55 ... ubuntu_archive, 'bar', name16))
56
57-Now put in place a package set, add 'bar' to it and define a permission
58-for the former.
59+
60+Let's first add an empty package set, grant 'name16' an archive permission
61+to it and see whether that changes things.
62
63 >>> commit()
64 >>> LaunchpadZopelessLayer.switchDbUser('launchpad')
65@@ -90,7 +91,44 @@
66 ... for datum in sort_by_id(iterable):
67 ... print('%3d -> %s' % (datum.id, datum.name))
68
69+Here goes the empty package set.
70+
71 >>> ps_set = getUtility(IPackagesetSet)
72+ >>> empty_ps = ps_set.new(
73+ ... u'empty-pkg-set', u'Empty package set.', name16)
74+ >>> commit()
75+
76+And here's name16's upload permission for it.
77+
78+ >>> ignore_this = ap_set.newPackagesetUploader(
79+ ... ubuntu_archive, name16, empty_ps)
80+
81+There are still no package sets that include 'bar'.
82+
83+ >>> print_permission(
84+ ... ap_set.packagesetsForSourceUploader(
85+ ... ubuntu_archive, 'bar', name16))
86+
87+Let's retry the upload.
88+
89+ >>> bar_failed = NascentUpload(
90+ ... datadir('suite/bar_1.0-1/bar_1.0-1_source.changes'),
91+ ... insecure_policy, mock_logger_quiet)
92+
93+ >>> bar_failed.process()
94+ >>> bar_failed.is_rejected
95+ True
96+ >>> print bar_failed.rejection_message
97+ The signer of this package is lacking the upload rights for the source
98+ package, component or package set in question.
99+
100+The error message above makes it clear that the uploader does have *some*
101+permissions defined but these are not sufficient for the source package at
102+hand.
103+
104+Next put in place a package set, add 'bar' to it and define a permission
105+for the former.
106+
107 >>> foo_ps = ps_set.new(
108 ... u'foo-pkg-set', u'Packages that require special care.', name16)
109 >>> commit()
110@@ -103,7 +141,7 @@
111 >>> print_data(
112 ... ps_set.setsIncludingSource('bar',
113 ... direct_inclusion=True))
114- 1 -> foo-pkg-set
115+ 2 -> foo-pkg-set
116
117 name16 has no package set based upload privileges for 'bar' yet.
118