def sorted_rows(self, start, end, sort, order): rows = list() term = self.filter_term model = self.model principal_roles = model.principal_roles inheritance = model.role_inheritance if term: principal_ids = security.search_for_principals('*%s*' % term) else: if inheritance: principal_ids = model.aggregated_roles.keys() else: principal_ids = principal_roles.keys() # XXX: currently always sorted by principal id. Fix to sort by # principal title, needs some refactoring though ids = sorted(principal_ids) if order == 'desc': ids.reverse() user_display_attr = ugm_backend.user_display_attr group_display_attr = ugm_backend.group_display_attr for principal_id in ids[start:end]: principal = security.principal_by_id(principal_id) if not principal: logger.warning('principal %s not found' % principal_id) continue else: if principal_id.startswith('group:'): title = principal.attrs.get(group_display_attr) title = title if title else principal_id[6:] else: title = principal.attrs.get(user_display_attr) title = title if title else principal_id row_data = RowData() row_data['principal'] = title ugm_roles = principal.roles local_roles = principal_roles.get(principal_id, list()) if inheritance: for role in model.aggregated_roles_for(principal_id): if role not in local_roles: ugm_roles.append(role) for role in security.DEFAULT_ROLES: inherited = role[0] in ugm_roles local = role[0] in local_roles row_data[role[0]] = \ self._role_column(principal_id, role[0], local, inherited) rows.append(row_data) return rows
def sorted_rows(self, start, end, sort, order): rows = list() term = self.filter_term model = self.model principal_roles = model.principal_roles inheritance = model.role_inheritance if term: principal_ids = security.search_for_principals('*%s*' % term) else: if inheritance: principal_ids = model.aggregated_roles.keys() else: principal_ids = principal_roles.keys() # XXX: currently always sorted by principal id. Fix to sort by # principal title, needs some refactoring though ids = sorted(principal_ids) if order == 'desc': ids.reverse() for principal_id in ids[start:end]: principal = security.principal_by_id(principal_id) if not principal: logger.warning('principal %s not found' % principal_id) continue else: default = principal_id if principal_id.startswith('group:'): default = principal_id[6:] title = principal.attrs.get(GROUP_TITLE_ATTR, default) else: title = principal.attrs.get(USER_TITLE_ATTR, default) row_data = RowData() row_data['principal'] = title ugm_roles = principal.roles local_roles = principal_roles.get(principal_id, list()) if inheritance: for role in model.aggregated_roles_for(principal_id): if role not in local_roles: ugm_roles.append(role) for role in security.DEFAULT_ROLES: inherited = role[0] in ugm_roles local = role[0] in local_roles row_data[role[0]] = \ self._role_column(principal_id, role[0], local, inherited) rows.append(row_data) return rows
def sorted_rows(self, start, end, sort, order): rows = list() term = self.filter_term model = self.model principal_roles = model.principal_roles inheritance = model.role_inheritance if term: principal_ids = security.search_for_principals('*%s*' % term) else: if inheritance: principal_ids = model.aggregated_roles.keys() else: principal_ids = principal_roles.keys() ids = principal_ids if order == 'desc': ids.reverse() for principal_id in ids[start:end]: principal = security.principal_by_id(principal_id) if not principal: logger.warning('principal %s not found' % principal_id) continue else: default = principal_id if principal_id.startswith('group:'): default = principal_id[6:] title = principal.attrs.get('fullname', default) row_data = RowData() row_data['principal'] = title ugm_roles = principal.roles local_roles = principal_roles.get(principal_id, list()) if inheritance: for role in model.aggregated_roles_for(principal_id): if not role in local_roles: ugm_roles.append(role) for role in security.DEFAULT_ROLES: inherited = role[0] in ugm_roles local = role[0] in local_roles row_data[role[0]] = \ self._role_column(principal_id, role[0], local, inherited) rows.append(row_data) return rows
def sorted_rows(self, start, end, sort, order): rows = list() term = self.filter_term model = self.model principal_roles = model.principal_roles inheritance = model.role_inheritance if term: principal_ids = security.search_for_principals("*%s*" % term) else: if inheritance: principal_ids = model.aggregated_roles.keys() else: principal_ids = principal_roles.keys() ids = principal_ids if order == "desc": ids.reverse() for principal_id in ids[start:end]: principal = security.principal_by_id(principal_id) if not principal: logger.warning("principal %s not found" % principal_id) continue else: default = principal_id if principal_id.startswith("group:"): default = principal_id[6:] title = principal.attrs.get("fullname", default) row_data = RowData() row_data["principal"] = title ugm_roles = principal.roles local_roles = principal_roles.get(principal_id, list()) if inheritance: for role in model.aggregated_roles_for(principal_id): if not role in local_roles: ugm_roles.append(role) for role in security.DEFAULT_ROLES: inherited = role[0] in ugm_roles local = role[0] in local_roles row_data[role[0]] = self._role_column(principal_id, role[0], local, inherited) rows.append(row_data) return rows
def item_count(self): term = self.filter_term if term: principals = security.search_for_principals('*%s*' % term) return len(principals) return len(self.model.principal_roles.keys())
def item_count(self): term = self.filter_term if term: principals = security.search_for_principals("*%s*" % term) return len(principals) return len(self.model.principal_roles.keys())
def test_search_for_principals(self): self.assertEqual(search_for_principals('viewer'), [u'viewer']) self.assertEqual(search_for_principals('group*'), [u'group:group1'])