예제 #1
0
파일: views.py 프로젝트: ghusse/gitstack
def rest_group(request):
    try:
        # create a group
        if request.method == 'POST':
            # get the username/password from the request
            name = request.POST['name']
            # check the username
            matcher = re.compile("^[A-Za-z]\w{0,}$")
            if matcher.match(name) is None:
                return HttpResponseServerError("Please enter an alphanumeric name without spaces")
            if(name == ""):
                return HttpResponseServerError("Please enter a non empty name")
            group = Group(name)
            group.create()
            return HttpResponse("Group " + name + " has been successfully created." )
        
        # get retrieve_all the groups
        if request.method == 'GET':
            group_list = Group.retrieve_all()
            json_reply = jsonpickle.encode(group_list, unpicklable = False)

            return HttpResponse(json_reply)
        
    except Exception as e:
        return HttpResponseServerError(e)
예제 #2
0
def rest_group(request):
    try:
        # create a group
        if request.method == 'POST':
            # get the username/password from the request
            name = request.POST['name']
            # check the username
            matcher = re.compile("^[A-Za-z]\w{0,}$")
            if matcher.match(name) is None:
                return HttpResponseServerError(
                    "Please enter an alphanumeric name without spaces")
            if (name == ""):
                return HttpResponseServerError("Please enter a non empty name")
            group = Group(name)
            group.create()
            return HttpResponse("Group " + name +
                                " has been successfully created.")

        # get retrieve_all the groups
        if request.method == 'GET':
            group_list = Group.retrieve_all()
            json_reply = jsonpickle.encode(group_list, unpicklable=False)

            return HttpResponse(json_reply)

    except Exception as e:
        return HttpResponseServerError(e)
예제 #3
0
def rest_group_action(request, name):
    try:
        if request.method == 'DELETE':
            # retrieve the group name from the url
            group = Group(name)
            # delete the user
            group.delete()
            return HttpResponse(name + " has been deleted")
    except Exception as e:
        return HttpResponseServerError(e)
예제 #4
0
def rest_group_action(request, name):
    try:
        if request.method == 'DELETE':
            # retrieve the group name from the url
            group = Group(name)
            # delete the user
            group.delete()
            return HttpResponse(name + " has been deleted")
    except Exception as e:
        return HttpResponseServerError(e)
예제 #5
0
def rest_group_user_all(request, group_name):
    # Get the repository and add the user
    group = Group(group_name)
    group.load()
    users = group.member_list
    logger.debug(len(users))
    users_name = map(lambda foo: foo.__unicode__(), users)
    
    json_reply = json.dumps(users_name)
    return HttpResponse(json_reply)
예제 #6
0
def rest_group_user_all(request, group_name):
    # Get the repository and add the user
    group = Group(group_name)
    group.load()
    users = group.member_list
    logger.debug(len(users))
    users_name = map(lambda foo: foo.__unicode__(), users)

    json_reply = json.dumps(users_name)
    return HttpResponse(json_reply)
예제 #7
0
파일: views.py 프로젝트: craftyjon/gitstack
def add_group_user_dialog(request, group_name):
    # retrieve all the users
    user_list = UserApache.retrieve_all()
    # get the users already added to the repository
    group = Group(group_name)
    group.load()
    group_user_list = group.member_list
    
        
    # substract the repository users from the user list
    for group_user in group_user_list:
        if group_user in user_list:
            user_list.remove(group_user)
    everyone = UserFactory.instantiate_user('everyone')
    user_list.remove(everyone)
    return render_to_response('gitstack/add_group_user.html', {'group_name': group_name,
                                                              'user_list': user_list }, context_instance=RequestContext(request))
예제 #8
0
def rest_repo_group(request, repo_name, group_name):
    repo = Repository(repo_name)
    group = Group(group_name)

    # Add group
    if request.method == 'POST':
        # Get the repository and add the user
        repo.add_group(group)
        repo.add_group_read(group)
        repo.add_group_write(group)
        repo.save()
        return HttpResponse("User " + group_name + " added to " + repo_name)

    # Delete the group
    if request.method == 'DELETE':
        # Remove the group from the repository
        repo.remove_group(group)
        repo.save()
        return HttpResponse(group_name + " removed from " + repo_name)

    # Get the group permissions
    if request.method == 'GET':
        permissions = {'read': False, 'write': False}
        # retrieve the list of read and write users
        group_read_list = repo.group_read_list
        group_write_list = repo.group_write_list
        # check if the user has read and write access
        if group in group_read_list:
            permissions['read'] = True
        if group in group_write_list:
            permissions['write'] = True

        # reply with the json permission object
        json_reply = json.dumps(permissions)
        return HttpResponse(json_reply)

    if request.method == 'PUT':
        # retrieve the credentials from the json
        permissions = json.loads(request.raw_post_data)

        # Get the old password and new password
        if 'read' in permissions:
            # add the read permission to the repo
            if permissions['read']:
                repo.add_group_read(group)
            else:
                repo.remove_group_read(group)

        if 'write' in permissions:
            # add the write permission to the repo
            if permissions['write']:
                repo.add_group_write(group)
            else:
                repo.remove_group_write(group)

        repo.save()
        return HttpResponse(group_name + "'s permissions updated")
예제 #9
0
def add_group_user_dialog(request, group_name):
    # retrieve all the users
    user_list = UserApache.retrieve_all()
    # get the users already added to the repository
    group = Group(group_name)
    group.load()
    group_user_list = group.member_list

    # substract the repository users from the user list
    for group_user in group_user_list:
        if group_user in user_list:
            user_list.remove(group_user)
    everyone = UserFactory.instantiate_user('everyone')
    user_list.remove(everyone)
    return render_to_response('gitstack/add_group_user.html', {
        'group_name': group_name,
        'user_list': user_list
    },
                              context_instance=RequestContext(request))
예제 #10
0
def rest_group(request):
    try:
        # create a group
        if request.method == 'POST':
            # get the username/password from the request
            name = request.POST['name']
            group = Group(name)
            group.create()
            return HttpResponse("Group " + name + " has been successfully created." )
        
        # get retrieve_all the groups
        if request.method == 'GET':
            group_list = Group.retrieve_all()
            json_reply = jsonpickle.encode(group_list, unpicklable = False)

            return HttpResponse(json_reply)
        
    except Exception as e:
        return HttpResponseServerError(e)
예제 #11
0
파일: views.py 프로젝트: craftyjon/gitstack
def add_repo_group_dialog(request, repo_name):
    # retrieve all the users
    group_list = Group.retrieve_all()
    # get the users already added to the repository
    repository = Repository(repo_name)
    repository_group_list = repository.group_list
    
    # substract the repository groups from the group list
    for repository_group in repository_group_list:
        if repository_group in group_list:
            group_list.remove(repository_group)
    
    return render_to_response('gitstack/add_repo_group.html', {'repo_name': repo_name,
                                                              'group_list': group_list }, context_instance=RequestContext(request))
예제 #12
0
파일: tests.py 프로젝트: zhanggvi/gitstack
    def tearDown(self):
        # delete repos
        repositories = Repository.retrieve_all()
        for repo in repositories:
            repo.delete()

        # delete users
        os.remove(settings.INSTALL_DIR + '/data/passwdfile')

        # delete groups
        groups = Group.retrieve_all()
        for group in groups:
            # delete the group
            group.delete()

        # remove the settings.ini file from the filesystem
        os.remove(settings.SETTINGS_PATH)
예제 #13
0
def add_repo_group_dialog(request, repo_name):
    # retrieve all the users
    group_list = Group.retrieve_all()
    # get the users already added to the repository
    repository = Repository(repo_name)
    repository_group_list = repository.group_list

    # substract the repository groups from the group list
    for repository_group in repository_group_list:
        if repository_group in group_list:
            group_list.remove(repository_group)

    return render_to_response('gitstack/add_repo_group.html', {
        'repo_name': repo_name,
        'group_list': group_list
    },
                              context_instance=RequestContext(request))
예제 #14
0
파일: tests.py 프로젝트: 184686787/gitstack
    def tearDown(self):
        # delete repos
        repositories = Repository.retrieve_all()
        for repo in repositories:
            repo.delete()

        # delete users
        os.remove(settings.INSTALL_DIR + '/data/passwdfile')
          
        # delete groups
        groups = Group.retrieve_all()
        for group in groups:
            # delete the group
            group.delete()
            
        # remove the settings.ini file from the filesystem
        os.remove(settings.SETTINGS_PATH)
예제 #15
0
    def tearDown(self):
        # delete repos
        repositories = Repository.retrieve_all()
        for repo in repositories:
            repo.delete()

        # delete users
        users = UserApache.retrieve_all()
        for user in users:
            # delete the user
            if user.username != 'everyone':
                user.delete()
                time.sleep(0.1)
            
        # delete groups
        groups = Group.retrieve_all()
        for group in groups:
            # delete the group
            group.delete()
예제 #16
0
def rest_group_user(request, group_name, username):
    group = Group(group_name)
    group.load()
    user = UserFactory.instantiate_user(username)
    
    # Add member to the group
    if request.method == 'POST':
        group.add_user(user)
        group.save()
        return HttpResponse("User " + username + " added to " + group_name)

    # Remove a group member
    if request.method == 'DELETE':
        group.remove_user(user)
        group.save()
        return HttpResponse(username + " removed from " + group_name)
예제 #17
0
def rest_group_user(request, group_name, username):
    group = Group(group_name)
    group.load()
    user = UserFactory.instantiate_user(username)

    # Add member to the group
    if request.method == 'POST':
        try:
            group.add_user(user)
            group.save()
            return HttpResponse("User " + username + " added to " + group_name)
        except Exception as e:
            return HttpResponseServerError(e)

    # Remove a group member
    if request.method == 'DELETE':
        group.remove_user(user)
        group.save()
        return HttpResponse(username + " removed from " + group_name)