1001
1003
archive.getComponentsForQueueAdmin(user.person)) or user.in_admin
1004
class EditDistroSeriesDifference(AuthorizationBase):
1006
class EditDistroSeriesDifference(DelegatedAuthorization):
1005
1007
"""Anyone with lp.View on the distribution can edit a DSD."""
1006
1008
permission = 'launchpad.Edit'
1007
1009
usedfor = IDistroSeriesDifferenceEdit
1009
def checkAuthenticated(self, user):
1010
return self.forwardCheckAuthenticated(
1011
user, self.obj.derived_series.distribution, 'launchpad.View')
1011
def __init__(self, obj):
1012
super(EditDistroSeriesDifference, self).__init__(
1013
obj, obj.derived_series.distribution, 'launchpad.View')
1015
def checkUnauthenticated(self):
1014
1019
class SeriesDrivers(AuthorizationBase):
1924
1929
self.forwardCheckAuthenticated(user, self.obj.distribution))
1927
class AdminDistributionSourcePackageTranslations(AuthorizationBase):
1932
class AdminDistributionSourcePackageTranslations(DelegatedAuthorization):
1928
1933
"""DistributionSourcePackage objects link to a distribution."""
1929
1934
permission = 'launchpad.TranslationsAdmin'
1930
1935
usedfor = IDistributionSourcePackage
1932
def checkAuthenticated(self, user):
1933
"""Distribution admins are admins for source packages as well."""
1934
return self.forwardCheckAuthenticated(user, self.obj.distribution)
1937
def __init__(self, obj):
1938
super(AdminDistributionSourcePackageTranslations, self).__init__(
1939
obj, obj.distribution)
1937
1942
class AdminProductSeriesTranslations(AuthorizationBase):
1977
1982
self.branches))
1980
class PreviewDiffView(AuthorizationBase):
1985
class PreviewDiffView(DelegatedAuthorization):
1981
1986
permission = 'launchpad.View'
1982
1987
usedfor = IPreviewDiff
1986
return BranchMergeProposalView(self.obj.branch_merge_proposal)
1988
def checkAuthenticated(self, user):
1989
"""Is the user able to view the preview diff?
1991
The user can see a preview diff if they can see the merge proposal.
1993
return self.bmp_view.checkAuthenticated(user)
1995
def checkUnauthenticated(self):
1996
"""Is anyone able to view the branch merge proposal?
1998
The user can see a preview diff if they can see the merge proposal.
2000
return self.bmp_view.checkUnauthenticated()
2003
class CodeReviewVoteReferenceEdit(AuthorizationBase):
1989
def __init__(self, obj):
1990
super(PreviewDiffView, self).__init__(obj, obj.branch_merge_proposal)
1993
class CodeReviewVoteReferenceEdit(DelegatedAuthorization):
2004
1994
permission = 'launchpad.Edit'
2005
1995
usedfor = ICodeReviewVoteReference
1997
def __init__(self, obj):
1998
super(CodeReviewVoteReferenceEdit, self).__init__(
1999
obj, obj.branch_merge_proposal.target_branch)
2007
2001
def checkAuthenticated(self, user):
2008
2002
"""Only the affected teams may change the review request.
2014
2008
Anyone with edit permissions on the target branch of the merge
2015
2009
proposal can also edit the reviews.
2017
if user.inTeam(self.obj.reviewer) or user.inTeam(self.obj.registrant):
2019
target_access = EditBranch(
2020
self.obj.branch_merge_proposal.target_branch)
2021
return target_access.checkAuthenticated(user)
2024
class CodeReviewCommentView(AuthorizationBase):
2011
return (user.inTeam(self.obj.reviewer) or
2012
user.inTeam(self.obj.registrant) or
2013
super(CodeReviewVoteReferenceEdit, self).checkAuthenticated(
2017
class CodeReviewCommentView(DelegatedAuthorization):
2025
2018
permission = 'launchpad.View'
2026
2019
usedfor = ICodeReviewComment
2028
def checkAuthenticated(self, user):
2029
"""Is the user able to view the code review comment?
2031
The user can see a code review comment if they can see the branch
2034
bmp_checker = BranchMergeProposalView(self.obj.branch_merge_proposal)
2035
return bmp_checker.checkAuthenticated(user)
2037
def checkUnauthenticated(self):
2038
"""Are not-logged-in people able to view the code review comment?
2040
They can see a code review comment if they can see the branch merge
2043
bmp_checker = BranchMergeProposalView(self.obj.branch_merge_proposal)
2044
return bmp_checker.checkUnauthenticated()
2047
class CodeReviewCommentDelete(AuthorizationBase):
2021
def __init__(self, obj):
2022
super(CodeReviewCommentView, self).__init__(
2023
obj, obj.branch_merge_proposal)
2026
class CodeReviewCommentDelete(DelegatedAuthorization):
2048
2027
permission = 'launchpad.Edit'
2049
2028
usedfor = ICodeReviewCommentDeletion
2051
def checkAuthenticated(self, user):
2052
"""Is the user able to view the code review message?
2054
The user can see a code review message if they can see the branch
2057
bmp_checker = BranchMergeProposalEdit(self.obj.branch_merge_proposal)
2058
return bmp_checker.checkAuthenticated(user)
2060
def checkUnauthenticated(self):
2061
"""Are not-logged-in people able to view the code review message?
2063
They can see a code review message if they can see the branch merge
2066
bmp_checker = BranchMergeProposalEdit(self.obj.branch_merge_proposal)
2067
return bmp_checker.checkUnauthenticated()
2030
def __init__(self, obj):
2031
super(CodeReviewCommentDelete, self).__init__(
2032
obj, obj.branch_merge_proposal)
2070
2035
class BranchMergeProposalEdit(AuthorizationBase):
2334
2299
permission = "launchpad.Edit"
2335
2300
usedfor = IArchiveAuthToken
2302
def __init__(self, obj):
2303
super(EditArchiveAuthToken, self).__init__(
2304
obj, obj.archive, 'launchpad.Append')
2337
2306
def checkAuthenticated(self, user):
2338
auth_append = AppendArchive(self.obj.archive)
2339
if auth_append.checkAuthenticated(user):
2341
return user.in_admin
2344
class ViewPersonalArchiveSubscription(AuthorizationBase):
2307
return (user.in_admin or
2308
super(EditArchiveAuthToken, self).checkAuthenticated(user))
2311
class ViewPersonalArchiveSubscription(DelegatedAuthorization):
2345
2312
"""Restrict viewing of personal archive subscriptions (non-db class).
2347
2314
The user should be the subscriber, have append privilege to the archive
2350
2317
permission = "launchpad.View"
2351
2318
usedfor = IPersonalArchiveSubscription
2320
def __init__(self, obj):
2321
super(ViewPersonalArchiveSubscription, self).__init__(
2322
obj, obj.archive, 'launchpad.Append')
2353
2324
def checkAuthenticated(self, user):
2354
if user.person == self.obj.subscriber:
2356
append_archive = AppendArchive(self.obj.archive)
2358
if append_archive.checkAuthenticated(user):
2361
return user.in_admin
2364
class ViewArchiveSubscriber(AuthorizationBase):
2325
if user.person == self.obj.subscriber or user.in_admin:
2328
ViewPersonalArchiveSubscription, self).checkAuthenticated(user)
2331
class ViewArchiveSubscriber(DelegatedAuthorization):
2365
2332
"""Restrict viewing of archive subscribers.
2367
The user should be the subscriber, have append privilege to the
2334
The user should be the subscriber, have edit privilege to the
2368
2335
archive or be an admin.
2370
2337
permission = "launchpad.View"
2371
2338
usedfor = IArchiveSubscriber
2340
def __init__(self, obj):
2341
super(ViewArchiveSubscriber, self).__init__(
2342
obj, obj, 'launchpad.Edit')
2373
2344
def checkAuthenticated(self, user):
2374
auth_edit = EditArchiveSubscriber(self.obj)
2375
result = auth_edit.checkAuthenticated(user)
2377
result = user.inTeam(self.obj.subscriber)
2381
class EditArchiveSubscriber(AuthorizationBase):
2345
return (user.inTeam(self.obj.subscriber) or
2346
super(ViewArchiveSubscriber, self).checkAuthenticated(user))
2349
class EditArchiveSubscriber(DelegatedAuthorization):
2382
2350
"""Restrict editing of archive subscribers.
2384
2352
The user should have append privilege to the archive or be an admin.
2386
2354
permission = "launchpad.Edit"
2387
2355
usedfor = IArchiveSubscriber
2389
def checkAuthenticated(self, user):
2390
auth_append = AppendArchive(self.obj.archive)
2391
if auth_append.checkAuthenticated(user):
2393
return user.in_admin
2396
class DerivedAuthorization(AuthorizationBase):
2397
"""An Authorization that is based on permissions for other objects.
2399
Implementations must define permission, usedfor and iter_objects.
2400
iter_objects should iterate through the objects to check permission on.
2402
Failure on the permission check for any object causes an overall failure.
2405
def iter_adapters(self):
2407
getAdapter(obj, IAuthorization, self.permission)
2408
for obj in self.iter_objects())
2410
def checkAuthenticated(self, user):
2411
for adapter in self.iter_adapters():
2412
if not adapter.checkAuthenticated(user):
2416
def checkUnauthenticated(self):
2417
for adapter in self.iter_adapters():
2418
if not adapter.checkUnauthenticated():
2423
class ViewSourcePackageRecipe(DerivedAuthorization):
2357
def __init__(self, obj):
2358
super(EditArchiveSubscriber, self).__init__(
2359
obj, obj.archive, 'launchpad.Append')
2361
def checkAuthenticated(self, user):
2362
return (user.in_admin or
2363
super(EditArchiveSubscriber, self).checkAuthenticated(user))
2366
class ViewSourcePackageRecipe(DelegatedAuthorization):
2425
2368
permission = "launchpad.View"
2426
2369
usedfor = ISourcePackageRecipe
2449
2392
super(ViewSourcePackagePublishingHistory, self).__init__(obj.archive)
2452
class EditPublishing(AuthorizationBase):
2395
class EditPublishing(DelegatedAuthorization):
2453
2396
"""Restrict editing of source and binary packages.."""
2454
2397
permission = "launchpad.Edit"
2455
2398
usedfor = IPublishingEdit
2457
def checkAuthenticated(self, user):
2458
return AppendArchive(self.obj.archive).checkAuthenticated(user)
2400
def __init__(self, obj):
2401
super(EditPublishing, self).__init__(
2402
obj, obj.archive, 'launchpad.Append')
2461
2405
class ViewBinaryPackagePublishingHistory(ViewSourcePackagePublishingHistory):
2485
2429
def checkAuthenticated(self, user):
2486
2430
"""Verify that the user can view the sourcepackagerelease."""
2487
2431
for archive in self.obj.published_archives:
2488
auth_archive = ViewArchive(archive)
2489
if auth_archive.checkAuthenticated(user):
2432
adapter = queryAdapter(archive, IAuthorization, self.permission)
2433
if adapter is not None and adapter.checkAuthenticated(user):