##// END OF EJS Templates
notifications changes...
marcink -
r3430:bbe21df7 beta
parent child Browse files
Show More
@@ -329,7 +329,7 b' class ChangesetController(BaseRepoContro'
329 329 text = text or (_('Status change -> %s')
330 330 % ChangesetStatus.get_status_lbl(status))
331 331
332 comm = ChangesetCommentsModel().create(
332 c.co = comm = ChangesetCommentsModel().create(
333 333 text=text,
334 334 repo=c.rhodecode_db_repo.repo_id,
335 335 user=c.rhodecode_user.user_id,
@@ -371,12 +371,11 b' class ChangesetController(BaseRepoContro'
371 371 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
372 372 return redirect(h.url('changeset_home', repo_name=repo_name,
373 373 revision=revision))
374
374 #only ajax below
375 375 data = {
376 376 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
377 377 }
378 378 if comm:
379 c.co = comm
380 379 data.update(comm.get_dict())
381 380 data.update({'rendered_text':
382 381 render('changeset/changeset_comment_block.html')})
@@ -403,11 +403,15 b' class PullrequestsController(BaseRepoCon'
403 403 status = request.POST.get('changeset_status')
404 404 change_status = request.POST.get('change_changeset_status')
405 405 text = request.POST.get('text')
406 close_pr = request.POST.get('save_close')
406 407
407 408 allowed_to_change_status = self._get_is_allowed_change_status(pull_request)
408 409 if status and change_status and allowed_to_change_status:
409 text = text or (_('Status change -> %s')
410 _def = (_('status change -> %s')
410 411 % ChangesetStatus.get_status_lbl(status))
412 if close_pr:
413 _def = _('Closing with') + ' ' + _def
414 text = text or _def
411 415 comm = ChangesetCommentsModel().create(
412 416 text=text,
413 417 repo=c.rhodecode_db_repo.repo_id,
@@ -416,7 +420,9 b' class PullrequestsController(BaseRepoCon'
416 420 f_path=request.POST.get('f_path'),
417 421 line_no=request.POST.get('line'),
418 422 status_change=(ChangesetStatus.get_status_lbl(status)
419 if status and change_status and allowed_to_change_status else None)
423 if status and change_status
424 and allowed_to_change_status else None),
425 closing_pr=close_pr
420 426 )
421 427
422 428 action_logger(self.rhodecode_user,
@@ -434,7 +440,7 b' class PullrequestsController(BaseRepoCon'
434 440 pull_request=pull_request_id
435 441 )
436 442
437 if request.POST.get('save_close'):
443 if close_pr:
438 444 if status in ['rejected', 'approved']:
439 445 PullRequestModel().close_pull_request(pull_request_id)
440 446 action_logger(self.rhodecode_user,
@@ -35,6 +35,7 b' from rhodecode.model import BaseModel'
35 35 from rhodecode.model.db import ChangesetComment, User, Repository, \
36 36 Notification, PullRequest
37 37 from rhodecode.model.notification import NotificationModel
38 from rhodecode.model.meta import Session
38 39
39 40 log = logging.getLogger(__name__)
40 41
@@ -57,8 +58,103 b' class ChangesetCommentsModel(BaseModel):'
57 58 user_objects.append(user_obj)
58 59 return user_objects
59 60
61 def _get_notification_data(self, repo, comment, user, comment_text,
62 line_no=None, revision=None, pull_request=None,
63 status_change=None, closing_pr=False):
64 """
65 Get notification data
66
67 :param comment_text:
68 :param line:
69 :returns: tuple (subj,body,recipients,notification_type,email_kwargs)
70 """
71 # make notification
72 body = comment_text # text of the comment
73 line = ''
74 if line_no:
75 line = _('on line %s') % line_no
76
77 #changeset
78 if revision:
79 notification_type = Notification.TYPE_CHANGESET_COMMENT
80 cs = repo.scm_instance.get_changeset(revision)
81 desc = "%s" % (cs.short_id)
82
83 _url = h.url('changeset_home',
84 repo_name=repo.repo_name,
85 revision=revision,
86 anchor='comment-%s' % comment.comment_id,
87 qualified=True,
88 )
89 subj = safe_unicode(
90 h.link_to('Re changeset: %(desc)s %(line)s' % \
91 {'desc': desc, 'line': line},
92 _url)
93 )
94 email_subject = 'User %s commented on changeset %s' % \
95 (user.username, h.short_id(revision))
96 # get the current participants of this changeset
97 recipients = ChangesetComment.get_users(revision=revision)
98 # add changeset author if it's in rhodecode system
99 cs_author = User.get_from_cs_author(cs.author)
100 if not cs_author:
101 #use repo owner if we cannot extract the author correctly
102 cs_author = repo.user
103 recipients += [cs_author]
104 email_kwargs = {
105 'status_change': status_change,
106 'cs_comment_user': h.person(user.email),
107 'cs_target_repo': h.url('summary_home', repo_name=repo.repo_name,
108 qualified=True),
109 'cs_comment_url': _url,
110 'raw_id': revision,
111 'message': cs.message
112 }
113 #pull request
114 elif pull_request:
115 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
116 desc = comment.pull_request.title
117 _url = h.url('pullrequest_show',
118 repo_name=pull_request.other_repo.repo_name,
119 pull_request_id=pull_request.pull_request_id,
120 anchor='comment-%s' % comment.comment_id,
121 qualified=True,
122 )
123 subj = safe_unicode(
124 h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
125 {'desc': desc,
126 'pr_id': comment.pull_request.pull_request_id,
127 'line': line},
128 _url)
129 )
130 email_subject = 'User %s commented on pull request #%s' % \
131 (user.username, comment.pull_request.pull_request_id)
132 # get the current participants of this pull request
133 recipients = ChangesetComment.get_users(pull_request_id=
134 pull_request.pull_request_id)
135 # add pull request author
136 recipients += [pull_request.author]
137
138 # add the reviewers to notification
139 recipients += [x.user for x in pull_request.reviewers]
140
141 #set some variables for email notification
142 email_kwargs = {
143 'pr_id': pull_request.pull_request_id,
144 'status_change': status_change,
145 'closing_pr': closing_pr,
146 'pr_comment_url': _url,
147 'pr_comment_user': h.person(user.email),
148 'pr_target_repo': h.url('summary_home',
149 repo_name=pull_request.other_repo.repo_name,
150 qualified=True)
151 }
152
153 return subj, body, recipients, notification_type, email_kwargs, email_subject
154
60 155 def create(self, text, repo, user, revision=None, pull_request=None,
61 f_path=None, line_no=None, status_change=None, send_email=True):
156 f_path=None, line_no=None, status_change=None, closing_pr=False,
157 send_email=True):
62 158 """
63 159 Creates new comment for changeset or pull request.
64 160 IF status_change is not none this comment is associated with a
@@ -72,9 +168,11 b' class ChangesetCommentsModel(BaseModel):'
72 168 :param f_path:
73 169 :param line_no:
74 170 :param status_change:
171 :param closing_pr:
75 172 :param send_email:
76 173 """
77 174 if not text:
175 log.warning('Missing text for comment, skipping...')
78 176 return
79 177
80 178 repo = self._get_repo(repo)
@@ -87,8 +185,6 b' class ChangesetCommentsModel(BaseModel):'
87 185 comment.line_no = line_no
88 186
89 187 if revision:
90 cs = repo.scm_instance.get_changeset(revision)
91 desc = "%s - %s" % (cs.short_id, h.shorter(cs.message, 256))
92 188 comment.revision = revision
93 189 elif pull_request:
94 190 pull_request = self.__get_pull_request(pull_request)
@@ -96,82 +192,24 b' class ChangesetCommentsModel(BaseModel):'
96 192 else:
97 193 raise Exception('Please specify revision or pull_request_id')
98 194
99 self.sa.add(comment)
100 self.sa.flush()
101
102 # make notification
103 line = ''
104 body = text
105
106 #changeset
107 if revision:
108 if line_no:
109 line = _('on line %s') % line_no
110 subj = safe_unicode(
111 h.link_to('Re commit: %(desc)s %(line)s' % \
112 {'desc': desc, 'line': line},
113 h.url('changeset_home', repo_name=repo.repo_name,
114 revision=revision,
115 anchor='comment-%s' % comment.comment_id,
116 qualified=True,
117 )
118 )
119 )
120 notification_type = Notification.TYPE_CHANGESET_COMMENT
121 # get the current participants of this changeset
122 recipients = ChangesetComment.get_users(revision=revision)
123 # add changeset author if it's in rhodecode system
124 cs_author = User.get_from_cs_author(cs.author)
125 if not cs_author:
126 #use repo owner if we cannot extract the author correctly
127 cs_author = repo.user
128 recipients += [cs_author]
129 email_kwargs = {
130 'status_change': status_change,
131 }
132 #pull request
133 elif pull_request:
134 _url = h.url('pullrequest_show',
135 repo_name=pull_request.other_repo.repo_name,
136 pull_request_id=pull_request.pull_request_id,
137 anchor='comment-%s' % comment.comment_id,
138 qualified=True,
139 )
140 subj = safe_unicode(
141 h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
142 {'desc': comment.pull_request.title,
143 'pr_id': comment.pull_request.pull_request_id,
144 'line': line},
145 _url)
146 )
147
148 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
149 # get the current participants of this pull request
150 recipients = ChangesetComment.get_users(pull_request_id=
151 pull_request.pull_request_id)
152 # add pull request author
153 recipients += [pull_request.author]
154
155 # add the reviewers to notification
156 recipients += [x.user for x in pull_request.reviewers]
157
158 #set some variables for email notification
159 email_kwargs = {
160 'pr_id': pull_request.pull_request_id,
161 'status_change': status_change,
162 'pr_comment_url': _url,
163 'pr_comment_user': h.person(user.email),
164 'pr_target_repo': h.url('summary_home',
165 repo_name=pull_request.other_repo.repo_name,
166 qualified=True)
167 }
195 Session().add(comment)
196 Session().flush()
168 197
169 198 if send_email:
199 (subj, body, recipients, notification_type,
200 email_kwargs, email_subject) = self._get_notification_data(
201 repo, comment, user,
202 comment_text=text,
203 line_no=line_no,
204 revision=revision,
205 pull_request=pull_request,
206 status_change=status_change,
207 closing_pr=closing_pr)
170 208 # create notification objects, and emails
171 209 NotificationModel().create(
172 210 created_by=user, subject=subj, body=body,
173 211 recipients=recipients, type_=notification_type,
174 email_kwargs=email_kwargs
212 email_kwargs=email_kwargs, email_subject=email_subject
175 213 )
176 214
177 215 mention_recipients = set(self._extract_mentions(body))\
@@ -195,7 +233,7 b' class ChangesetCommentsModel(BaseModel):'
195 233 :param comment_id:
196 234 """
197 235 comment = self.__get_changeset_comment(comment)
198 self.sa.delete(comment)
236 Session().delete(comment)
199 237
200 238 return comment
201 239
@@ -204,11 +242,8 b' class ChangesetCommentsModel(BaseModel):'
204 242 Get's main comments based on revision or pull_request_id
205 243
206 244 :param repo_id:
207 :type repo_id:
208 245 :param revision:
209 :type revision:
210 246 :param pull_request:
211 :type pull_request:
212 247 """
213 248
214 249 q = ChangesetComment.query()\
@@ -226,7 +261,7 b' class ChangesetCommentsModel(BaseModel):'
226 261 return q.all()
227 262
228 263 def get_inline_comments(self, repo_id, revision=None, pull_request=None):
229 q = self.sa.query(ChangesetComment)\
264 q = Session().query(ChangesetComment)\
230 265 .filter(ChangesetComment.repo_id == repo_id)\
231 266 .filter(ChangesetComment.line_no != None)\
232 267 .filter(ChangesetComment.f_path != None)\
@@ -35,6 +35,7 b' import rhodecode'
35 35 from rhodecode.lib import helpers as h
36 36 from rhodecode.model import BaseModel
37 37 from rhodecode.model.db import Notification, User, UserNotification
38 from rhodecode.model.meta import Session
38 39
39 40 log = logging.getLogger(__name__)
40 41
@@ -55,7 +56,7 b' class NotificationModel(BaseModel):'
55 56
56 57 def create(self, created_by, subject, body, recipients=None,
57 58 type_=Notification.TYPE_MESSAGE, with_email=True,
58 email_kwargs={}):
59 email_kwargs={}, email_subject=None):
59 60 """
60 61
61 62 Creates notification of given type
@@ -69,6 +70,7 b' class NotificationModel(BaseModel):'
69 70 :param type_: type of notification
70 71 :param with_email: send email with this notification
71 72 :param email_kwargs: additional dict to pass as args to email template
73 :param email_subject: use given subject as email subject
72 74 """
73 75 from rhodecode.lib.celerylib import tasks, run_task
74 76
@@ -106,7 +108,8 b' class NotificationModel(BaseModel):'
106 108
107 109 # send email with notification to all other participants
108 110 for rec in rec_objs:
109 email_subject = NotificationModel().make_description(notif, False)
111 if not email_subject:
112 email_subject = NotificationModel().make_description(notif, show_age=False)
110 113 type_ = type_
111 114 email_body = body
112 115 ## this is passed into template
@@ -131,7 +134,7 b' class NotificationModel(BaseModel):'
131 134 .filter(UserNotification.notification
132 135 == notification)\
133 136 .one()
134 self.sa.delete(obj)
137 Session().delete(obj)
135 138 return True
136 139 except Exception:
137 140 log.error(traceback.format_exc())
@@ -142,7 +145,6 b' class NotificationModel(BaseModel):'
142 145 Get mentions for given user, filter them if filter dict is given
143 146
144 147 :param user:
145 :type user:
146 148 :param filter:
147 149 """
148 150 user = self._get_user(user)
@@ -168,7 +170,7 b' class NotificationModel(BaseModel):'
168 170 == notification)\
169 171 .one()
170 172 obj.read = True
171 self.sa.add(obj)
173 Session().add(obj)
172 174 return True
173 175 except Exception:
174 176 log.error(traceback.format_exc())
@@ -188,7 +190,7 b' class NotificationModel(BaseModel):'
188 190 # update on joined tables :(
189 191 for obj in q.all():
190 192 obj.read = True
191 self.sa.add(obj)
193 Session().add(obj)
192 194
193 195 def get_unread_cnt_for_user(self, user):
194 196 user = self._get_user(user)
@@ -218,7 +220,7 b' class NotificationModel(BaseModel):'
218 220 #alias
219 221 _n = notification
220 222 _map = {
221 _n.TYPE_CHANGESET_COMMENT: _('commented on commit at %(when)s'),
223 _n.TYPE_CHANGESET_COMMENT: _('commented on changeset at %(when)s'),
222 224 _n.TYPE_MESSAGE: _('sent message at %(when)s'),
223 225 _n.TYPE_MENTION: _('mentioned you at %(when)s'),
224 226 _n.TYPE_REGISTRATION: _('registered in RhodeCode at %(when)s'),
@@ -75,13 +75,13 b' class PullRequestModel(BaseModel):'
75 75 new.title = title
76 76 new.description = description
77 77 new.author = created_by_user
78 self.sa.add(new)
78 Session().add(new)
79 79 Session().flush()
80 80 #members
81 81 for member in set(reviewers):
82 82 _usr = self._get_user(member)
83 83 reviewer = PullRequestReviewers(_usr, new)
84 self.sa.add(reviewer)
84 Session().add(reviewer)
85 85
86 86 #reset state to under-review
87 87 ChangesetStatusModel().set_status(
@@ -90,7 +90,8 b' class PullRequestModel(BaseModel):'
90 90 user=created_by_user,
91 91 pull_request=new
92 92 )
93
93 revision_data = [(x.raw_id, x.message)
94 for x in map(org_repo.get_changeset, revisions)]
94 95 #notification to reviewers
95 96 notif = NotificationModel()
96 97
@@ -114,7 +115,7 b' class PullRequestModel(BaseModel):'
114 115 'pr_repo_url': h.url('summary_home', repo_name=other_repo.repo_name,
115 116 qualified=True,),
116 117 'pr_url': pr_url,
117 'pr_revisions': revisions
118 'pr_revisions': revision_data
118 119 }
119 120
120 121 notif.create(created_by=created_by_user, subject=subject, body=body,
@@ -140,7 +141,7 b' class PullRequestModel(BaseModel):'
140 141 for uid in to_add:
141 142 _usr = self._get_user(uid)
142 143 reviewer = PullRequestReviewers(_usr, pull_request)
143 self.sa.add(reviewer)
144 Session().add(reviewer)
144 145
145 146 for uid in to_remove:
146 147 reviewer = PullRequestReviewers.query()\
@@ -148,7 +149,7 b' class PullRequestModel(BaseModel):'
148 149 PullRequestReviewers.pull_request==pull_request)\
149 150 .scalar()
150 151 if reviewer:
151 self.sa.delete(reviewer)
152 Session().delete(reviewer)
152 153
153 154 def delete(self, pull_request):
154 155 pull_request = self.__get_pull_request(pull_request)
@@ -158,7 +159,7 b' class PullRequestModel(BaseModel):'
158 159 pull_request = self.__get_pull_request(pull_request)
159 160 pull_request.status = PullRequest.STATUS_CLOSED
160 161 pull_request.updated_on = datetime.datetime.now()
161 self.sa.add(pull_request)
162 Session().add(pull_request)
162 163
163 164 def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref):
164 165 """
@@ -1,12 +1,17 b''
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="main.html"/>
3
4 <h4>${subject}</h4>
5
3 ##message from user goes here
4 <p>
5 ${cs_comment_user}: <br/>
6 6 ${body}
7 </p>
8 %if status_change:
9 <span>${_('New status')} -&gt; ${status_change}</span>
10 %endif
11 <div>${_('View this comment here')}: ${cs_comment_url}</div>
7 12
8 % if status_change is not None:
9 <div>
10 ${_('New status')} -&gt; ${status_change}
11 </div>
12 % endif
13 <pre>
14 ${_('Repo')}: ${cs_target_repo}
15 ${_('Changeset')}: ${h.short_id(raw_id)}
16 ${_('desc')}: ${h.shorter(message, 256)}
17 </pre>
@@ -10,8 +10,10 b''
10 10 </p>
11 11
12 12 <div>${_('revisions for reviewing')}</div>
13 <ul>
14 %for r in pr_revisions:
15 <li>${r}</li>
13 <pre>
14 %for r,r_msg in pr_revisions:
15 ${h.short_id(r)}:
16 ${h.shorter(r_msg, 256)}
17
16 18 %endfor
17 </ul>
19 </pre>
@@ -1,13 +1,18 b''
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="main.html"/>
3
4 ${_('User %s commented on pull request #%s for repository %s') % ('<b>%s</b>' % pr_comment_user, pr_id, pr_target_repo) |n}
3 ${_('Pull request #%s for repository %s') % (pr_id, pr_target_repo) |n}
4 ##message from user goes here
5 <p>
6 ${pr_comment_user}: <br/>
7 ${body}
8 </p>
5 9 <div>${_('View this comment here')}: ${pr_comment_url}</div>
6 10
7 <p>
8 ${body}
9
10 11 %if status_change:
11 <span>${_('New status')} -&gt; ${status_change}</span>
12 %if closing_pr:
13 <span>${_('Closing pull request with status')} -&gt; ${status_change}</span>
14 %else:
15 <span>${_('New status')} -&gt; ${status_change}</span>
16 %endif
12 17 %endif
13 18 </p>
@@ -30,7 +30,7 b''
30 30 <span style="font-size: 20px">
31 31 ${h.select('org_repo','',c.org_repos,class_='refs')}:${h.select('org_ref',c.default_org_ref,c.org_refs,class_='refs')}
32 32 </span>
33 <div style="padding:5px 3px 3px 42px;">${c.rhodecode_db_repo.description}</div>
33 <div style="padding:5px 3px 3px 20px;">${c.rhodecode_db_repo.description}</div>
34 34 </div>
35 35 <div style="clear:both;padding-top: 10px"></div>
36 36 </div>
@@ -44,7 +44,7 b''
44 44 <span style="font-size: 20px">
45 45 ${h.select('other_repo',c.default_other_repo,c.other_repos,class_='refs')}:${h.select('other_ref',c.default_other_ref,c.default_other_refs,class_='refs')}
46 46 </span>
47 <div id="other_repo_desc" style="padding:5px 3px 3px 42px;"></div>
47 <div id="other_repo_desc" style="padding:5px 3px 3px 20px;"></div>
48 48 </div>
49 49 <div style="clear:both;padding-top: 10px"></div>
50 50 </div>
General Comments 0
You need to be logged in to leave comments. Login now