{"action":"created","comment":{"url":"https://api.github.com/repos/indico/indico/pulls/comments/80059694","id":80059694,"diff_hunk":"@@ -0,0 +1,127 @@\n+# This file is part of Indico.\n+# Copyright (C) 2002 - 2016 European Organization for Nuclear Research (CERN).\n+#\n+# Indico is free software; you can redistribute it and/or\n+# modify it under the terms of the GNU General Public License as\n+# published by the Free Software Foundation; either version 3 of the\n+# License, or (at your option) any later version.\n+#\n+# Indico is distributed in the hope that it will be useful, but\n+# WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+# General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with Indico; if not, see <http://www.gnu.org/licenses/>.\n+\n+from __future__ import unicode_literals\n+\n+from flask import request\n+\n+from indico.core.db import db\n+from indico.modules.events.abstracts.controllers.management import RHManageAbstractsBase\n+from indico.modules.events.abstracts.forms import (EditEmailTemplateRuleForm, EditEmailTemplateTextForm,\n+                                                   CreateEmailTemplateForm)\n+from indico.modules.events.abstracts.models.email_templates import AbstractEmailTemplate\n+from indico.modules.events.abstracts.util import build_default_email_template, create_mock_abstract\n+from indico.util.placeholders import replace_placeholders\n+from indico.web.flask.templating import get_template_module\n+from indico.web.util import jsonify_data, jsonify_template\n+\n+\n+class RHEmailTemplateList(RHManageAbstractsBase):\n+    \"\"\"Display list of e-mail templates.\"\"\"\n+\n+    def _process(self):\n+        return jsonify_template('events/abstracts/management/notification_tpl_list.html', event=self.event_new)\n+\n+\n+class RHAddEmailTemplate(RHManageAbstractsBase):\n+    \"\"\"Add a new e-mail template.\"\"\"\n+\n+    def _process(self):\n+        form = CreateEmailTemplateForm(event=self.event_new)\n+        if form.validate_on_submit():\n+            new_tpl = build_default_email_template(self.event_new, form.default_tpl.data)\n+            form.populate_obj(new_tpl)\n+            self.event_new.abstract_email_templates.append(new_tpl)\n+            db.session.flush()\n+\n+            tpl = get_template_module('events/abstracts/management/_notification_tpl_list.html')\n+            return jsonify_data(html=tpl.render_notification_list(self.event_new))\n+        return jsonify_template('events/abstracts/management/notification_tpl_form.html', form=form)\n+\n+\n+class RHEditEmailTemplateBase(RHManageAbstractsBase):\n+    \"\"\"Base class for operations that involve editing an e-mail template.\"\"\"\n+\n+    normalize_url_spec = {\n+        'locators': {\n+            lambda self: self.email_tpl\n+        }\n+    }\n+\n+    def _checkParams(self, params):\n+        RHManageAbstractsBase._checkParams(self, params)\n+        self.email_tpl = AbstractEmailTemplate.get_one(request.view_args['email_tpl_id'])\n+\n+\n+class RHEditEmailTemplateRules(RHEditEmailTemplateBase):\n+    \"\"\"Edit the rules of a notification template.\"\"\"\n+\n+    def _process(self):\n+        form = EditEmailTemplateRuleForm(obj=self.email_tpl, event=self.event_new)\n+        if form.validate_on_submit():\n+            form.populate_obj(self.email_tpl)\n+            tpl = get_template_module('events/abstracts/management/_notification_tpl_list.html')\n+            return jsonify_data(html=tpl.render_notification_list(self.event_new))\n+        return jsonify_template('events/abstracts/management/notification_tpl_form.html',\n+                                form=form, is_edit=True)\n+\n+\n+class RHEditEmailTemplateText(RHEditEmailTemplateBase):\n+    \"\"\"Edit the e-mail text of a notification template.\"\"\"\n+\n+    def _process(self):\n+        form = EditEmailTemplateTextForm(obj=self.email_tpl, event=self.event_new)\n+        if form.validate_on_submit():\n+            form.populate_obj(self.email_tpl)\n+            tpl = get_template_module('events/abstracts/management/_notification_tpl_list.html')\n+            return jsonify_data(html=tpl.render_notification_list(self.event_new))\n+        return jsonify_template('events/abstracts/management/notification_tpl_text_form.html',\n+                                form=form, is_edit=True)\n+\n+\n+class RHSortEmailTemplates(RHManageAbstractsBase):\n+    \"\"\"Sort e-mail templates according to the order provided by the client.\"\"\"\n+\n+    def _process(self):\n+        new_order = [AbstractEmailTemplate.get(tpl_id) for tpl_id in request.json['sort_order']]\n+        if set(new_order) != set(self.event_new.abstract_email_templates):\n+            raise ValueError('Sorted and stored lists have different contents.')\n+        for position, tpl in enumerate(new_order):\n+            tpl.position = position\n+        return jsonify_data()\n+\n+\n+class RHDeleteEmailTemplate(RHEditEmailTemplateBase):\n+    \"\"\"Delete an e-mail template.\"\"\"\n+\n+    def _process(self):\n+        db.session.delete(self.email_tpl)\n+        tpl = get_template_module('events/abstracts/management/_notification_tpl_list.html')\n+        return jsonify_data(html=tpl.render_notification_list(self.event_new),\n+                            flash=False)","path":"indico/modules/events/abstracts/controllers/email_templates.py","position":114,"original_position":114,"commit_id":"3c65abf81ae2a3a4d21a31ea92de57a6a8cf23ad","original_commit_id":"3c65abf81ae2a3a4d21a31ea92de57a6a8cf23ad","user":{"login":"ThiefMaster","id":179599,"avatar_url":"https://avatars.githubusercontent.com/u/179599?v=3","gravatar_id":"","url":"https://api.github.com/users/ThiefMaster","html_url":"https://github.com/ThiefMaster","followers_url":"https://api.github.com/users/ThiefMaster/followers","following_url":"https://api.github.com/users/ThiefMaster/following{/other_user}","gists_url":"https://api.github.com/users/ThiefMaster/gists{/gist_id}","starred_url":"https://api.github.com/users/ThiefMaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThiefMaster/subscriptions","organizations_url":"https://api.github.com/users/ThiefMaster/orgs","repos_url":"https://api.github.com/users/ThiefMaster/repos","events_url":"https://api.github.com/users/ThiefMaster/events{/privacy}","received_events_url":"https://api.github.com/users/ThiefMaster/received_events","type":"User","site_admin":false},"body":"fits in the same line now that `render_notification_list` takes only one argument","created_at":"2016-09-22T14:55:43Z","updated_at":"2016-09-22T14:55:43Z","html_url":"https://github.com/indico/indico/pull/2595#discussion_r80059694","pull_request_url":"https://api.github.com/repos/indico/indico/pulls/2595","_links":{"self":{"href":"https://api.github.com/repos/indico/indico/pulls/comments/80059694"},"html":{"href":"https://github.com/indico/indico/pull/2595#discussion_r80059694"},"pull_request":{"href":"https://api.github.com/repos/indico/indico/pulls/2595"}}},"pull_request":{"url":"https://api.github.com/repos/indico/indico/pulls/2595","id":84298449,"html_url":"https://github.com/indico/indico/pull/2595","diff_url":"https://github.com/indico/indico/pull/2595.diff","patch_url":"https://github.com/indico/indico/pull/2595.patch","issue_url":"https://api.github.com/repos/indico/indico/issues/2595","number":2595,"state":"open","locked":false,"title":"Notification e-mails","user":{"login":"pferreir","id":2699,"avatar_url":"https://avatars.githubusercontent.com/u/2699?v=3","gravatar_id":"","url":"https://api.github.com/users/pferreir","html_url":"https://github.com/pferreir","followers_url":"https://api.github.com/users/pferreir/followers","following_url":"https://api.github.com/users/pferreir/following{/other_user}","gists_url":"https://api.github.com/users/pferreir/gists{/gist_id}","starred_url":"https://api.github.com/users/pferreir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pferreir/subscriptions","organizations_url":"https://api.github.com/users/pferreir/orgs","repos_url":"https://api.github.com/users/pferreir/repos","events_url":"https://api.github.com/users/pferreir/events{/privacy}","received_events_url":"https://api.github.com/users/pferreir/received_events","type":"User","site_admin":false},"body":"Things missing:\r\n * [x] UI to change the order of templates\r\n * [x] Unit tests\r\n * [x] Actually sending e-mails from within the `send_abstract_notifications` function\r\n * [x] Handling different \"types\" of Contribution Type and Track - e.g. when `state == merged` we shouldn't take into account `accepted_contrib_type_id`, since it hasn't been accepted.\r\n\r\nStuff we should do later:\r\n * [ ] Actually invoking `send_abstract_notifications` when required\r\n * [ ] Printing a warning somewhere in case there is a misspelled placeholder","created_at":"2016-09-07T13:19:19Z","updated_at":"2016-09-22T14:55:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7a54b31487310f47b8c9777a8ac41129eb6f209","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/indico/indico/pulls/2595/commits","review_comments_url":"https://api.github.com/repos/indico/indico/pulls/2595/comments","review_comment_url":"https://api.github.com/repos/indico/indico/pulls/comments{/number}","comments_url":"https://api.github.com/repos/indico/indico/issues/2595/comments","statuses_url":"https://api.github.com/repos/indico/indico/statuses/3c65abf81ae2a3a4d21a31ea92de57a6a8cf23ad","head":{"label":"pferreir:wip/notification-emails","ref":"wip/notification-emails","sha":"3c65abf81ae2a3a4d21a31ea92de57a6a8cf23ad","user":{"login":"pferreir","id":2699,"avatar_url":"https://avatars.githubusercontent.com/u/2699?v=3","gravatar_id":"","url":"https://api.github.com/users/pferreir","html_url":"https://github.com/pferreir","followers_url":"https://api.github.com/users/pferreir/followers","following_url":"https://api.github.com/users/pferreir/following{/other_user}","gists_url":"https://api.github.com/users/pferreir/gists{/gist_id}","starred_url":"https://api.github.com/users/pferreir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pferreir/subscriptions","organizations_url":"https://api.github.com/users/pferreir/orgs","repos_url":"https://api.github.com/users/pferreir/repos","events_url":"https://api.github.com/users/pferreir/events{/privacy}","received_events_url":"https://api.github.com/users/pferreir/received_events","type":"User","site_admin":false},"repo":{"id":3867135,"name":"indico","full_name":"pferreir/indico","owner":{"login":"pferreir","id":2699,"avatar_url":"https://avatars.githubusercontent.com/u/2699?v=3","gravatar_id":"","url":"https://api.github.com/users/pferreir","html_url":"https://github.com/pferreir","followers_url":"https://api.github.com/users/pferreir/followers","following_url":"https://api.github.com/users/pferreir/following{/other_user}","gists_url":"https://api.github.com/users/pferreir/gists{/gist_id}","starred_url":"https://api.github.com/users/pferreir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pferreir/subscriptions","organizations_url":"https://api.github.com/users/pferreir/orgs","repos_url":"https://api.github.com/users/pferreir/repos","events_url":"https://api.github.com/users/pferreir/events{/privacy}","received_events_url":"https://api.github.com/users/pferreir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pferreir/indico","description":"The Indico Project (mirror)","fork":true,"url":"https://api.github.com/repos/pferreir/indico","forks_url":"https://api.github.com/repos/pferreir/indico/forks","keys_url":"https://api.github.com/repos/pferreir/indico/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pferreir/indico/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pferreir/indico/teams","hooks_url":"https://api.github.com/repos/pferreir/indico/hooks","issue_events_url":"https://api.github.com/repos/pferreir/indico/issues/events{/number}","events_url":"https://api.github.com/repos/pferreir/indico/events","assignees_url":"https://api.github.com/repos/pferreir/indico/assignees{/user}","branches_url":"https://api.github.com/repos/pferreir/indico/branches{/branch}","tags_url":"https://api.github.com/repos/pferreir/indico/tags","blobs_url":"https://api.github.com/repos/pferreir/indico/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pferreir/indico/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pferreir/indico/git/refs{/sha}","trees_url":"https://api.github.com/repos/pferreir/indico/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pferreir/indico/statuses/{sha}","languages_url":"https://api.github.com/repos/pferreir/indico/languages","stargazers_url":"https://api.github.com/repos/pferreir/indico/stargazers","contributors_url":"https://api.github.com/repos/pferreir/indico/contributors","subscribers_url":"https://api.github.com/repos/pferreir/indico/subscribers","subscription_url":"https://api.github.com/repos/pferreir/indico/subscription","commits_url":"https://api.github.com/repos/pferreir/indico/commits{/sha}","git_commits_url":"https://api.github.com/repos/pferreir/indico/git/commits{/sha}","comments_url":"https://api.github.com/repos/pferreir/indico/comments{/number}","issue_comment_url":"https://api.github.com/repos/pferreir/indico/issues/comments{/number}","contents_url":"https://api.github.com/repos/pferreir/indico/contents/{+path}","compare_url":"https://api.github.com/repos/pferreir/indico/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pferreir/indico/merges","archive_url":"https://api.github.com/repos/pferreir/indico/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pferreir/indico/downloads","issues_url":"https://api.github.com/repos/pferreir/indico/issues{/number}","pulls_url":"https://api.github.com/repos/pferreir/indico/pulls{/number}","milestones_url":"https://api.github.com/repos/pferreir/indico/milestones{/number}","notifications_url":"https://api.github.com/repos/pferreir/indico/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pferreir/indico/labels{/name}","releases_url":"https://api.github.com/repos/pferreir/indico/releases{/id}","deployments_url":"https://api.github.com/repos/pferreir/indico/deployments","created_at":"2012-03-29T15:01:36Z","updated_at":"2015-05-04T14:44:08Z","pushed_at":"2016-09-22T14:40:19Z","git_url":"git://github.com/pferreir/indico.git","ssh_url":"git@github.com:pferreir/indico.git","clone_url":"https://github.com/pferreir/indico.git","svn_url":"https://github.com/pferreir/indico","homepage":"http://indico-software.org","size":192366,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"indico:devel","ref":"devel","sha":"85e319134af6fb91fd3e1ca57c281eca3143b55d","user":{"login":"indico","id":715236,"avatar_url":"https://avatars.githubusercontent.com/u/715236?v=3","gravatar_id":"","url":"https://api.github.com/users/indico","html_url":"https://github.com/indico","followers_url":"https://api.github.com/users/indico/followers","following_url":"https://api.github.com/users/indico/following{/other_user}","gists_url":"https://api.github.com/users/indico/gists{/gist_id}","starred_url":"https://api.github.com/users/indico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indico/subscriptions","organizations_url":"https://api.github.com/users/indico/orgs","repos_url":"https://api.github.com/users/indico/repos","events_url":"https://api.github.com/users/indico/events{/privacy}","received_events_url":"https://api.github.com/users/indico/received_events","type":"Organization","site_admin":false},"repo":{"id":2113067,"name":"indico","full_name":"indico/indico","owner":{"login":"indico","id":715236,"avatar_url":"https://avatars.githubusercontent.com/u/715236?v=3","gravatar_id":"","url":"https://api.github.com/users/indico","html_url":"https://github.com/indico","followers_url":"https://api.github.com/users/indico/followers","following_url":"https://api.github.com/users/indico/following{/other_user}","gists_url":"https://api.github.com/users/indico/gists{/gist_id}","starred_url":"https://api.github.com/users/indico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indico/subscriptions","organizations_url":"https://api.github.com/users/indico/orgs","repos_url":"https://api.github.com/users/indico/repos","events_url":"https://api.github.com/users/indico/events{/privacy}","received_events_url":"https://api.github.com/users/indico/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/indico/indico","description":"The Indico Project","fork":false,"url":"https://api.github.com/repos/indico/indico","forks_url":"https://api.github.com/repos/indico/indico/forks","keys_url":"https://api.github.com/repos/indico/indico/keys{/key_id}","collaborators_url":"https://api.github.com/repos/indico/indico/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/indico/indico/teams","hooks_url":"https://api.github.com/repos/indico/indico/hooks","issue_events_url":"https://api.github.com/repos/indico/indico/issues/events{/number}","events_url":"https://api.github.com/repos/indico/indico/events","assignees_url":"https://api.github.com/repos/indico/indico/assignees{/user}","branches_url":"https://api.github.com/repos/indico/indico/branches{/branch}","tags_url":"https://api.github.com/repos/indico/indico/tags","blobs_url":"https://api.github.com/repos/indico/indico/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/indico/indico/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/indico/indico/git/refs{/sha}","trees_url":"https://api.github.com/repos/indico/indico/git/trees{/sha}","statuses_url":"https://api.github.com/repos/indico/indico/statuses/{sha}","languages_url":"https://api.github.com/repos/indico/indico/languages","stargazers_url":"https://api.github.com/repos/indico/indico/stargazers","contributors_url":"https://api.github.com/repos/indico/indico/contributors","subscribers_url":"https://api.github.com/repos/indico/indico/subscribers","subscription_url":"https://api.github.com/repos/indico/indico/subscription","commits_url":"https://api.github.com/repos/indico/indico/commits{/sha}","git_commits_url":"https://api.github.com/repos/indico/indico/git/commits{/sha}","comments_url":"https://api.github.com/repos/indico/indico/comments{/number}","issue_comment_url":"https://api.github.com/repos/indico/indico/issues/comments{/number}","contents_url":"https://api.github.com/repos/indico/indico/contents/{+path}","compare_url":"https://api.github.com/repos/indico/indico/compare/{base}...{head}","merges_url":"https://api.github.com/repos/indico/indico/merges","archive_url":"https://api.github.com/repos/indico/indico/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/indico/indico/downloads","issues_url":"https://api.github.com/repos/indico/indico/issues{/number}","pulls_url":"https://api.github.com/repos/indico/indico/pulls{/number}","milestones_url":"https://api.github.com/repos/indico/indico/milestones{/number}","notifications_url":"https://api.github.com/repos/indico/indico/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/indico/indico/labels{/name}","releases_url":"https://api.github.com/repos/indico/indico/releases{/id}","deployments_url":"https://api.github.com/repos/indico/indico/deployments","created_at":"2011-07-27T13:56:30Z","updated_at":"2016-09-09T15:50:20Z","pushed_at":"2016-09-22T14:40:20Z","git_url":"git://github.com/indico/indico.git","ssh_url":"git@github.com:indico/indico.git","clone_url":"https://github.com/indico/indico.git","svn_url":"https://github.com/indico/indico","homepage":"http://indico-software.org","size":202699,"stargazers_count":164,"watchers_count":164,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":81,"mirror_url":null,"open_issues_count":622,"forks":81,"open_issues":622,"watchers":164,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/indico/indico/pulls/2595"},"html":{"href":"https://github.com/indico/indico/pull/2595"},"issue":{"href":"https://api.github.com/repos/indico/indico/issues/2595"},"comments":{"href":"https://api.github.com/repos/indico/indico/issues/2595/comments"},"review_comments":{"href":"https://api.github.com/repos/indico/indico/pulls/2595/comments"},"review_comment":{"href":"https://api.github.com/repos/indico/indico/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/indico/indico/pulls/2595/commits"},"statuses":{"href":"https://api.github.com/repos/indico/indico/statuses/3c65abf81ae2a3a4d21a31ea92de57a6a8cf23ad"}}}}
{"actor":{"display_login":"ThiefMaster"}}