def edit_group(request, name=None): """ edit_group(request, name = None) -> reply @type request: HttpRequest @param request: The request object @type name: string @param name: Default to None, when creating a new group Only superusers may create a group """ if not request.user.is_superuser: raise PopupException(_("You must be a superuser to add or edit a group."), error_code=401) if name is not None: instance = Group.objects.get(name=name) else: instance = None if request.method == 'POST': form = GroupEditForm(request.POST, instance=instance) if form.is_valid(): form.save() request.info(_('Group information updated')) return list_groups(request) else: form = GroupEditForm(instance=instance) return render('edit_group.mako', request, dict(form=form, action=request.path, name=name))
def edit_group(request, name=None): """ edit_group(request, name = None) -> reply @type request: HttpRequest @param request: The request object @type name: string @param name: Default to None, when creating a new group Only superusers may create a group """ if not request.user.is_superuser: raise PopupException( _("You must be a superuser to add or edit a group."), error_code=401) if name is not None: instance = Group.objects.get(name=name) else: instance = None if request.method == 'POST': form = GroupEditForm(request.POST, instance=instance) if form.is_valid(): form.save() request.info(_('Group information updated')) return list_groups(request) else: form = GroupEditForm(instance=instance) return render('edit_group.mako', request, dict(form=form, action=request.path, name=name))
def edit_group(request, name=None): """ edit_group(request, name = None) -> reply @type request: HttpRequest @param request: The request object @type name: string @param name: Default to None, when creating a new group Only superusers may create a group """ if not request.user.is_superuser: request.audit = {'allowed': False} if name is not None: request.audit['operation'] = 'EDIT_GROUP' request.audit['operationText'] = _get_failed_operation_text(request.user.username, 'EDIT_GROUP') else: request.audit['operation'] = 'CREATE_GROUP' request.audit['operationText'] = _get_failed_operation_text(request.user.username, 'CREATE_GROUP') raise PopupException(_("You must be a superuser to add or edit a group."), error_code=401) if name is not None: instance = Group.objects.get(name=name) else: instance = None if request.method == 'POST': form = GroupEditForm(request.POST, instance=instance) if form.is_valid(): form.save() request.info(_('Group information updated')) # Audit log if name is not None: usernames = instance.user_set.all().values_list('username', flat=True) request.audit = { 'operation': 'EDIT_GROUP', 'operationText': 'Edited Group: %s, with member(s): %s' % (name, ', '.join(usernames)) } else: user_ids = request.POST.getlist('members', []) usernames = User.objects.filter(pk__in=user_ids).values_list('username', flat=True) request.audit = { 'operation': 'CREATE_GROUP', 'operationText': 'Created Group: %s, with member(s): %s' % (request.POST.get('name', ''), ', '.join(usernames)) } return redirect(reverse(list_groups)) else: form = GroupEditForm(instance=instance) return render('edit_group.mako', request, { 'form': form, 'action': request.path, 'name': name, 'is_embeddable': request.GET.get('is_embeddable', False), })
def edit_group(request, name=None): """ edit_group(request, name = None) -> reply @type request: HttpRequest @param request: The request object @type name: string @param name: Default to None, when creating a new group Only superusers may create a group """ if not request.user.is_superuser: request.audit = {'allowed': False} if name is not None: request.audit['operation'] = 'EDIT_GROUP' request.audit['operationText'] = _get_failed_operation_text(request.user.username, 'EDIT_GROUP') else: request.audit['operation'] = 'CREATE_GROUP' request.audit['operationText'] = _get_failed_operation_text(request.user.username, 'CREATE_GROUP') raise PopupException(_("You must be a superuser to add or edit a group."), error_code=401) if name is not None: instance = Group.objects.get(name=name) else: instance = None if request.method == 'POST': form = GroupEditForm(request.POST, instance=instance) if form.is_valid(): form.save() request.info(_('Group information updated')) # Audit log if name is not None: usernames = instance.user_set.all().values_list('username', flat=True) request.audit = { 'operation': 'EDIT_GROUP', 'operationText': 'Edited Group: %s, with member(s): %s' % (name, ', '.join(usernames)) } else: user_ids = request.POST.getlist('members', []) usernames = User.objects.filter(pk__in=user_ids).values_list('username', flat=True) request.audit = { 'operation': 'CREATE_GROUP', 'operationText': 'Created Group: %s, with member(s): %s' % (request.POST.get('name', ''), ', '.join(usernames)) } return redirect(reverse(list_groups)) else: form = GroupEditForm(instance=instance) return render('edit_group.mako', request, dict(form=form, action=request.path, name=name))
def edit_group(request, name=None): """ edit_group(request, name = None) -> reply @type request: HttpRequest @param request: The request object @type name: string @param name: Default to None, when creating a new group Only superusers may create a group """ if not request.user.is_superuser: request.audit = {'allowed': False} if name is not None: request.audit['operation'] = 'EDIT_GROUP' request.audit['operationText'] = _get_failed_operation_text(request.user.username, 'EDIT_GROUP') else: request.audit['operation'] = 'CREATE_GROUP' request.audit['operationText'] = _get_failed_operation_text(request.user.username, 'CREATE_GROUP') raise PopupException(_("You must be a superuser to add or edit a group."), error_code=401) if name is not None: instance = Group.objects.get(name=name) else: instance = None is_embeddable = request.GET.get('is_embeddable', request.POST.get('is_embeddable', False)) if request.method == 'POST': form = GroupEditForm(request.POST, instance=instance) if form.is_valid(): form.save() # Audit log if name is not None: usernames = instance.user_set.all().values_list('username', flat=True) request.audit = { 'operation': 'EDIT_GROUP', 'operationText': 'Edited Group: %s, with member(s): %s' % (name, ', '.join(usernames)) } else: user_ids = request.POST.getlist('members', []) usernames = User.objects.filter(pk__in=user_ids).values_list('username', flat=True) request.audit = { 'operation': 'CREATE_GROUP', 'operationText': 'Created Group: %s, with member(s): %s' % (request.POST.get('name', ''), ', '.join(usernames)) } if is_embeddable: return JsonResponse({'url': '/hue' + reverse(list_groups)}) else: request.info(_('Group information updated')) return redirect('/useradmin/groups') else: form = GroupEditForm(instance=instance) if request.method == 'POST' and is_embeddable: return JsonResponse( {'status': -1, 'errors': [{'id': f.id_for_label, 'message': f.errors} for f in form if f.errors]}) else: return render('edit_group.mako', request, { 'form': form, 'action': request.path, 'name': name, 'is_embeddable': is_embeddable, })