58
61
from canonical.librarian.interfaces import ILibrarianClient
59
62
from lp.app.errors import NotFoundError
60
63
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
64
from lp.app.interfaces.security import IAuthorization
61
65
from lp.registry.interfaces.distribution import IDistribution
62
66
from lp.registry.interfaces.distroseries import IDistroSeries
63
67
from lp.registry.interfaces.person import (
297
301
def canAdmin(self, roles):
298
302
"""See `ITranslationImportQueueEntry`."""
299
# As a special case, the Ubuntu translation group owners can
300
# manage Ubuntu uploads.
301
if self.is_targeted_to_ubuntu:
302
group = self.distroseries.distribution.translationgroup
303
if group is not None and roles.inTeam(group.owner):
305
# Rosetta experts and admins can administer the entry.
306
return roles.in_rosetta_experts or roles.in_admin
308
def _canEditExcludeImporter(self, roles):
309
"""All people that can edit the entry except the importer."""
310
# Admin rights include edit rights.
311
if self.canAdmin(roles):
313
# The maintainer and the drivers can edit the entry.
314
if self.productseries is not None:
315
return (roles.isOwner(self.productseries.product) or
316
roles.isOneOfDrivers(self.productseries))
317
if self.distroseries is not None:
318
return (roles.isOwner(self.distroseries.distribution) or
319
roles.isOneOfDrivers(self.distroseries))
303
next_adapter = queryAdapter(self, IAuthorization, 'launchpad.Admin')
304
if next_adapter is None:
307
return next_adapter.checkAuthenticated(roles)
322
309
def canEdit(self, roles):
323
310
"""See `ITranslationImportQueueEntry`."""
324
# The importer can edit the entry.
325
if roles.inTeam(self.importer):
327
return self._canEditExcludeImporter(roles)
311
next_adapter = queryAdapter(self, IAuthorization, 'launchpad.Edit')
312
if next_adapter is None:
315
return next_adapter.checkAuthenticated(roles)
329
317
def canSetStatus(self, new_status, user):
330
318
"""See `ITranslationImportQueueEntry`."""
352
340
return roles.in_admin or roles.in_rosetta_experts
353
341
if new_status == RosettaImportStatus.BLOCKED:
354
342
# Importers are not allowed to set BLOCKED
355
return self._canEditExcludeImporter(roles)
343
return self.canAdmin(roles)
356
344
# All other statuses can be set set by all authorized persons.
357
345
return self.canEdit(roles)