~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/model/translationimportqueue.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-27 19:27:56 UTC
  • mfrom: (13453.4.5 bug-800123)
  • Revision ID: launchpad@pqm.canonical.com-20110727192756-twhbrx0a7mnie8qw
[r=gmb][bug=800123] Allow project maintainers and owners to manage
        and approve translation imports themselves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    Int,
35
35
    Reference,
36
36
    )
37
 
from zope.component import getUtility
 
37
from zope.component import (
 
38
    getUtility,
 
39
    queryAdapter,
 
40
    )
38
41
from zope.interface import implements
39
42
 
40
43
from canonical.database.constants import (
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 (
296
300
 
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):
304
 
                return True
305
 
        # Rosetta experts and admins can administer the entry.
306
 
        return roles.in_rosetta_experts or roles.in_admin
307
 
 
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):
312
 
            return True
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))
320
 
        return False
 
303
        next_adapter = queryAdapter(self, IAuthorization, 'launchpad.Admin')
 
304
        if next_adapter is None:
 
305
            return False
 
306
        else:
 
307
            return next_adapter.checkAuthenticated(roles)
321
308
 
322
309
    def canEdit(self, roles):
323
310
        """See `ITranslationImportQueueEntry`."""
324
 
        # The importer can edit the entry.
325
 
        if roles.inTeam(self.importer):
326
 
            return True
327
 
        return self._canEditExcludeImporter(roles)
 
311
        next_adapter = queryAdapter(self, IAuthorization, 'launchpad.Edit')
 
312
        if next_adapter is None:
 
313
            return False
 
314
        else:
 
315
            return next_adapter.checkAuthenticated(roles)
328
316
 
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)
358
346