def member_list(context, data_dict): check_access('member_list', context, data_dict) # Copy from CKAN member_list: model = context['model'] group = model.Group.get(_get_or_bust(data_dict, 'id')) if not group: raise NotFound obj_type = data_dict.get('object_type', None) capacity = data_dict.get('capacity', None) # User must be able to update the group to remove a member from it check_access('group_show', context, data_dict) q = model.Session.query(model.Member).\ filter(model.Member.group_id == group.id).\ filter(model.Member.state == "active") if obj_type: q = q.filter(model.Member.table_name == obj_type) if capacity: q = q.filter(model.Member.capacity == capacity) trans = authz.roles_trans() def translated_capacity(capacity): try: return _Capacity(trans[capacity], capacity) # Etsin modification except KeyError: return capacity return [(m.table_id, m.table_name, translated_capacity(m.capacity)) for m in q.all()]
def member_list(context, data_dict=None): '''Return the members of a group. Modified copy of the original ckan member_list action to also return the non-translated capacity (role) :rtype: list of (id, type, translated capacity, capacity ) tuples ''' model = context['model'] group = model.Group.get(_get_or_bust(data_dict, 'id')) if not group: raise logic.NotFound # user = context.get('user') if group.state == 'deleted' and (not c.userobj or not c.userobj.sysadmin): raise logic.NotFound obj_type = data_dict.get('object_type', None) capacity = data_dict.get('capacity', None) show_user_info = data_dict.get('user_info', False) q_term = data_dict.get('q', None) # User must be able to update the group to remove a member from it _check_access('group_show', context, data_dict) q = model.Session.query(model.Member, model.User). \ filter(model.Member.table_id == model.User.id). \ filter(model.Member.group_id == group.id). \ filter(model.Member.state == "active") if q_term and q_term != '': q = q.filter( sqlalchemy.or_(model.User.fullname.ilike('%' + q_term + '%'), model.User.name.ilike('%' + q_term + '%'))) if obj_type: q = q.filter(model.Member.table_name == obj_type) if capacity: q = q.filter(model.Member.capacity == capacity) trans = new_authz.roles_trans() def translated_capacity(capacity): try: return trans[capacity] except KeyError: return capacity if show_user_info: return [(m.table_id, m.table_name, translated_capacity(m.capacity), m.capacity, u.fullname if u.fullname else u.name) for m, u in q.all()] else: return [(m.table_id, m.table_name, translated_capacity(m.capacity), m.capacity) for m, u in q.all()]
def get_member_list(context, data_dict=None): ''' :param id: the id or name of the group :type id: string :param object_type: restrict the members returned to those of a given type, e.g. ``'user'`` or ``'package'`` (optional, default: ``None``) :type object_type: string :param capacity: restrict the members returned to those with a given capacity, e.g. ``'member'``, ``'editor'``, ``'admin'``, ``'public'``, ``'private'`` (optional, default: ``None``) :type capacity: string :rtype: list of (id, type, capacity) tuples :raises: :class:`ckan.logic.NotFound`: if the group doesn't exist ''' model = context['model'] group = model.Group.get(logic.get_or_bust(data_dict, 'id')) if not group: raise NotFound obj_type = data_dict.get('object_type', None) capacity = data_dict.get('capacity', None) q = model.Session.query(model.Member).\ filter(model.Member.group_id == group.id).\ filter(model.Member.state == "active") if obj_type: q = q.filter(model.Member.table_name == obj_type) if capacity: q = q.filter(model.Member.capacity == capacity) trans = authz.roles_trans() def translated_capacity(capacity): try: return trans[capacity] except KeyError: return capacity return [(m.table_id, m.table_name, translated_capacity(m.capacity)) for m in q.all()]