示例#1
0
def rest_user(request):
    try:
        # create user
        if request.method == 'POST':
            # get the username/password from the request
            username = request.POST['username']
            password = request.POST['password']
            user = UserFactory.instantiate_user(username, password)
            user.create()
            return HttpResponse("User created")
        # get retrieve_all the users
        if request.method == 'GET':
            # convert list of objects to list of strings
            user_list_str = []
            user_list_obj = UserFactory.instantiate_user('').retrieve_all()
            for user in user_list_obj:   
                user_list_str.append(user.username)
            json_reply = json.dumps(user_list_str)
            return HttpResponse(json_reply)
        # update the user
        if request.method == 'PUT':
            # retrieve the credentials from the json
            credentials = json.loads(request.raw_post_data)
            # create an instance of the user and update it
            user = UserFactory.instantiate_user(credentials['username'], credentials['password'])
            user.update()
            return HttpResponse("User successfully updated")
        
    except Exception as e:
        return HttpResponseServerError(e)
示例#2
0
文件: views.py 项目: ghusse/gitstack
def rest_repo_user(request, repo_name, username):
    repo = Repository(repo_name)
    user = UserFactory.instantiate_user(username)

    # Add user
    if request.method == 'POST':
        try:
            # Get the repository and add the user
            repo.add_user(user)
            repo.add_user_read(user)
            repo.add_user_write(user)
            repo.save()
            return HttpResponse("User " + username + " added to " + repo_name)
        except Exception as e:
            return HttpResponseServerError(e)
    # Delete the user
    if request.method == 'DELETE':
        # Remove the user from the repository
        repo.remove_user(user)
        repo.save()
        return HttpResponse(username + " removed from " + repo_name)
    # Get the user permissions
    if request.method == 'GET':
        permissions = {'read' : False, 'write' : False}
        # retrieve the list of read and write users
        user_read_list = repo.user_read_list
        user_write_list = repo.user_write_list
        # check if the user has read and write access
        if user in user_read_list:
            permissions['read'] = True
        if user in user_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_user_read(user)
            else:
                repo.remove_user_read(user)

        if 'write' in permissions:
            # add the write permission to the repo
            if permissions['write']:
                repo.add_user_write(user)
            else:
                repo.remove_user_write(user)
                
        repo.save()
        return HttpResponse(user.username + "'s permissions updated")
示例#3
0
def rest_user_action(request, username):
    try:
        if request.method == 'DELETE':
            # retrieve the username from the json
            user = UserFactory.instantiate_user(username)
            # delete the user
            user.delete()
            return HttpResponse(username + " has been deleted")
    except Exception as e:
        return HttpResponseServerError(e)
示例#4
0
def rest_user_action(request, username):
    try:
        if request.method == 'DELETE':
            # retrieve the username from the json
            user = UserFactory.instantiate_user(username)
            # delete the user
            user.delete()
            return HttpResponse(username + " has been deleted")
    except Exception as e:
        return HttpResponseServerError(e)
示例#5
0
def rest_user(request):
    try:
        # create user
        if request.method == 'POST':
            username = request.POST['username']
            password = request.POST['password']

            # get the username/password from the request
            # check the username
            matcher = re.compile("^[A-Za-z]\w{2,}$")
            if matcher.match(username) is None:
                raise Exception(
                    "Please enter an alphanumeric name without spaces")
            if (username == ""):
                raise Exception("Please enter a non empty name")

            user = UserFactory.instantiate_user(username, password)
            user.create()
            return HttpResponse("User created")
        # get retrieve_all the users
        if request.method == 'GET':
            # convert list of objects to list of strings
            user_list_str = []
            user_list_obj = UserFactory.instantiate_user('').retrieve_all()
            for user in user_list_obj:
                user_list_str.append(user.username)
            json_reply = json.dumps(user_list_str)
            return HttpResponse(json_reply)
        # update the user
        if request.method == 'PUT':
            # retrieve the credentials from the json
            credentials = json.loads(request.raw_post_data)
            # create an instance of the user and update it
            user = UserFactory.instantiate_user(credentials['username'],
                                                credentials['password'])
            user.update()
            return HttpResponse("User successfully updated")

    except Exception as e:
        return HttpResponseServerError(e)
示例#6
0
def add_repo_user_dialog(request, repo_name):
    # retrieve all the users
    user_list = UserFactory.instantiate_user('').retrieve_all()
    # get the users already added to the repository
    repository = Repository(repo_name)
    repository_user_list = repository.user_list
    
    # substract the repository users from the user list
    for repository_user in repository_user_list:
        user_list.remove(repository_user)
    
    return render_to_response('gitstack/add_repo_user.html', {'repo_name': repo_name,
                                                              'user_list': user_list }, context_instance=RequestContext(request))
示例#7
0
文件: views.py 项目: ghusse/gitstack
def rest_user(request):
    try:
        # create user
        if request.method == 'POST':
            username = request.POST['username']
            password = request.POST['password']
            
            # get the username/password from the request
            # check the username
            matcher = re.compile("^[A-Za-z]\w{2,}$")
            if matcher.match(username) is None:
                raise Exception("Please enter an alphanumeric name without spaces")
            if(username == ""):
                raise Exception("Please enter a non empty name")
            
            user = UserFactory.instantiate_user(username, password)
            user.create()
            return HttpResponse("User created")
        # get retrieve_all the users
        if request.method == 'GET':
            # convert list of objects to list of strings
            user_list_str = []
            user_list_obj = UserFactory.instantiate_user('').retrieve_all()
            for user in user_list_obj:   
                user_list_str.append(user.username)
            json_reply = json.dumps(user_list_str)
            return HttpResponse(json_reply)
        # update the user
        if request.method == 'PUT':
            # retrieve the credentials from the json
            credentials = json.loads(request.raw_post_data)
            # create an instance of the user and update it
            user = UserFactory.instantiate_user(credentials['username'], credentials['password'])
            user.update()
            return HttpResponse("User successfully updated")
        
    except Exception as e:
        return HttpResponseServerError(e)
示例#8
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)
示例#9
0
def add_repo_user_dialog(request, repo_name):
    # retrieve all the users
    user_list = UserFactory.instantiate_user('').retrieve_all()
    # get the users already added to the repository
    repository = Repository(repo_name)
    repository_user_list = repository.user_list

    # substract the repository users from the user list
    for repository_user in repository_user_list:
        user_list.remove(repository_user)

    return render_to_response('gitstack/add_repo_user.html', {
        'repo_name': repo_name,
        'user_list': user_list
    },
                              context_instance=RequestContext(request))
示例#10
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))
示例#11
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)
示例#12
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))
示例#13
0
def rest_repo_user(request, repo_name, username):
    repo = Repository(repo_name)
    user = UserFactory.instantiate_user(username)

    # Add user
    if request.method == 'POST':
        try:
            # Get the repository and add the user
            repo.add_user(user)
            repo.add_user_read(user)
            repo.add_user_write(user)
            repo.save()
            return HttpResponse("User " + username + " added to " + repo_name)
        except Exception as e:
            return HttpResponseServerError(e)
    # Delete the user
    if request.method == 'DELETE':
        try:
            # Remove the user from the repository
            repo.remove_user(user)
            repo.save()
            return HttpResponse(username + " removed from " + repo_name)
        except Exception as e:
            return HttpResponseServerError(e)
    # Get the user permissions
    if request.method == 'GET':
        permissions = {'read': False, 'write': False}
        # retrieve the list of read and write users
        user_read_list = repo.user_read_list
        user_write_list = repo.user_write_list
        # check if the user has read and write access
        if user in user_read_list:
            permissions['read'] = True
        if user in user_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_user_read(user)
            else:
                repo.remove_user_read(user)

        if 'write' in permissions:
            # add the write permission to the repo
            if permissions['write']:
                repo.add_user_write(user)
            else:
                repo.remove_user_write(user)

        repo.save()
        return HttpResponse(user.username + "'s permissions updated")