Show More
@@ -20,7 +20,7 b'' | |||||
20 |
|
20 | |||
21 | import pytest |
|
21 | import pytest | |
22 |
|
22 | |||
23 | from rhodecode.model.db import ChangesetStatus |
|
23 | from rhodecode.model.db import ChangesetStatus, User | |
24 | from rhodecode.api.tests.utils import ( |
|
24 | from rhodecode.api.tests.utils import ( | |
25 | build_data, api_call, assert_error, assert_ok) |
|
25 | build_data, api_call, assert_error, assert_ok) | |
26 |
|
26 | |||
@@ -79,3 +79,38 b' class TestCommentCommit(object):' | |||||
79 | 'success': True |
|
79 | 'success': True | |
80 | } |
|
80 | } | |
81 | assert_ok(id_, expected, given=response.body) |
|
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 | import pytest |
|
21 | import pytest | |
22 |
|
22 | |||
23 | from rhodecode.model.comment import CommentsModel |
|
23 | from rhodecode.model.comment import CommentsModel | |
24 | from rhodecode.model.db import UserLog |
|
24 | from rhodecode.model.db import UserLog, User | |
25 | from rhodecode.model.pull_request import PullRequestModel |
|
25 | from rhodecode.model.pull_request import PullRequestModel | |
26 | from rhodecode.tests import TEST_USER_ADMIN_LOGIN |
|
26 | from rhodecode.tests import TEST_USER_ADMIN_LOGIN | |
27 | from rhodecode.api.tests.utils import ( |
|
27 | from rhodecode.api.tests.utils import ( | |
@@ -70,6 +70,43 b' class TestCommentPullRequest(object):' | |||||
70 | assert journal[-1].action == 'repo.pull_request.comment.create' |
|
70 | assert journal[-1].action == 'repo.pull_request.comment.create' | |
71 |
|
71 | |||
72 | @pytest.mark.backends("git", "hg") |
|
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 | def test_api_comment_pull_request_change_status( |
|
110 | def test_api_comment_pull_request_change_status( | |
74 | self, pr_util, no_notifications): |
|
111 | self, pr_util, no_notifications): | |
75 | pull_request = pr_util.create_pull_request() |
|
112 | pull_request = pr_util.create_pull_request() |
@@ -50,6 +50,7 b' class TestGetMethod(object):' | |||||
50 | {'apiuser': '<RequiredType>', |
|
50 | {'apiuser': '<RequiredType>', | |
51 | 'comment_type': "<Optional:u'note'>", |
|
51 | 'comment_type': "<Optional:u'note'>", | |
52 | 'commit_id': '<RequiredType>', |
|
52 | 'commit_id': '<RequiredType>', | |
|
53 | 'extra_recipients': '<Optional:[]>', | |||
53 | 'message': '<RequiredType>', |
|
54 | 'message': '<RequiredType>', | |
54 | 'repoid': '<RequiredType>', |
|
55 | 'repoid': '<RequiredType>', | |
55 | 'request': '<RequiredType>', |
|
56 | 'request': '<RequiredType>', |
@@ -451,7 +451,7 b' def comment_pull_request(' | |||||
451 | request, apiuser, pullrequestid, repoid=Optional(None), |
|
451 | request, apiuser, pullrequestid, repoid=Optional(None), | |
452 | message=Optional(None), commit_id=Optional(None), status=Optional(None), |
|
452 | message=Optional(None), commit_id=Optional(None), status=Optional(None), | |
453 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), |
|
453 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), | |
454 | resolves_comment_id=Optional(None), |
|
454 | resolves_comment_id=Optional(None), extra_recipients=Optional([]), | |
455 | userid=Optional(OAttr('apiuser'))): |
|
455 | userid=Optional(OAttr('apiuser'))): | |
456 | """ |
|
456 | """ | |
457 | Comment on the pull request specified with the `pullrequestid`, |
|
457 | Comment on the pull request specified with the `pullrequestid`, | |
@@ -476,6 +476,11 b' def comment_pull_request(' | |||||
476 | :type status: str |
|
476 | :type status: str | |
477 | :param comment_type: Comment type, one of: 'note', 'todo' |
|
477 | :param comment_type: Comment type, one of: 'note', 'todo' | |
478 | :type comment_type: Optional(str), default: 'note' |
|
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 | :param userid: Comment on the pull request as this user |
|
484 | :param userid: Comment on the pull request as this user | |
480 | :type userid: Optional(str or int) |
|
485 | :type userid: Optional(str or int) | |
481 |
|
486 | |||
@@ -521,6 +526,7 b' def comment_pull_request(' | |||||
521 | commit_id = Optional.extract(commit_id) |
|
526 | commit_id = Optional.extract(commit_id) | |
522 | comment_type = Optional.extract(comment_type) |
|
527 | comment_type = Optional.extract(comment_type) | |
523 | resolves_comment_id = Optional.extract(resolves_comment_id) |
|
528 | resolves_comment_id = Optional.extract(resolves_comment_id) | |
|
529 | extra_recipients = Optional.extract(extra_recipients) | |||
524 |
|
530 | |||
525 | if not message and not status: |
|
531 | if not message and not status: | |
526 | raise JSONRPCError( |
|
532 | raise JSONRPCError( | |
@@ -580,7 +586,8 b' def comment_pull_request(' | |||||
580 | renderer=renderer, |
|
586 | renderer=renderer, | |
581 | comment_type=comment_type, |
|
587 | comment_type=comment_type, | |
582 | resolves_comment_id=resolves_comment_id, |
|
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 | if allowed_to_change_status and status: |
|
593 | if allowed_to_change_status and status: |
@@ -1550,7 +1550,7 b' def lock(request, apiuser, repoid, locke' | |||||
1550 | def comment_commit( |
|
1550 | def comment_commit( | |
1551 | request, apiuser, repoid, commit_id, message, status=Optional(None), |
|
1551 | request, apiuser, repoid, commit_id, message, status=Optional(None), | |
1552 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), |
|
1552 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), | |
1553 | resolves_comment_id=Optional(None), |
|
1553 | resolves_comment_id=Optional(None), extra_recipients=Optional([]), | |
1554 | userid=Optional(OAttr('apiuser'))): |
|
1554 | userid=Optional(OAttr('apiuser'))): | |
1555 | """ |
|
1555 | """ | |
1556 | Set a commit comment, and optionally change the status of the commit. |
|
1556 | Set a commit comment, and optionally change the status of the commit. | |
@@ -1568,6 +1568,11 b' def comment_commit(' | |||||
1568 | :type status: str |
|
1568 | :type status: str | |
1569 | :param comment_type: Comment type, one of: 'note', 'todo' |
|
1569 | :param comment_type: Comment type, one of: 'note', 'todo' | |
1570 | :type comment_type: Optional(str), default: 'note' |
|
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 | :param userid: Set the user name of the comment creator. |
|
1576 | :param userid: Set the user name of the comment creator. | |
1572 | :type userid: Optional(str or int) |
|
1577 | :type userid: Optional(str or int) | |
1573 |
|
1578 | |||
@@ -1604,6 +1609,7 b' def comment_commit(' | |||||
1604 | status = Optional.extract(status) |
|
1609 | status = Optional.extract(status) | |
1605 | comment_type = Optional.extract(comment_type) |
|
1610 | comment_type = Optional.extract(comment_type) | |
1606 | resolves_comment_id = Optional.extract(resolves_comment_id) |
|
1611 | resolves_comment_id = Optional.extract(resolves_comment_id) | |
|
1612 | extra_recipients = Optional.extract(extra_recipients) | |||
1607 |
|
1613 | |||
1608 | allowed_statuses = [x[0] for x in ChangesetStatus.STATUSES] |
|
1614 | allowed_statuses = [x[0] for x in ChangesetStatus.STATUSES] | |
1609 | if status and status not in allowed_statuses: |
|
1615 | if status and status not in allowed_statuses: | |
@@ -1632,7 +1638,8 b' def comment_commit(' | |||||
1632 | renderer=renderer, |
|
1638 | renderer=renderer, | |
1633 | comment_type=comment_type, |
|
1639 | comment_type=comment_type, | |
1634 | resolves_comment_id=resolves_comment_id, |
|
1640 | resolves_comment_id=resolves_comment_id, | |
1635 | auth_user=apiuser |
|
1641 | auth_user=apiuser, | |
|
1642 | extra_recipients=extra_recipients | |||
1636 | ) |
|
1643 | ) | |
1637 | if status: |
|
1644 | if status: | |
1638 | # also do a status change |
|
1645 | # also do a status change |
@@ -232,7 +232,7 b' class CommentsModel(BaseModel):' | |||||
232 | f_path=None, line_no=None, status_change=None, |
|
232 | f_path=None, line_no=None, status_change=None, | |
233 | status_change_type=None, comment_type=None, |
|
233 | status_change_type=None, comment_type=None, | |
234 | resolves_comment_id=None, closing_pr=False, send_email=True, |
|
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 | Creates new comment for commit or pull request. |
|
237 | Creates new comment for commit or pull request. | |
238 | IF status_change is not none this comment is associated with a |
|
238 | IF status_change is not none this comment is associated with a | |
@@ -247,10 +247,13 b' class CommentsModel(BaseModel):' | |||||
247 | :param line_no: |
|
247 | :param line_no: | |
248 | :param status_change: Label for status change |
|
248 | :param status_change: Label for status change | |
249 | :param comment_type: Type of comment |
|
249 | :param comment_type: Type of comment | |
|
250 | :param resolves_comment_id: id of comment which this one will resolve | |||
250 | :param status_change_type: type of status change |
|
251 | :param status_change_type: type of status change | |
251 | :param closing_pr: |
|
252 | :param closing_pr: | |
252 | :param send_email: |
|
253 | :param send_email: | |
253 | :param renderer: pick renderer for this comment |
|
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 | if not text: |
|
259 | if not text: | |
@@ -406,6 +409,9 b' class CommentsModel(BaseModel):' | |||||
406 | 'pr_comment_url': pr_comment_url, |
|
409 | 'pr_comment_url': pr_comment_url, | |
407 | 'pr_closing': closing_pr, |
|
410 | 'pr_closing': closing_pr, | |
408 | }) |
|
411 | }) | |
|
412 | ||||
|
413 | recipients += [self._get_user(u) for u in (extra_recipients or [])] | |||
|
414 | ||||
409 | if send_email: |
|
415 | if send_email: | |
410 | # pre-generate the subject for notification itself |
|
416 | # pre-generate the subject for notification itself | |
411 | (subject, |
|
417 | (subject, |
@@ -111,6 +111,7 b' class NotificationModel(BaseModel):' | |||||
111 |
|
111 | |||
112 | # add mentioned users into recipients |
|
112 | # add mentioned users into recipients | |
113 | final_recipients = set(recipients_objs).union(mention_recipients) |
|
113 | final_recipients = set(recipients_objs).union(mention_recipients) | |
|
114 | ||||
114 | notification = Notification.create( |
|
115 | notification = Notification.create( | |
115 | created_by=created_by_obj, subject=notification_subject, |
|
116 | created_by=created_by_obj, subject=notification_subject, | |
116 | body=notification_body, recipients=final_recipients, |
|
117 | body=notification_body, recipients=final_recipients, |
General Comments 0
You need to be logged in to leave comments.
Login now