def edit(self, content, auth, save=False): if not self.node.can_comment(auth) or self.user._id != auth.user._id: raise PermissionsError( '{0!r} does not have permission to edit this comment'.format( auth.user)) log_dict = { 'project': self.node.parent_id, 'node': self.node._id, 'user': self.user._id, 'comment': self._id, } log_dict.update(self.root_target.referent.get_extra_log_params(self)) self.content = content self.modified = True self.date_modified = timezone.now() new_mentions = get_valid_mentioned_users_guids(self, self.node.contributors) if save: if new_mentions: project_signals.mention_added.send(self, new_mentions=new_mentions, auth=auth) self.ever_mentioned.extend(new_mentions) self.save() self.node.add_log( NodeLog.COMMENT_UPDATED, log_dict, auth=auth, save=False, ) self.node.save()
def edit(self, content, auth, save=False): if not self.node.can_comment(auth) or self.user._id != auth.user._id: raise PermissionsError('{0!r} does not have permission to edit this comment'.format(auth.user)) log_dict = { 'project': self.node.parent_id, 'node': self.node._id, 'user': self.user._id, 'comment': self._id, } log_dict.update(self.root_target.referent.get_extra_log_params(self)) self.content = content self.modified = True self.date_modified = timezone.now() new_mentions = get_valid_mentioned_users_guids(self, self.node.contributors) if save: if new_mentions: project_signals.mention_added.send(self, new_mentions=new_mentions, auth=auth) self.ever_mentioned.extend(new_mentions) self.save() self.node.add_log( NodeLog.COMMENT_UPDATED, log_dict, auth=auth, save=False, ) self.node.save()
def create(cls, auth, **kwargs): comment = cls(**kwargs) if not comment.node.can_comment(auth): raise PermissionsError( '{0!r} does not have permission to comment on this node'. format(auth.user)) log_dict = { 'project': comment.node.parent_id, 'node': comment.node._id, 'user': comment.user._id, 'comment': comment._id, } if isinstance(comment.target.referent, Comment): comment.root_target = comment.target.referent.root_target else: comment.root_target = comment.target page = getattr(comment.root_target.referent, 'root_target_page', None) if not page: raise ValueError('Invalid root target.') comment.page = page log_dict.update( comment.root_target.referent.get_extra_log_params(comment)) new_mentions = [] if comment.content: if not comment.id: # must have id before accessing M2M comment.save() new_mentions = get_valid_mentioned_users_guids( comment, comment.node.contributors_and_group_members) if new_mentions: project_signals.mention_added.send(comment, new_mentions=new_mentions, auth=auth) comment.ever_mentioned.add(*comment.node.contributors.filter( guids___id__in=new_mentions)) comment.save() comment.node.add_log( NodeLog.COMMENT_ADDED, log_dict, auth=auth, save=False, ) comment.node.save() project_signals.comment_added.send(comment, auth=auth, new_mentions=new_mentions) return comment
def create(cls, auth, **kwargs): comment = cls(**kwargs) if not comment.node.can_comment(auth): raise PermissionsError('{0!r} does not have permission to comment on this node'.format(auth.user)) log_dict = { 'project': comment.node.parent_id, 'node': comment.node._id, 'user': comment.user._id, 'comment': comment._id, } if isinstance(comment.target.referent, Comment): comment.root_target = comment.target.referent.root_target else: comment.root_target = comment.target page = getattr(comment.root_target.referent, 'root_target_page', None) if not page: raise ValueError('Invalid root target.') comment.page = page log_dict.update(comment.root_target.referent.get_extra_log_params(comment)) new_mentions = [] if comment.content: if not comment.id: # must have id before accessing M2M comment.save() new_mentions = get_valid_mentioned_users_guids(comment, comment.node.contributors) if new_mentions: project_signals.mention_added.send(comment, new_mentions=new_mentions, auth=auth) comment.ever_mentioned.add(*comment.node.contributors.filter(guids___id__in=new_mentions)) comment.save() comment.node.add_log( NodeLog.COMMENT_ADDED, log_dict, auth=auth, save=False, ) comment.node.save() project_signals.comment_added.send(comment, auth=auth, new_mentions=new_mentions) return comment