예제 #1
0
 def notify_moderators(self, post):
     ''' Notify moderators that a post needs approval [#2963] '''
     artifact = self.artifact or self
     subject = '[%s:%s] Moderation action required' % (
         c.project.shortname, c.app.config.options.mount_point)
     author = post.author()
     url = self.discussion_class().query.get(_id=self.discussion_id).url()
     text = ('The following submission requires approval at %s before '
             'it can be approved for posting:\n\n%s'
             % (h.absurl(url + 'moderate'), post.text))
     n = Notification(
         ref_id=artifact.index_id(),
         topic='message',
         link=artifact.url(),
         _id=artifact.url() + post._id,
         from_address=str(author._id) if author != User.anonymous()
         else None,
         reply_to_address=g.noreply,
         subject=subject,
         text=text,
         in_reply_to=post.parent_id,
         author_id=author._id,
         pubdate=datetime.utcnow())
     users = self.app_config.project.users()
     for u in users:
         if (has_access(self, 'moderate', u)
             and Mailbox.subscribed(user_id=u._id,
                                    app_config_id=post.app_config_id)):
                 n.send_direct(str(u._id))
예제 #2
0
 def notify(self, file_info=None, notification_text=None):
     if self.project.notifications_disabled:
         return  # notifications disabled for entire project
     artifact = self.thread.artifact or self.thread
     msg_id = artifact.url() + self._id
     notification_params = dict(
         post=self,
         text=notification_text,
         file_info=file_info)
     n = Notification.query.get(_id=msg_id)
     if n and 'Moderation action required' in n.subject:
         # Existing notification for this artifact is for moderators only,
         # this means artifact was not auto approved, and all the
         # subscribers did not receive notification. Now, moderator approved
         # artifact/post, so we should re-send actual notification
         msg_id = u'approved-' + msg_id
         n = Notification.query.get(_id=msg_id)
         if n:
             # 'approved' notification also exists, re-send
             n.fire_notification_task(artifact, 'message')
         else:
             # 'approved' notification does not exist, create
             notification_params['message_id'] = msg_id
     if not n:
         n = Notification.post(artifact, 'message', **notification_params)
     if not n:
         return
     if (hasattr(artifact, "monitoring_email")
             and artifact.monitoring_email):
         if hasattr(artifact, 'notify_post'):
             if artifact.notify_post:
                 n.send_simple(artifact.monitoring_email)
         else:  # Send if no extra checks required
             n.send_simple(artifact.monitoring_email)
예제 #3
0
 def notify(self, file_info=None, notification_text=None):
     if self.project.notifications_disabled:
         return  # notifications disabled for entire project
     artifact = self.thread.artifact or self.thread
     msg_id = artifact.url() + self._id
     notification_params = dict(post=self,
                                text=notification_text,
                                file_info=file_info)
     n = Notification.query.get(_id=msg_id)
     if n and 'Moderation action required' in n.subject:
         # Existing notification for this artifact is for moderators only,
         # this means artifact was not auto approved, and all the
         # subscribers did not receive notification. Now, moderator approved
         # artifact/post, so we should re-send actual notification
         msg_id = u'approved-' + msg_id
         n = Notification.query.get(_id=msg_id)
         if n:
             # 'approved' notification also exists, re-send
             n.fire_notification_task(artifact, 'message')
         else:
             # 'approved' notification does not exist, create
             notification_params['message_id'] = msg_id
     if not n:
         n = Notification.post(artifact, 'message', **notification_params)
     if not n:
         return
     if (hasattr(artifact, "monitoring_email")
             and artifact.monitoring_email):
         if hasattr(artifact, 'notify_post'):
             if artifact.notify_post:
                 n.send_simple(artifact.monitoring_email)
         else:  # Send if no extra checks required
             n.send_simple(artifact.monitoring_email)
예제 #4
0
 def approve(self, file_info=None):
     from allura.model.notification import Notification
     if self.status == 'ok': return
     self.status = 'ok'
     if self.parent_id is None:
         thd = self.thread_class().query.get(_id=self.thread_id)
         g.post_event('discussion.new_thread', thd._id)
     author = self.author()
     security.simple_grant(self.acl, author.project_role()._id, 'moderate')
     self.commit()
     if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated'
             and author._id != None):
         security.simple_grant(self.acl,
                               author.project_role()._id,
                               'unmoderated_post')
     g.post_event('discussion.new_post', self.thread_id, self._id)
     artifact = self.thread.artifact or self.thread
     n = Notification.post(artifact,
                           'message',
                           post=self,
                           file_info=file_info)
     if hasattr(self.discussion,
                "monitoring_email") and self.discussion.monitoring_email:
         n.send_simple(self.discussion.monitoring_email)
     session(self).flush()
     self.thread.last_post_date = max(self.thread.last_post_date,
                                      self.mod_date)
     self.thread.update_stats()
     self.discussion.update_stats()
예제 #5
0
 def notify(self, file_info=None, check_dup=False):
     artifact = self.thread.artifact or self.thread
     n = Notification.query.get(
         _id=artifact.url() + self._id) if check_dup else None
     if not n:
         n = Notification.post(artifact, 'message', post=self,
                               file_info=file_info)
     if (hasattr(artifact, "monitoring_email")
             and artifact.monitoring_email):
         if hasattr(artifact, 'notify_post'):
             if artifact.notify_post:
                 n.send_simple(artifact.monitoring_email)
         else:  # Send if no extra checks required
             n.send_simple(artifact.monitoring_email)
예제 #6
0
파일: discuss.py 프로젝트: pombreda/allura
 def notify(self, file_info=None, check_dup=False):
     if self.project.notifications_disabled:
         return  # notifications disabled for entire project
     artifact = self.thread.artifact or self.thread
     n = Notification.query.get(
         _id=artifact.url() + self._id) if check_dup else None
     if not n:
         n = Notification.post(artifact, 'message', post=self,
                               file_info=file_info)
     if not n: return
     if (hasattr(artifact, "monitoring_email")
             and artifact.monitoring_email):
         if hasattr(artifact, 'notify_post'):
             if artifact.notify_post:
                 n.send_simple(artifact.monitoring_email)
         else:  # Send if no extra checks required
             n.send_simple(artifact.monitoring_email)
예제 #7
0
 def notify(self, file_info=None, check_dup=False, notification_text=None):
     if self.project.notifications_disabled:
         return  # notifications disabled for entire project
     artifact = self.thread.artifact or self.thread
     n = Notification.query.get(
         _id=artifact.url() + self._id) if check_dup else None
     if not n:
         n = Notification.post(artifact, 'message',
                               post=self, text=notification_text,
                               file_info=file_info)
     if not n:
         return
     if (hasattr(artifact, "monitoring_email")
             and artifact.monitoring_email):
         if hasattr(artifact, 'notify_post'):
             if artifact.notify_post:
                 n.send_simple(artifact.monitoring_email)
         else:  # Send if no extra checks required
             n.send_simple(artifact.monitoring_email)