def delete(self, request, largs, name, subname): """Remove a subgroup from a group.""" if not request.user.has_perm('Groups.group_remove_group'): return HttpResponseForbidden() if backend.SUPPORTS_SUBGROUPS is False: return HttpResponseNotImplemented() # If GroupNotFound: 404 Not Found backend.remove_subgroup(group=name, service=request.user, subgroup=subname, subservice=request.user) self.log.info('Remove subgroup %s', subname, extra=largs) return HttpResponseNoContent()
def _main(args): # Actions that do not act on an existing group: if args.action == 'add': try: backend.create_group(group=args.group, service=args.service) except GroupExists: parser.error('Group already exists.') elif args.action in ['list', 'ls']: groups = backend.list_groups(service=args.service) for name in sorted(groups): print(name) elif args.action == 'view': explicit_users = sorted(backend.members(group=args.group, service=args.service, depth=0)) effective_users = sorted(backend.members(group=args.group, service=args.service)) if explicit_users: print('* Explicit members: %s' % ', '.join(explicit_users)) else: print('* No explicit members') if backend.SUPPORTS_SUBGROUPS: if effective_users: print('* Effective members: %s' % ', '.join(effective_users)) else: print('* No effective members') if backend.SUPPORTS_SUBGROUPS is True: parents = backend.parents(group=args.group, service=args.service) sub_groups = backend.subgroups(group=args.group, service=args.service, filter=False) if parents: if backend.SUPPORTS_GROUP_VISIBILITY: print('* Parent groups:') parents = sorted(parents, key=lambda g: g[1].username if g[1] else '') print_by_service(parents, ' ') else: print('* Parent groups: %s' % ', '.join([g[0] for g in parents])) else: print('* No parent groups') if sub_groups: if backend.SUPPORTS_GROUP_VISIBILITY: print('* Subgroups:') sub_groups = sorted(sub_groups, key=lambda g: g[1].username if g[1] else '') print_by_service(sub_groups, ' ') else: print('* Subgroups: %s' % ', '.join([g[0] for g in sub_groups])) else: print('* No subgroups') elif args.action == 'set-service': if backend.SUPPORTS_GROUP_VISIBILITY is False: parser.error('Backend does not support group visiblity.') backend.set_service(group=args.group, service=args.service, new_service=args.new_service) elif args.action == 'add-user': backend.add_member(group=args.group, service=args.service, user=args.user) elif args.action == 'add-group': if backend.SUPPORTS_SUBGROUPS is False: parser.error('Backend does not support subgroups.') backend.add_subgroup(group=args.group, service=args.service, subgroup=args.subgroup, subservice=args.sub_service) elif args.action in ['delete', 'del', 'rm']: backend.remove_group(group=args.group, service=args.service) elif args.action in ['remove-user', 'rm-user', 'del-user']: try: backend.remove_member(group=args.group, service=args.service, user=args.user) except UserNotFound: parser.error('User "%s" not member of group "%s".' % (args.user, args.group)) elif args.action == 'rename': backend.rename_group(args.group, args.name, service=args.service) elif args.action in ['remove-group', 'rm-group', 'del-group']: # pragma: no branch if backend.SUPPORTS_SUBGROUPS is False: parser.error('Backend does not support subgroups.') try: backend.remove_subgroup(group=args.group, service=args.service, subgroup=args.subgroup, subservice=args.sub_service) except GroupNotFound: parser.error('Group "%s" is not a subgroup of "%s".' % (args.subgroup, args.group))