# HG changeset patch # User Marcin Kuzminski # Date 2020-07-16 10:37:52 # Node ID 824dc51fa2c0f3954efbcf127eb877947618f4d7 # Parent ae62a3cc1e550b766abc8169390fc439c3d351c8 emails: added logic to allow overwriting the default email titles via rcextensions. diff --git a/rhodecode/config/rcextensions/examples/custom_integration_templates.py b/rhodecode/config/rcextensions/examples/custom_integration_templates.py --- a/rhodecode/config/rcextensions/examples/custom_integration_templates.py +++ b/rhodecode/config/rcextensions/examples/custom_integration_templates.py @@ -1,5 +1,6 @@ -# This code allows override the integrations templates. -# Put this into the __init__.py file of rcextensions to override the templates +# Below code examples allows override the integrations templates, or email titles. +# Append selected parts at the end of the __init__.py file of rcextensions directory +# to override the templates # EMAIL Integration @@ -185,3 +186,18 @@ message: ``` ''') + + +# Example to modify emails default title +from rhodecode.model import notification + +notification.EMAIL_PR_UPDATE_SUBJECT_TEMPLATE = '{updating_user} updated pull request. !{pr_id}: "{pr_title}"' +notification.EMAIL_PR_REVIEW_SUBJECT_TEMPLATE = '{user} requested a pull request review. !{pr_id}: "{pr_title}"' + +notification.EMAIL_PR_COMMENT_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"' +notification.EMAIL_PR_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = '{mention_prefix}[status: {status}] {user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"' +notification.EMAIL_PR_COMMENT_FILE_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in pull request !{pr_id}: "{pr_title}"' + +notification.EMAIL_COMMENT_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on commit `{commit_id}`' +notification.EMAIL_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = '{mention_prefix}[status: {status}] {user} left a {comment_type} on commit `{commit_id}`' +notification.EMAIL_COMMENT_FILE_SUBJECT_TEMPLATE = '{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in commit `{commit_id}`' diff --git a/rhodecode/model/notification.py b/rhodecode/model/notification.py --- a/rhodecode/model/notification.py +++ b/rhodecode/model/notification.py @@ -295,6 +295,27 @@ class NotificationModel(BaseModel): } +# Templates for Titles, that could be overwritten by rcextensions +# Title of email for pull-request update +EMAIL_PR_UPDATE_SUBJECT_TEMPLATE = '' +# Title of email for request for pull request review +EMAIL_PR_REVIEW_SUBJECT_TEMPLATE = '' + +# Title of email for general comment on pull request +EMAIL_PR_COMMENT_SUBJECT_TEMPLATE = '' +# Title of email for general comment which includes status change on pull request +EMAIL_PR_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = '' +# Title of email for inline comment on a file in pull request +EMAIL_PR_COMMENT_FILE_SUBJECT_TEMPLATE = '' + +# Title of email for general comment on commit +EMAIL_COMMENT_SUBJECT_TEMPLATE = '' +# Title of email for general comment which includes status change on commit +EMAIL_COMMENT_STATUS_CHANGE_SUBJECT_TEMPLATE = '' +# Title of email for inline comment on a file in commit +EMAIL_COMMENT_FILE_SUBJECT_TEMPLATE = '' + + class EmailNotificationModel(BaseModel): TYPE_COMMIT_COMMENT = Notification.TYPE_CHANGESET_COMMENT TYPE_REGISTRATION = Notification.TYPE_REGISTRATION diff --git a/rhodecode/templates/email_templates/commit_comment.mako b/rhodecode/templates/email_templates/commit_comment.mako --- a/rhodecode/templates/email_templates/commit_comment.mako +++ b/rhodecode/templates/email_templates/commit_comment.mako @@ -17,19 +17,22 @@ data = { 'commit_id': h.show_id(commit), 'mention_prefix': '[mention] ' if mention else '', } + + +if comment_file: + subject_template = email_comment_file_subject_template or \ + _('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in commit `{commit_id}` in the `{repo_name}` repository').format(**data) +else: + if status_change: + subject_template = email_comment_status_change_subject_template or \ + _('{mention_prefix}[status: {status}] {user} left a {comment_type} on commit `{commit_id}` in the `{repo_name}` repository').format(**data) + else: + subject_template = email_comment_subject_template or \ + _('{mention_prefix}{user} left a {comment_type} on commit `{commit_id}` in the `{repo_name}` repository').format(**data) %> -% if comment_file: - ${_('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in commit `{commit_id}`').format(**data)} ${_('in the `{repo_name}` repository').format(**data) |n} -% else: - % if status_change: - ${_('{mention_prefix}[status: {status}] {user} left a {comment_type} on commit `{commit_id}`').format(**data) |n} ${_('in the `{repo_name}` repository').format(**data) |n} - % else: - ${_('{mention_prefix}{user} left a {comment_type} on commit `{commit_id}`').format(**data) |n} ${_('in the `{repo_name}` repository').format(**data) |n} - % endif -% endif - +${subject_template.format(**data) |n} ## PLAINTEXT VERSION OF BODY diff --git a/rhodecode/templates/email_templates/pull_request_comment.mako b/rhodecode/templates/email_templates/pull_request_comment.mako --- a/rhodecode/templates/email_templates/pull_request_comment.mako +++ b/rhodecode/templates/email_templates/pull_request_comment.mako @@ -18,19 +18,21 @@ data = { 'pr_id': pull_request.pull_request_id, 'mention_prefix': '[mention] ' if mention else '', } + +if comment_file: + subject_template = email_pr_comment_file_subject_template or \ + _('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in pull request !{pr_id}: "{pr_title}"').format(**data) +else: + if status_change: + subject_template = email_pr_comment_status_change_subject_template or \ + _('{mention_prefix}[status: {status}] {user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) + else: + subject_template = email_pr_comment_subject_template or \ + _('{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) %> -% if comment_file: - ${_('{mention_prefix}{user} left a {comment_type} on file `{comment_file}` in pull request !{pr_id}: "{pr_title}"').format(**data) |n} -% else: - % if status_change: - ${_('{mention_prefix}[status: {status}] {user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) |n} - % else: - ${_('{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) |n} - % endif -% endif - +${subject_template.format(**data) |n} ## PLAINTEXT VERSION OF BODY diff --git a/rhodecode/templates/email_templates/pull_request_review.mako b/rhodecode/templates/email_templates/pull_request_review.mako --- a/rhodecode/templates/email_templates/pull_request_review.mako +++ b/rhodecode/templates/email_templates/pull_request_review.mako @@ -10,9 +10,11 @@ data = { 'pr_id': pull_request.pull_request_id, 'pr_title': pull_request.title, } + +subject_template = email_pr_review_subject_template or _('{user} requested a pull request review. !{pr_id}: "{pr_title}"') %> -${_('{user} requested a pull request review. !{pr_id}: "{pr_title}"').format(**data) |n} +${subject_template.format(**data) |n} ## PLAINTEXT VERSION OF BODY diff --git a/rhodecode/templates/email_templates/pull_request_update.mako b/rhodecode/templates/email_templates/pull_request_update.mako --- a/rhodecode/templates/email_templates/pull_request_update.mako +++ b/rhodecode/templates/email_templates/pull_request_update.mako @@ -10,9 +10,11 @@ data = { 'pr_id': pull_request.pull_request_id, 'pr_title': pull_request.title, } + +subject_template = email_pr_update_subject_template or _('{updating_user} updated pull request. !{pr_id}: "{pr_title}"') %> -${_('{updating_user} updated pull request. !{pr_id}: "{pr_title}"').format(**data) |n} +${subject_template.format(**data) |n} ## PLAINTEXT VERSION OF BODY