From c5cf803462ef9509106712331acad11b56ba54b9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 08 2015 09:56:35 +0000 Subject: [PATCH 1/5] Expand the EditFileForm form to include the email address of the editor --- diff --git a/pagure/forms.py b/pagure/forms.py index 40b6260..87715d6 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -275,3 +275,18 @@ class EditFileForm(wtf.Form): 'Title', [wtforms.validators.Required()]) commit_message = wtforms.TextAreaField( 'Commit message', [wtforms.validators.optional()]) + email = wtforms.SelectField( + 'Email', [wtforms.validators.Required()], + choices=[(item, item) for item in []] + ) + + def __init__(self, *args, **kwargs): + """ Calls the default constructor with the normal argument but + uses the list of collection provided to fill the choices of the + drop-down list. + """ + super(EditFileForm, self).__init__(*args, **kwargs) + if 'emails' in kwargs: + self.email.choices = [ + (email.email, email.email) for email in kwargs['emails'] + ] From 8c7f7cb37541c6c2f0d19ba76c35596137e4576e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 08 2015 09:56:57 +0000 Subject: [PATCH 2/5] Update pagure.lib.git.update_file_in_git to ask for the editor's email --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 2250e91..59bc866 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -649,7 +649,7 @@ def add_file_to_git(repo, issue, ticketfolder, user, filename, filestream): return os.path.join('files', filename) -def update_file_in_git(repo, branch, filename, content, message, user): +def update_file_in_git(repo, branch, filename, content, message, user, email): ''' Update a specific file in the specified repository with the content given and commit the change under the user's name. @@ -703,7 +703,7 @@ def update_file_in_git(repo, branch, filename, content, message, user): # Author/commiter will always be this one author = pygit2.Signature( name=user.username, - email=user.email + email=email ) # Actually commit From 383b8e3e68dc9fdaef7f215067ab0b0db569dcc4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 08 2015 09:57:27 +0000 Subject: [PATCH 3/5] Adjust the edit_file to ask and forward the editor's email address --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index d86c4bf..dd9a8d5 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -1202,6 +1202,9 @@ def edit_file(repo, branchname, filename, username=None): 403, 'You are not allowed to change the settings for this project') + user = pagure.lib.search_user( + SESSION, username=flask.g.fas_user.username) + reponame = pagure.get_repo_path(repo) repo_obj = pygit2.Repository(reponame) @@ -1216,7 +1219,7 @@ def edit_file(repo, branchname, filename, username=None): else: flask.abort(400, 'Invalid branch specified') - form = pagure.forms.EditFileForm() + form = pagure.forms.EditFileForm(emails=user.emails) if form.validate_on_submit(): try: pagure.lib.git.update_file_in_git( @@ -1228,7 +1231,8 @@ def edit_file(repo, branchname, filename, username=None): form.commit_title.data.strip(), form.commit_message.data.strip() ), - user=flask.g.fas_user + user=flask.g.fas_user, + email=form.email.data, ) flask.flash('Changes committed') return flask.redirect( @@ -1260,4 +1264,5 @@ def edit_file(repo, branchname, filename, username=None): data=data, filename=filename, form=form, + user=user, ) From f7c1f25178a5ba079ce20eb76b3a0b8e503201f9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 08 2015 09:57:46 +0000 Subject: [PATCH 4/5] Adjust the edit_file template to allow specifying which email address to use --- diff --git a/pagure/templates/edit_file.html b/pagure/templates/edit_file.html index cb78ce5..ef0b84b 100644 --- a/pagure/templates/edit_file.html +++ b/pagure/templates/edit_file.html @@ -41,6 +41,17 @@
+ {{ user.username | avatar(24) | safe }} + {{ user.fullname }} + +
+
From badd09babd59997e8e7407f4b916b0b615d05fe9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 08 2015 10:00:44 +0000 Subject: [PATCH 5/5] Expand the unit-tests to enforce the presence of an email address when editing a file --- diff --git a/tests/test_progit_flask_ui_repo.py b/tests/test_progit_flask_ui_repo.py index 6e8a53f..6ca66b6 100644 --- a/tests/test_progit_flask_ui_repo.py +++ b/tests/test_progit_flask_ui_repo.py @@ -1657,8 +1657,21 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 200) self.assertEqual(output.data, 'foo\n bar') - # Works + # Missing email data['csrf_token'] = csrf_token + output = self.app.post('/test/edit/master/f/sources', data=data) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Edit - test - Pagure', output.data) + + # Invalid email + data['email'] = 'pingou@fp.o' + output = self.app.post('/test/edit/master/f/sources', data=data) + self.assertIn( + 'Edit - test - Pagure', output.data) + + # Works + data['email'] = 'bar@pingou.com' output = self.app.post( '/test/edit/master/f/sources', data=data, follow_redirects=True)