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))
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")