예제 #1
0
def projects(request):

    if request.method == 'POST':

        from project_actions import add_user_to_project, remove_user_from_project
        from project_actions import add_group_to_project, remove_group_from_project

        if request.POST['action'] == 'add':
            project_id = request.POST['project_id']
            name = request.POST['name']
            pa_project = PAProject.objects.get(id=project_id)
            try:
                pa_user = PAUser.objects.get(name=name)
                add_user_to_project(pa_project, pa_user)
            except:
                pa_group = PAGroup.objects.get(name=name)
                add_group_to_project(pa_project, pa_group)

        elif request.POST['action'] == 'remove_user':
            project_access_id = request.POST['user_with_access_id']
            pa_project_access = PAUserProjectAccess.objects.get(id=project_access_id)
            remove_user_from_project(pa_project_access)
        elif request.POST['action'] == 'remove_group':
            project_access_id = request.POST['group_with_access_id']
            pa_project_access = PAGroupProjectAccess.objects.get(id=project_access_id)
            remove_group_from_project(pa_project_access)
        else:
            raise Exception("Unsupported POST action")

    template = loader.get_template('projects.html')
    context = RequestContext(request, {
        'projects': PAProject.objects.all(),
    })

    return HttpResponse(template.render(context))
예제 #2
0
    def destroy(self, request, project_pk, pk):

        project = self.get_project(project_pk)
        user_project_access = PAUserProjectAccess.objects.get(id=pk)
        if PAUserProjectAccess.objects.filter(project=project, id=user_project_access.pk).exists():
            remove_user_from_project(user_project_access)

            return Response(None, status.HTTP_204_NO_CONTENT)
        else:
            return Response({u"detail": "User is not part of project's access list"}, status.HTTP_404_NOT_FOUND)
    def test_add_and_remove_user(self):

        with P4Connection(self.P4HOST, self.P4PORT, self.P4USER) as p4:
            project = None
            project_access = None
            try:
                project = create_new_project(self.PROJECT_NAME)
                project_access = add_user_to_project(project, self.user)
                remove_user_from_project(project_access)
            except:
                if project_access:
                    remove_user_from_project(project_access)
                if project:
                    delete_project(project)
                raise
    def test_add_and_remove_user(self):

        with P4ConnectionAsUnitTestUser() as p4:
            project = None
            project_access = None
            try:
                project = create_new_project(self.PROJECT_NAME)
                project_access = add_user_to_project(project, self.user)
                remove_user_from_project(project_access)
                project_access = None
                delete_project(project)
                project = None
            except:
                if project_access:
                    remove_user_from_project(project_access)
                if project:
                    delete_project(project)
                raise