From 8782bc31e2ca9b26f117f39b316ed60180748aa2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 24 2014 09:22:37 +0000 Subject: Add a new endpoint to add a new user to a project Which basically gives the specified user commit rights on the project directly --- diff --git a/progit/repo.py b/progit/repo.py index 0c423ef..61a4244 100644 --- a/progit/repo.py +++ b/progit/repo.py @@ -580,3 +580,39 @@ def delete_repo(repo, username=None): return flask.redirect( flask.url_for('view_user', username=flask.g.fas_user.username)) + + +@APP.route('//adduser', methods=('GET', 'POST')) +@APP.route('/fork///adduser', methods=('GET', 'POST')) +@cla_required +def add_user(repo, username=None): + """ Add the specified user from the project. + """ + repo = progit.lib.get_project(SESSION, repo, user=username) + + if not repo: + flask.abort(404, 'Project not found') + + if not is_repo_admin(repo): + flask.abort( + 403, + 'You are not allowed to change the settings for this project') + + form = progit.forms.AddUserForm() + + if form.validate_on_submit(): + msg = progit.lib.add_user_to_project(SESSION, repo, form.user.data) + + SESSION.commit() + + flask.flash(msg) + return flask.redirect( + flask.url_for('.view_settings', repo=repo.name, username=username) + ) + + return flask.render_template( + 'add_user.html', + form=form, + username=username, + repo=repo, + )