# HG changeset patch # User Milka Kuzminski # Date 2021-02-01 22:10:32 # Node ID 21211d2fdda2f9a68f2a190bc878f5f965eec58b # Parent 537039702c527ad456395d620a14d052ae2f5ebd pull-requests: fixed a case when template marker was used in description field. fixes #5652 diff --git a/rhodecode/apps/repository/tests/test_repo_pullrequests.py b/rhodecode/apps/repository/tests/test_repo_pullrequests.py --- a/rhodecode/apps/repository/tests/test_repo_pullrequests.py +++ b/rhodecode/apps/repository/tests/test_repo_pullrequests.py @@ -420,6 +420,27 @@ class TestPullrequestsView(object): assert pull_request.title == 'New title' assert pull_request.description == 'New description' + def test_edit_title_description(self, pr_util, csrf_token): + pull_request = pr_util.create_pull_request() + pull_request_id = pull_request.pull_request_id + + response = self.app.post( + route_path('pullrequest_update', + repo_name=pull_request.target_repo.repo_name, + pull_request_id=pull_request_id), + params={ + 'edit_pull_request': 'true', + 'title': 'New title {} {2} {foo}', + 'description': 'New description', + 'csrf_token': csrf_token}) + + assert_session_flash( + response, u'Pull request title & description updated.', + category='success') + + pull_request = PullRequest.get(pull_request_id) + assert pull_request.title_safe == 'New title {{}} {{2}} {{foo}}' + def test_edit_title_description_closed(self, pr_util, csrf_token): pull_request = pr_util.create_pull_request() pull_request_id = pull_request.pull_request_id diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -4220,6 +4220,12 @@ class _PullRequestBase(BaseModel): return True return False + @property + def title_safe(self): + return self.title\ + .replace('{', '{{')\ + .replace('}', '}}') + @hybrid_property def description_safe(self): from rhodecode.lib import helpers as h diff --git a/rhodecode/public/js/src/rhodecode/comments.js b/rhodecode/public/js/src/rhodecode/comments.js --- a/rhodecode/public/js/src/rhodecode/comments.js +++ b/rhodecode/public/js/src/rhodecode/comments.js @@ -1462,7 +1462,6 @@ var CommentsController = function() { var comment = $('#comment-'+commentId); var commentData = comment.data(); - console.log(commentData); if (commentData.commentInline) { var f_path = commentData.commentFPath; 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 @@ -14,7 +14,7 @@ data = { 'comment_type': comment_type, 'comment_id': comment_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'pr_id': pull_request.pull_request_id, 'mention_prefix': '[mention] ' if mention else '', } @@ -31,7 +31,6 @@ else: _('{mention_prefix}{user} left a {comment_type} on pull request !{pr_id}: "{pr_title}"').format(**data) %> - ${subject_template.format(**data) |n} @@ -47,7 +46,7 @@ data = { 'comment_type': comment_type, 'comment_id': comment_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'pr_id': pull_request.pull_request_id, 'source_ref_type': pull_request.source_ref_parts.type, 'source_ref_name': pull_request.source_ref_parts.name, @@ -99,7 +98,7 @@ data = { 'comment_id': comment_id, 'renderer_type': renderer_type or 'plain', - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'pr_id': pull_request.pull_request_id, 'status': status_change, 'source_ref_type': pull_request.source_ref_parts.type, 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 @@ -8,7 +8,7 @@ data = { 'user': '@'+h.person(user), 'pr_id': pull_request.pull_request_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, } if user_role == 'observer': @@ -26,7 +26,7 @@ else: data = { 'user': h.person(user), 'pr_id': pull_request.pull_request_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'source_ref_type': pull_request.source_ref_parts.type, 'source_ref_name': pull_request.source_ref_parts.name, 'target_ref_type': pull_request.target_ref_parts.type, @@ -66,7 +66,7 @@ data = { data = { 'user': h.person(user), 'pr_id': pull_request.pull_request_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'source_ref_type': pull_request.source_ref_parts.type, 'source_ref_name': pull_request.source_ref_parts.name, 'target_ref_type': pull_request.target_ref_parts.type, 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 @@ -8,7 +8,7 @@ data = { 'updating_user': '@'+h.person(updating_user), 'pr_id': pull_request.pull_request_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, } subject_template = email_pr_update_subject_template or _('{updating_user} updated pull request. !{pr_id}: "{pr_title}"') @@ -23,7 +23,7 @@ subject_template = email_pr_update_subje data = { 'updating_user': h.person(updating_user), 'pr_id': pull_request.pull_request_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'source_ref_type': pull_request.source_ref_parts.type, 'source_ref_name': pull_request.source_ref_parts.name, 'target_ref_type': pull_request.target_ref_parts.type, @@ -74,7 +74,7 @@ data = { data = { 'updating_user': h.person(updating_user), 'pr_id': pull_request.pull_request_id, - 'pr_title': pull_request.title, + 'pr_title': pull_request.title_safe, 'source_ref_type': pull_request.source_ref_parts.type, 'source_ref_name': pull_request.source_ref_parts.name, 'target_ref_type': pull_request.target_ref_parts.type, diff --git a/rhodecode/tests/lib/test_mako_emails.py b/rhodecode/tests/lib/test_mako_emails.py --- a/rhodecode/tests/lib/test_mako_emails.py +++ b/rhodecode/tests/lib/test_mako_emails.py @@ -27,6 +27,16 @@ from rhodecode.model.db import User, Pul from rhodecode.model.notification import EmailNotificationModel +@pytest.fixture() +def pr(): + def factory(ref): + return collections.namedtuple( + 'PullRequest', + 'pull_request_id, title, title_safe, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')\ + (200, 'Example Pull Request', 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch') + return factory + + def test_get_template_obj(app, request_stub): template = EmailNotificationModel().get_renderer( EmailNotificationModel.TYPE_TEST, request_stub) @@ -53,14 +63,10 @@ def test_render_email(app, http_host_onl @pytest.mark.parametrize('role', PullRequestReviewers.ROLES) -def test_render_pr_email(app, user_admin, role): +def test_render_pr_email(app, user_admin, role, pr): ref = collections.namedtuple( 'Ref', 'name, type')('fxies123', 'book') - - pr = collections.namedtuple('PullRequest', - 'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')( - 200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch') - + pr = pr(ref) source_repo = target_repo = collections.namedtuple( 'Repo', 'type, repo_name')('hg', 'pull_request_1') @@ -89,13 +95,11 @@ def test_render_pr_email(app, user_admin assert subject == '@test_admin (RhodeCode Admin) added you as observer to pull request. !200: "Example Pull Request"' -def test_render_pr_update_email(app, user_admin): +def test_render_pr_update_email(app, user_admin, pr): ref = collections.namedtuple( 'Ref', 'name, type')('fxies123', 'book') - pr = collections.namedtuple('PullRequest', - 'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')( - 200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch') + pr = pr(ref) source_repo = target_repo = collections.namedtuple( 'Repo', 'type, repo_name')('hg', 'pull_request_1') @@ -150,13 +154,11 @@ def test_render_pr_update_email(app, use EmailNotificationModel.TYPE_COMMIT_COMMENT, EmailNotificationModel.TYPE_PULL_REQUEST_COMMENT ]) -def test_render_comment_subject_no_newlines(app, mention, email_type): +def test_render_comment_subject_no_newlines(app, mention, email_type, pr): ref = collections.namedtuple( 'Ref', 'name, type')('fxies123', 'book') - pr = collections.namedtuple('PullRequest', - 'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')( - 200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch') + pr = pr(ref) source_repo = target_repo = collections.namedtuple( 'Repo', 'type, repo_name')('hg', 'pull_request_1')