示例#1
0
    def _reopen(self, review, prev_state):
        models.Event.create_event(review.project, models.EventType.DEMO_OPENED,
                                  review, review.last_action_by)
        users = User.objects.filter(
            Q(reviewer__review=review, reviewer__is_active=True) |
            Q(follower__review=review, follower__is_active=True), ).distinct()
        reviewers = review.reviewer_set.active()
        for user in users:
            is_reviewer = user in reviewers
            helpers.send_system_message(
                '"{}" has been Reopened'.format(review.title),
                'demotime/messages/reopened.html',
                {
                    'is_reviewer': is_reviewer,
                    'review': review,
                    'previous_state': prev_state.title(),
                    'user': user
                },
                user,
                revision=review.revision,
            )

        reviewers.update(status=constants.REVIEWING)
        review.reviewer_state = constants.REVIEWING
        review.save(update_fields=['reviewer_state'])
        models.Reminder.update_reminder_activity_for_review(review, True)
示例#2
0
    def on_enter(self, review, prev_state):
        super().on_enter(review, prev_state)
        models.Event.create_event(
            review.project,
            models.EventType.DEMO_ABORTED,
            review,
            review.last_action_by,
        )
        users = User.objects.filter(
            Q(reviewer__review=review, reviewer__is_active=True) |
            Q(follower__review=review, follower__is_active=True), ).distinct()
        reviewers = review.reviewers.all()
        for user in users:
            is_reviewer = user in reviewers
            helpers.send_system_message(
                '"{}" has been Aborted'.format(review.title),
                'demotime/messages/closed.html',
                {
                    'is_reviewer': is_reviewer,
                    'review': review,
                    'previous_state': prev_state.name.title(),
                    'user': user,
                },
                user,
                revision=review.revision,
            )

        models.Reminder.update_reminder_activity_for_review(review)
        self._common_state_change(review, self.name)
示例#3
0
 def _send_creator_message(self, removed=False):
     subject = 'You have been {} as an owner of {}'.format(
         'removed' if removed else 'added', self.review.title)
     helpers.send_system_message(subject,
                                 'demotime/messages/creator.html', {
                                     'review': self.review,
                                     'removed': removed,
                                     'title': self.review.title,
                                     'url': self.review.get_absolute_url(),
                                 },
                                 self.user,
                                 revision=self.review.revision)
示例#4
0
 def on_enter(self, review, prev_state):
     super().on_enter(review, prev_state)
     helpers.send_system_message(
         '"{}" has been Rejected'.format(review.title),
         'demotime/messages/rejected.html',
         {'review': review},
         review.last_action_by,
         revision=review.revision,
     )
     models.Event.create_event(review.project,
                               models.EventType.DEMO_REJECTED, review,
                               review.last_action_by)
     self._common_state_change(review, constants.REJECTED)
示例#5
0
 def send_reminder(self):
     context = {
         'reminder': self,
         'url': self.review.get_absolute_url(),
     }
     title = 'Reminder: {}'.format(self.review.title)
     helpers.send_system_message(
         title,
         'demotime/messages/reminder.html',
         context,
         self.user,
         revision=self.review.revision,
     )
     self.remind_at = get_reminder_days(self.review.project)
     self.save(update_fields=['remind_at'])
示例#6
0
 def on_enter(self, review, prev_state):
     super().on_enter(review, prev_state)
     helpers.send_system_message(
         '"{}" is back Under Review'.format(review.title),
         'demotime/messages/reviewing.html',
         {
             'review': review,
             'previous_state': prev_state.name.title()
         },
         review.last_action_by,
         revision=review.revision,
     )
     models.Event.create_event(review.project,
                               models.EventType.DEMO_REVIEWING, review,
                               review.last_action_by)
     self._common_state_change(review, constants.REVIEWING)
示例#7
0
    def _send_follower_message(self, notify_follower=False, notify_creator=False):
        if not notify_follower and not notify_creator:
            raise Exception('No receipient for message in follower message')

        title_template = '{} {} now following {}'
        title = title_template.format(
            self.display_name,
            'is',
            self.review.title
        )

        receipients = [
            creator.user for creator in self.review.creator_set.active()
        ]
        if notify_follower:
            receipients = [self.user]
            title = title_template.format(
                'You',
                'are',
                self.review.title
            )

        for receipient in receipients:
            context = {
                'receipient': receipient,
                'url': self.review.get_absolute_url(),
                'title': self.review.title,
                'follower': self,
                'is_follower': notify_follower,
            }
            helpers.send_system_message(
                title,
                'demotime/messages/follower.html',
                context,
                receipient,
                revision=self.review.revision,
            )
示例#8
0
    def send_revision_messages(self, update=False):
        title = 'New Review: {}'.format(self.title)
        if update:
            title = 'Update on Review: {}'.format(self.title)

            for creator in self.creator_set.active().exclude(
                    user=self.last_action_by):
                context = {
                    'receipient': creator.user,
                    'url': self.get_absolute_url(),
                    'update': update,
                    'title': self.title,
                    'is_creator': True,
                }
                helpers.send_system_message(
                    title,
                    'demotime/messages/review.html',
                    context,
                    creator.user,
                    revision=self.revision,
                )

        for reviewer in self.reviewer_set.active():
            context = {
                'receipient': reviewer.reviewer,
                'url': self.get_absolute_url(),
                'update': update,
                'title': self.title,
                'is_reviewer': True
            }
            helpers.send_system_message(
                title,
                'demotime/messages/review.html',
                context,
                reviewer.reviewer,
                revision=self.revision,
            )

        for follower in self.follower_set.active():
            context = {
                'receipient': follower.user,
                'url': self.get_absolute_url(),
                'update': update,
                'title': self.title,
                'is_follower': True,
            }
            helpers.send_system_message(
                title,
                'demotime/messages/review.html',
                context,
                follower.user,
                revision=self.revision,
            )
示例#9
0
    def create_comment(cls,
                       commenter,
                       comment,
                       review,
                       thread=None,
                       attachments=None,
                       is_issue=False):
        if not thread:
            thread = CommentThread.create_comment_thread(review)

        # Find Mentions
        starts_with_mention = False
        comment_without_html = strip_tags(comment)
        mentioned_users = []
        mentions = cls.MENTION_REGEX.findall(comment_without_html)
        for mention in mentions:
            username = mention[1:]  # Drop the @
            try:
                mentioned_user = User.objects.get(username__iexact=username)
            except User.DoesNotExist:
                continue  # Bad Mention, user was probably doing something else weird

            mentioned_users.append(mentioned_user.pk)
            if not starts_with_mention:
                starts_with_mention = comment_without_html.startswith(mention)

        obj = cls.objects.create(commenter=commenter,
                                 comment=comment,
                                 thread=thread)
        if is_issue:
            Issue.create_issue(review.review, obj, commenter)
        if not attachments:
            attachments = []

        for count, attachment in enumerate(attachments):
            Attachment.create_attachment(
                attachment=attachment['attachment'],
                description=attachment.get('description', ''),
                content_object=obj,
                sort_order=attachment.get('sort_order') or count)

        if not review.review.state == constants.DRAFT:
            Event.create_event(
                project=review.review.project,
                event_type_code=EventType.COMMENT_ADDED,
                related_object=obj,
                user=commenter,
            )
            review.review.trigger_webhooks(constants.COMMENT,
                                           {'comment': obj.to_json()})

            system_user = User.objects.get(username='******')
            if starts_with_mention:
                users = User.objects.filter(pk__in=mentioned_users)
            else:
                users = User.objects.filter((
                    # Reviewers
                    models.Q(reviewer__review=review.review,
                             reviewer__is_active=True) |
                    # Followers
                    models.Q(follower__review=review.review,
                             follower__is_active=True) |
                    # Creator
                    models.Q(creator__review=review.review,
                             creator__active=True) |
                    # Mentions
                    models.Q(pk__in=mentioned_users))).distinct()

            for user in users:
                if user == commenter:
                    continue

                UserReviewStatus.objects.filter(
                    review=review.review,
                    user=user,
                ).update(read=False)

                context = {
                    'receipient': user,
                    'sender': system_user,
                    'comment': obj,
                    'url': review.get_absolute_url(),
                    'title': review.review.title,
                }
                helpers.send_system_message(
                    'New Comment on {}'.format(review.review.title),
                    'demotime/messages/new_comment.html',
                    context,
                    user,
                    revision=review,
                )

        tasks.post_process_comment.delay(obj.pk)
        return obj