def edit_collaborator(request, project_id, username): """ Form to edit collaborator's permissions in a project """ project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): return HttpResponse("Unauthorized") project_collaborator = get_object_or_404(ProjectCollaborator, project=project, user__username=username) if request.method == 'POST': form = base_forms.EditCollaboratorForm(request.POST) if form.is_valid(): project_collaborator.collaborator_type = form.cleaned_data[ 'collaborator_type'] project_collaborator.save() return redirect('project_collaborators', project_id) else: form = base_forms.EditCollaboratorForm() return render( request, 'project/edit_collaborator.html', { 'project_collaborator': project_collaborator, 'project': project, 'form': form, })
def edit_collaborator(request, project_id, username): """ Form to edit collaborator's permissions in a project """ project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): return HttpResponse("Unauthorized") project_collaborator = get_object_or_404(ProjectCollaborator, project=project, user__username=username) if request.method == 'POST': form = base_forms.EditCollaboratorForm(request.POST) if form.is_valid(): seqr_projects = SeqrProject.objects.filter( deprecated_project_id=project_id) if seqr_projects: if form.cleaned_data['collaborator_type'] == 'manager': seqr_projects[0].can_edit_group.user_set.add( project_collaborator.user) seqr_projects[0].can_view_group.user_set.add( project_collaborator.user) elif form.cleaned_data['collaborator_type'] == 'collaborator': seqr_projects[0].can_edit_group.user_set.remove( project_collaborator.user) seqr_projects[0].can_view_group.user_set.add( project_collaborator.user) else: raise ValueError( "Unexpected collaborator_type: " + str(form.cleaned_data['collaborator_type'])) project_collaborator.collaborator_type = form.cleaned_data[ 'collaborator_type'] project_collaborator.save() return redirect('project_collaborators', project_id) else: form = base_forms.EditCollaboratorForm() return render( request, 'project/edit_collaborator.html', { 'project_collaborator': project_collaborator, 'project': project, 'form': form, })