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
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
def test_principal_searcher(self): import ptah principal = Principal("1", "user", "user") def search(term=""): if term == "user": yield principal ptah.register_principal_searcher("test-provider", search) self.assertEqual(list(ptah.search_principals("user")), [principal])
def test_principal_searcher(self): import ptah principal = Principal('1', 'user', 'user') def search(term=''): if term == 'user': yield principal ptah.register_principal_searcher('test-provider', search) self.init_ptah() self.assertEqual(list(ptah.search_principals('user')), [principal])
def test_principal_searcher_pyramid(self): import ptah principal = Principal('1', 'user', 'user') def search(term=''): if term == 'user': yield principal config = testing.setUp() config.include('ptah') config.ptah_principal_searcher('test-provider', search) self.assertEqual(list(ptah.search_principals('user')), [principal])
def update(self): if 'form.buttons.search' in self.request.POST: self.term = self.request.POST.get('term') self.principals = list(ptah.search_principals(self.term)) if 'form.buttons.clear' in self.request.POST: self.term = '' self.principals = self.local_principals if not self.principals: if not self.term: self.request.add_message(_('There are no local roles defined.'), 'info') else: self.request.add_message(_('There are no users or groups found.'), 'info') return super(ShareForm, self).update()
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)
def update(self): if 'form.buttons.search' in self.request.POST: self.term = self.request.POST.get('term') self.principals = list(ptah.search_principals(self.term)) if 'form.buttons.clear' in self.request.POST: self.term = '' self.principals = self.local_principals if not self.principals: if not self.term: self.request.add_message( _('There are no local roles defined.'), 'info') else: self.request.add_message( _('There are no users or groups found.'), 'info') return super(ShareForm, self).update()
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)