Show More
@@ -20,7 +20,7 b'' | |||
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | 22 | |
|
23 | from rhodecode.model.db import ChangesetStatus | |
|
23 | from rhodecode.model.db import ChangesetStatus, User | |
|
24 | 24 | from rhodecode.api.tests.utils import ( |
|
25 | 25 | build_data, api_call, assert_error, assert_ok) |
|
26 | 26 | |
@@ -79,3 +79,38 b' class TestCommentCommit(object):' | |||
|
79 | 79 | 'success': True |
|
80 | 80 | } |
|
81 | 81 | assert_ok(id_, expected, given=response.body) |
|
82 | ||
|
83 | def test_api_comment_commit_with_extra_recipients(self, backend, user_util): | |
|
84 | ||
|
85 | commit_id = backend.repo.scm_instance().get_commit('tip').raw_id | |
|
86 | ||
|
87 | user1 = user_util.create_user() | |
|
88 | user1_id = user1.user_id | |
|
89 | user2 = user_util.create_user() | |
|
90 | user2_id = user2.user_id | |
|
91 | ||
|
92 | id_, params = build_data( | |
|
93 | self.apikey, 'comment_commit', repoid=backend.repo_name, | |
|
94 | commit_id=commit_id, | |
|
95 | message='abracadabra', | |
|
96 | extra_recipients=[user1.user_id, user2.username]) | |
|
97 | ||
|
98 | response = api_call(self.app, params) | |
|
99 | repo = backend.repo.scm_instance() | |
|
100 | ||
|
101 | expected = { | |
|
102 | 'msg': 'Commented on commit `%s` for repository `%s`' % ( | |
|
103 | repo.get_commit().raw_id, backend.repo_name), | |
|
104 | 'status_change': None, | |
|
105 | 'success': True | |
|
106 | } | |
|
107 | ||
|
108 | assert_ok(id_, expected, given=response.body) | |
|
109 | # check user1/user2 inbox for notification | |
|
110 | user1 = User.get(user1_id) | |
|
111 | assert 1 == len(user1.notifications) | |
|
112 | assert 'abracadabra' in user1.notifications[0].notification.body | |
|
113 | ||
|
114 | user2 = User.get(user2_id) | |
|
115 | assert 1 == len(user2.notifications) | |
|
116 | assert 'abracadabra' in user2.notifications[0].notification.body |
@@ -21,7 +21,7 b'' | |||
|
21 | 21 | import pytest |
|
22 | 22 | |
|
23 | 23 | from rhodecode.model.comment import CommentsModel |
|
24 | from rhodecode.model.db import UserLog | |
|
24 | from rhodecode.model.db import UserLog, User | |
|
25 | 25 | from rhodecode.model.pull_request import PullRequestModel |
|
26 | 26 | from rhodecode.tests import TEST_USER_ADMIN_LOGIN |
|
27 | 27 | from rhodecode.api.tests.utils import ( |
@@ -70,6 +70,43 b' class TestCommentPullRequest(object):' | |||
|
70 | 70 | assert journal[-1].action == 'repo.pull_request.comment.create' |
|
71 | 71 | |
|
72 | 72 | @pytest.mark.backends("git", "hg") |
|
73 | def test_api_comment_pull_request_with_extra_recipients(self, pr_util, user_util): | |
|
74 | pull_request = pr_util.create_pull_request() | |
|
75 | ||
|
76 | user1 = user_util.create_user() | |
|
77 | user1_id = user1.user_id | |
|
78 | user2 = user_util.create_user() | |
|
79 | user2_id = user2.user_id | |
|
80 | ||
|
81 | id_, params = build_data( | |
|
82 | self.apikey, 'comment_pull_request', | |
|
83 | repoid=pull_request.target_repo.repo_name, | |
|
84 | pullrequestid=pull_request.pull_request_id, | |
|
85 | message='test message', | |
|
86 | extra_recipients=[user1.user_id, user2.username] | |
|
87 | ) | |
|
88 | response = api_call(self.app, params) | |
|
89 | pull_request = PullRequestModel().get(pull_request.pull_request_id) | |
|
90 | ||
|
91 | comments = CommentsModel().get_comments( | |
|
92 | pull_request.target_repo.repo_id, pull_request=pull_request) | |
|
93 | ||
|
94 | expected = { | |
|
95 | 'pull_request_id': pull_request.pull_request_id, | |
|
96 | 'comment_id': comments[-1].comment_id, | |
|
97 | 'status': {'given': None, 'was_changed': None} | |
|
98 | } | |
|
99 | assert_ok(id_, expected, response.body) | |
|
100 | # check user1/user2 inbox for notification | |
|
101 | user1 = User.get(user1_id) | |
|
102 | assert 1 == len(user1.notifications) | |
|
103 | assert 'test message' in user1.notifications[0].notification.body | |
|
104 | ||
|
105 | user2 = User.get(user2_id) | |
|
106 | assert 1 == len(user2.notifications) | |
|
107 | assert 'test message' in user2.notifications[0].notification.body | |
|
108 | ||
|
109 | @pytest.mark.backends("git", "hg") | |
|
73 | 110 | def test_api_comment_pull_request_change_status( |
|
74 | 111 | self, pr_util, no_notifications): |
|
75 | 112 | pull_request = pr_util.create_pull_request() |
@@ -50,6 +50,7 b' class TestGetMethod(object):' | |||
|
50 | 50 | {'apiuser': '<RequiredType>', |
|
51 | 51 | 'comment_type': "<Optional:u'note'>", |
|
52 | 52 | 'commit_id': '<RequiredType>', |
|
53 | 'extra_recipients': '<Optional:[]>', | |
|
53 | 54 | 'message': '<RequiredType>', |
|
54 | 55 | 'repoid': '<RequiredType>', |
|
55 | 56 | 'request': '<RequiredType>', |
@@ -451,7 +451,7 b' def comment_pull_request(' | |||
|
451 | 451 | request, apiuser, pullrequestid, repoid=Optional(None), |
|
452 | 452 | message=Optional(None), commit_id=Optional(None), status=Optional(None), |
|
453 | 453 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), |
|
454 | resolves_comment_id=Optional(None), | |
|
454 | resolves_comment_id=Optional(None), extra_recipients=Optional([]), | |
|
455 | 455 | userid=Optional(OAttr('apiuser'))): |
|
456 | 456 | """ |
|
457 | 457 | Comment on the pull request specified with the `pullrequestid`, |
@@ -476,6 +476,11 b' def comment_pull_request(' | |||
|
476 | 476 | :type status: str |
|
477 | 477 | :param comment_type: Comment type, one of: 'note', 'todo' |
|
478 | 478 | :type comment_type: Optional(str), default: 'note' |
|
479 | :param resolves_comment_id: id of comment which this one will resolve | |
|
480 | :type resolves_comment_id: Optional(int) | |
|
481 | :param extra_recipients: list of user ids or usernames to add | |
|
482 | notifications for this comment. Acts like a CC for notification | |
|
483 | :type extra_recipients: Optional(list) | |
|
479 | 484 | :param userid: Comment on the pull request as this user |
|
480 | 485 | :type userid: Optional(str or int) |
|
481 | 486 | |
@@ -521,6 +526,7 b' def comment_pull_request(' | |||
|
521 | 526 | commit_id = Optional.extract(commit_id) |
|
522 | 527 | comment_type = Optional.extract(comment_type) |
|
523 | 528 | resolves_comment_id = Optional.extract(resolves_comment_id) |
|
529 | extra_recipients = Optional.extract(extra_recipients) | |
|
524 | 530 | |
|
525 | 531 | if not message and not status: |
|
526 | 532 | raise JSONRPCError( |
@@ -580,7 +586,8 b' def comment_pull_request(' | |||
|
580 | 586 | renderer=renderer, |
|
581 | 587 | comment_type=comment_type, |
|
582 | 588 | resolves_comment_id=resolves_comment_id, |
|
583 | auth_user=auth_user | |
|
589 | auth_user=auth_user, | |
|
590 | extra_recipients=extra_recipients | |
|
584 | 591 | ) |
|
585 | 592 | |
|
586 | 593 | if allowed_to_change_status and status: |
@@ -1550,7 +1550,7 b' def lock(request, apiuser, repoid, locke' | |||
|
1550 | 1550 | def comment_commit( |
|
1551 | 1551 | request, apiuser, repoid, commit_id, message, status=Optional(None), |
|
1552 | 1552 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), |
|
1553 | resolves_comment_id=Optional(None), | |
|
1553 | resolves_comment_id=Optional(None), extra_recipients=Optional([]), | |
|
1554 | 1554 | userid=Optional(OAttr('apiuser'))): |
|
1555 | 1555 | """ |
|
1556 | 1556 | Set a commit comment, and optionally change the status of the commit. |
@@ -1568,6 +1568,11 b' def comment_commit(' | |||
|
1568 | 1568 | :type status: str |
|
1569 | 1569 | :param comment_type: Comment type, one of: 'note', 'todo' |
|
1570 | 1570 | :type comment_type: Optional(str), default: 'note' |
|
1571 | :param resolves_comment_id: id of comment which this one will resolve | |
|
1572 | :type resolves_comment_id: Optional(int) | |
|
1573 | :param extra_recipients: list of user ids or usernames to add | |
|
1574 | notifications for this comment. Acts like a CC for notification | |
|
1575 | :type extra_recipients: Optional(list) | |
|
1571 | 1576 | :param userid: Set the user name of the comment creator. |
|
1572 | 1577 | :type userid: Optional(str or int) |
|
1573 | 1578 | |
@@ -1604,6 +1609,7 b' def comment_commit(' | |||
|
1604 | 1609 | status = Optional.extract(status) |
|
1605 | 1610 | comment_type = Optional.extract(comment_type) |
|
1606 | 1611 | resolves_comment_id = Optional.extract(resolves_comment_id) |
|
1612 | extra_recipients = Optional.extract(extra_recipients) | |
|
1607 | 1613 | |
|
1608 | 1614 | allowed_statuses = [x[0] for x in ChangesetStatus.STATUSES] |
|
1609 | 1615 | if status and status not in allowed_statuses: |
@@ -1632,7 +1638,8 b' def comment_commit(' | |||
|
1632 | 1638 | renderer=renderer, |
|
1633 | 1639 | comment_type=comment_type, |
|
1634 | 1640 | resolves_comment_id=resolves_comment_id, |
|
1635 | auth_user=apiuser | |
|
1641 | auth_user=apiuser, | |
|
1642 | extra_recipients=extra_recipients | |
|
1636 | 1643 | ) |
|
1637 | 1644 | if status: |
|
1638 | 1645 | # also do a status change |
@@ -232,7 +232,7 b' class CommentsModel(BaseModel):' | |||
|
232 | 232 | f_path=None, line_no=None, status_change=None, |
|
233 | 233 | status_change_type=None, comment_type=None, |
|
234 | 234 | resolves_comment_id=None, closing_pr=False, send_email=True, |
|
235 | renderer=None, auth_user=None): | |
|
235 | renderer=None, auth_user=None, extra_recipients=None): | |
|
236 | 236 | """ |
|
237 | 237 | Creates new comment for commit or pull request. |
|
238 | 238 | IF status_change is not none this comment is associated with a |
@@ -247,10 +247,13 b' class CommentsModel(BaseModel):' | |||
|
247 | 247 | :param line_no: |
|
248 | 248 | :param status_change: Label for status change |
|
249 | 249 | :param comment_type: Type of comment |
|
250 | :param resolves_comment_id: id of comment which this one will resolve | |
|
250 | 251 | :param status_change_type: type of status change |
|
251 | 252 | :param closing_pr: |
|
252 | 253 | :param send_email: |
|
253 | 254 | :param renderer: pick renderer for this comment |
|
255 | :param auth_user: current authenticated user calling this method | |
|
256 | :param extra_recipients: list of extra users to be added to recipients | |
|
254 | 257 | """ |
|
255 | 258 | |
|
256 | 259 | if not text: |
@@ -406,6 +409,9 b' class CommentsModel(BaseModel):' | |||
|
406 | 409 | 'pr_comment_url': pr_comment_url, |
|
407 | 410 | 'pr_closing': closing_pr, |
|
408 | 411 | }) |
|
412 | ||
|
413 | recipients += [self._get_user(u) for u in (extra_recipients or [])] | |
|
414 | ||
|
409 | 415 | if send_email: |
|
410 | 416 | # pre-generate the subject for notification itself |
|
411 | 417 | (subject, |
@@ -111,6 +111,7 b' class NotificationModel(BaseModel):' | |||
|
111 | 111 | |
|
112 | 112 | # add mentioned users into recipients |
|
113 | 113 | final_recipients = set(recipients_objs).union(mention_recipients) |
|
114 | ||
|
114 | 115 | notification = Notification.create( |
|
115 | 116 | created_by=created_by_obj, subject=notification_subject, |
|
116 | 117 | body=notification_body, recipients=final_recipients, |
General Comments 0
You need to be logged in to leave comments.
Login now