From 9871f9beb0d8336a65d28454acd85918188d0af7 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Dec 01 2016 11:12:12 +0000 Subject: Add settings block for editing quick replies --- diff --git a/pagure/templates/settings.html b/pagure/templates/settings.html index c9bc445..071017f 100644 --- a/pagure/templates/settings.html +++ b/pagure/templates/settings.html @@ -791,6 +791,63 @@ {% endif %} + {% if (config.get('ENABLE_TICKETS', True) + and repo.settings.get('issue_tracker', True)) + or repo.settings.get('pull_requests', True) %} +
+
+
+ Quick replies +
+
+

Quick replies will be offered in a new comment form on Issue or + Pull Request page. This allows you to reply to common probles with a + click of a button.

+

The reply can use the same Markdown formatting as regular + comments. The list you will choose the reply from will only show the + first 50 characters. Please make sure the important message is at the + beginning.

+

The replies will be presented in the same order they are written + here.

+
+
+ {{ tag_form.csrf_token }} +
+
+ {% for quick_reply in repo.quick_replies %} +
+
+ +
+
+ {% endfor %} +
+ +
+
+ +
+
+
+
+
+
+ {% endif %} + {% if config.get('ENABLE_DEL_PROJECTS', True) %}
@@ -939,6 +996,17 @@ $('#new_close_status').click(function(e) { ); }); +$('#new_quick_reply').click(function(e) { + console.log('new quick reply'); + $('#quick_reply_list').append( + '
\ +
\ + \ +
\ +
' + ); +}); + $('#new_custom_field').click(function(e) { console.log('new custom fields'); $('#custom_fields').append( diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 8d964a9..2e2c676 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -2157,6 +2157,58 @@ def update_close_status(repo, username=None, namespace=None): namespace=namespace)) +@APP.route('//update/quick_replies', methods=['POST']) +@APP.route('///update/quick_replies', methods=['POST']) +@APP.route('/fork///update/quick_replies', methods=['POST']) +@APP.route( + '/fork////update/quick_replies', + methods=['POST']) +@login_required +def update_quick_replies(repo, username=None, namespace=None): + """ Update the quick_replies of a project. + """ + if admin_session_timedout(): + flask.flash('Action canceled, try it again', 'error') + url = flask.url_for( + 'view_settings', username=username, repo=repo, + namespace=namespace) + return flask.redirect( + flask.url_for('auth_login', next=url)) + + repo = flask.g.repo + + if (not repo.settings.get('issue_tracker', True) and + not repo.settings.get('pull_requests', True)): + flask.abort( + 404, + 'Issue tracker and pull requests are disabled for this project') + + if not flask.g.repo_admin: + flask.abort( + 403, + 'You are not allowed to change the settings for this project') + + form = pagure.forms.ConfirmationForm() + + if form.validate_on_submit(): + quick_replies = [ + w.strip() for w in flask.request.form.getlist('quick_reply') + if w.strip() + ] + try: + repo.quick_replies = quick_replies + SESSION.add(repo) + SESSION.commit() + flask.flash('List of quick replies updated') + except SQLAlchemyError as err: # pragma: no cover + SESSION.rollback() + flask.flash(str(err), 'error') + + return flask.redirect(flask.url_for( + 'view_settings', username=username, repo=repo.name, + namespace=namespace)) + + @APP.route('//update/custom_keys', methods=['POST']) @APP.route('///update/custom_keys', methods=['POST']) @APP.route('/fork///update/custom_keys', methods=['POST'])