예제 #1
0
    def test_role_roles(self):
        import ptah

        role = ptah.Role('myrole', 'MyRole')
        self.init_ptah()

        self.assertTrue('myrole' in ptah.get_roles())
        self.assertTrue(ptah.get_roles()['myrole'] is role)
예제 #2
0
    def test_role_defaults(self):
        roles = sorted(list(ptah.get_roles().keys()))[:3]

        self.assertTrue(['Authenticated', 'Everyone', 'Owner'] == roles)
        self.assertTrue(ptah.get_roles()['Everyone'].id == 'system.Everyone')
        self.assertTrue(
            ptah.get_roles()['Authenticated'].id == 'system.Authenticated')
        self.assertTrue(ptah.get_roles()['Owner'].id == 'system.Owner')
예제 #3
0
    def test_role_roles(self):
        import ptah

        role = ptah.Role("myrole", "MyRole")
        self._init_ptah()

        self.assertTrue("myrole" in ptah.get_roles())
        self.assertTrue(ptah.get_roles()["myrole"] is role)
예제 #4
0
    def test_role_roles(self):
        import ptah

        role = ptah.Role('myrole', 'MyRole')
        self.init_ptah()

        self.assertTrue('myrole' in ptah.get_roles())
        self.assertTrue(ptah.get_roles()['myrole'] is role)
예제 #5
0
    def test_role_defaults(self):
        import ptah

        roles = sorted(list(ptah.get_roles().keys()))[:3]

        self.assertTrue(['Authenticated', 'Everyone', 'Owner'] == roles)
        self.assertTrue(ptah.get_roles()['Everyone'].id == 'system.Everyone')
        self.assertTrue(ptah.get_roles()['Authenticated'].id=='system.Authenticated')
        self.assertTrue(ptah.get_roles()['Owner'].id=='system.Owner')
예제 #6
0
    def test_role_defaults(self):
        import ptah

        self._init_ptah()

        roles = list(ptah.get_roles().keys())
        roles.sort()
        roles = roles[:3]

        self.assertTrue(["Authenticated", "Everyone", "Owner"] == roles)
        self.assertTrue(ptah.get_roles()["Everyone"].id == "system.Everyone")
        self.assertTrue(ptah.get_roles()["Authenticated"].id == "system.Authenticated")
        self.assertTrue(ptah.get_roles()["Owner"].id == "system.Owner")
예제 #7
0
파일: apps.py 프로젝트: djedproject/ptahcms
    def update(self):
        res = super(SharingForm, self).update()

        request = self.request
        context = self.context

        self.roles = [r for r in ptah.get_roles().values() if not r.system]
        self.local_roles = local_roles = context.__local_roles__

        term = request.session.get('apps-sharing-term', '')
        if term:
            self.users = list(ptah.search_principals(term))

        if 'form.buttons.save' in request.POST:
            users = []
            userdata = {}
            for attr, val in request.POST.items():
                if attr.startswith('user-'):
                    userId, roleId = attr[5:].rsplit('-',1)
                    data = userdata.setdefault(str(userId), [])
                    data.append(str(roleId))
                if attr.startswith('userid-'):
                    users.append(str(attr.split('userid-')[-1]))

            for uid in users:
                if userdata.get(uid):
                    local_roles[str(uid)] = userdata[uid]
                elif uid in local_roles:
                    del local_roles[uid]

            context.__local_roles__ = local_roles

        return res
예제 #8
0
    def update(self):
        super(SharingForm, self).update()

        request = self.request
        context = self.context

        self.roles = [r for r in ptah.get_roles().values() if not r.system]
        self.local_roles = local_roles = context.__local_roles__

        term = request.session.get('sharing-search-term', '')
        if term:
            self.users = list(ptah.search_principals(term))

        if 'form.buttons.save' in request.POST:
            users = []
            userdata = {}
            for attr, val in request.POST.items():
                if attr.startswith('user-'):
                    userId, roleId = attr[5:].rsplit('-', 1)
                    data = userdata.setdefault(str(userId), [])
                    data.append(str(roleId))
                if attr.startswith('userid-'):
                    users.append(str(attr.split('userid-')[-1]))

            for uid in users:
                if userdata.get(uid):
                    local_roles[str(uid)] = userdata[uid]
                elif uid in local_roles:
                    del local_roles[uid]

            context.__local_roles__ = local_roles
예제 #9
0
파일: user.py 프로젝트: webmaven/ptahcrowd
def get_roles_vocabulary(context):
    roles = []
    for name, role in ptah.get_roles().items():
        if role.system:
            continue

        roles.append([role.title, form.SimpleTerm(role.id, role.id, role.title)])

    return form.SimpleVocabulary(*[term for _t, term in sorted(roles)])
예제 #10
0
def get_roles_vocabulary(context):
    roles = []
    for name, role in ptah.get_roles().items():
        if role.system:
            continue

        roles.append(
            [role.title,
             ptah.form.Term(role.id, role.id, role.title)])

    return ptah.form.Vocabulary(*[term for _t, term in sorted(roles)])
예제 #11
0
    def __init__(self, context, request):
        self.tinfo = context.__type__
        self.roles = [r for r in ptah.get_roles().values() if not r.system]
        self.local_roles = local_roles = context.__local_roles__
        self.local_principals = [ptah.resolve(principalUri)
                               for principalUri in self.local_roles]

        for p in list(ptah.search_principals('')):
            p = ptah.resolve(p.__uri__)
            if hasattr(p, 'properties'):
                if p.properties.get('roles') and p not in self.local_principals:
                    self.local_principals.append(p)

        self.principals = sorted(self.local_principals, key=lambda p: str(p))

        super(ShareForm, self).__init__(context, request)
예제 #12
0
    def __init__(self, context, request):
        self.tinfo = context.__type__
        self.roles = [r for r in ptah.get_roles().values() if not r.system]
        self.local_roles = local_roles = context.__local_roles__
        self.local_principals = [
            ptah.resolve(principalUri) for principalUri in self.local_roles
        ]

        for p in list(ptah.search_principals('')):
            p = ptah.resolve(p.__uri__)
            if hasattr(p, 'properties'):
                if p.properties.get(
                        'roles') and p not in self.local_principals:
                    self.local_principals.append(p)

        self.principals = sorted(self.local_principals, key=lambda p: str(p))

        super(ShareForm, self).__init__(context, request)
예제 #13
0
 def update(self):
     self.roles = sorted(ptah.get_roles().values(), key=lambda r: r.title)
예제 #14
0
 def update(self):
     self.roles = ptah.get_roles().values()
     self.roles.sort(key = lambda r: r.title)
예제 #15
0
 def renderActions(self, *actions):
     return self.actions(
         roles = ptah.get_roles(),
         actions = actions,
         manage_url = manage.CONFIG.manage_url,
         request = self.request)
예제 #16
0
 def update(self):
     self.roles = sorted(ptah.get_roles().values(), key=lambda r: r.title)
예제 #17
0
 def renderActions(self, *actions):
     return self.actions(
         roles = ptah.get_roles(),
         actions = actions,
         request = self.request)