def add_sesh_user(request): """ View for adding a new sesh user user should be an organisation admin """ if request.user.is_org_admin: if request.method == 'POST': form = SeshUserForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.organisation = request.user.organisation user.save() return redirect('manage_org_users') else: return HttpResponseForbidden() else: return HttpResponseForbidden()
def edit_sesh_user(request, user_id): """ Edits a sesh user the user loged in should be an admin of the organisation """ if request.user.is_org_admin: context_dict = {} user = Sesh_User.objects.filter(id=user_id).first() form = SeshUserForm(instance=user) if request.method == 'POST': form = SeshUserForm(request.POST, instance=user) if form.is_valid(): form.save() return redirect('manage_org_users') user_sites = _get_user_sites(request) context_dict['form'] = form context_dict['permitted'] = get_org_edit_permissions(request.user) context_dict['sites_stats'] = get_quick_status(user_sites) return render(request, 'seshdash/settings/edit_sesh_user.html', context_dict) else: return HttpResponseForbidden()