~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Browser views for archivepermission."""

__metaclass__ = type

__all__ = [
    'ArchivePermissionUrl',
    ]

from zope.interface import implements

from lp.services.webapp.interfaces import ICanonicalUrlData
from lp.soyuz.enums import ArchivePermissionType


class ArchivePermissionURL:
    """Dynamic URL declaration for `IArchivePermission`."""
    implements(ICanonicalUrlData)
    rootsite = None

    def __init__(self, context):
        self.context = context

    @property
    def inside(self):
        return self.context.archive

    @property
    def path(self):
        if self.context.permission == ArchivePermissionType.UPLOAD:
            perm_type = "+upload"
        elif self.context.permission == ArchivePermissionType.QUEUE_ADMIN:
            perm_type = "+queue-admin"
        else:
            raise AssertionError, (
                "Unknown permission type %s" % self.context.permission)

        username = self.context.person.name

        if self.context.component_name is not None:
            item = "type=component&item=%s" % self.context.component_name
        elif self.context.source_package_name is not None:
            item = (
                "type=packagename&item=%s" % self.context.source_package_name)
        elif self.context.package_set_name is not None:
            item = ("type=packageset&item=%s&series=%s" %
                    (self.context.package_set_name,
                     self.context.distro_series_name))
        else:
            raise AssertionError, (
                "One of component, sourcepackagename or package set should "
                "be set")

        return u"%s/%s?%s" % (perm_type, username, item)