def approve(self, file_info=None, notify=True): if self.status == 'ok': return self.status = 'ok' author = self.author() security.simple_grant(self.acl, author.project_role(self.project)._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') if notify: self.notify(file_info=file_info) artifact = self.thread.artifact or self.thread session(self).flush() self.thread.last_post_date = max(self.thread.last_post_date, self.mod_date) self.thread.update_stats() if hasattr(artifact, 'update_stats'): artifact.update_stats() if self.text: g.director.create_activity(author, 'posted', self, target=artifact, related_nodes=[self.app_config.project])
def approve(self, file_info=None, notify=True, notification_text=None): if self.status == 'ok': return self.status = 'ok' author = self.author() author_role = ProjectRole.by_user( author, project=self.project, upsert=True) if not author.is_anonymous(): security.simple_grant( self.acl, author_role._id, 'moderate') self.commit() if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated' and author._id != None): security.simple_grant( self.acl, author_role._id, 'unmoderated_post') if notify: self.notify(file_info=file_info, notification_text=notification_text) artifact = self.thread.artifact or self.thread session(self).flush() self.thread.last_post_date = max( self.thread.last_post_date, self.mod_date) self.thread.update_stats() if hasattr(artifact, 'update_stats'): artifact.update_stats() if self.text and not self.is_meta: g.director.create_activity(author, 'posted', self, target=artifact, related_nodes=[self.app_config.project], tags=['comment'])
def spam(self): self.status = 'spam' g.spam_checker.submit_spam(self.text, artifact=self, user=self.author()) session(self).flush(self) self.thread.update_stats()
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()
def approve(self, file_info=None, notify=True): if self.status == 'ok': return self.status = 'ok' 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') if notify: self.notify(file_info=file_info) artifact = self.thread.artifact or self.thread session(self).flush() self.thread.last_post_date = max( self.thread.last_post_date, self.mod_date) self.thread.update_stats() if hasattr(artifact, 'update_stats'): artifact.update_stats() if self.text: g.director.create_activity(author, 'posted', self, target=artifact, related_nodes=[self.app_config.project])
def add_post(self, **kw): """Helper function to avoid code duplication.""" p = self.post(**kw) p.commit(update_stats=False) session(self).flush(self) self.update_stats() if not self.first_post: self.first_post_id = p._id self.post_to_feed(p) return p
def new(cls, **props): '''Creates a new Thread instance, ensuring a unique _id.''' for i in range(5): try: thread = cls(**props) session(thread).flush(thread) return thread except DuplicateKeyError as err: log.warning('Got DuplicateKeyError: attempt #%s, trying again. %s', i, err) if i == 4: raise session(thread).expunge(thread) continue
def undo(self, prev_status): if prev_status in ('ok', 'pending'): self.status = prev_status session(self).flush(self) self.thread.update_stats()
def spam(self, submit_spam_feedback=True): self.status = 'spam' if submit_spam_feedback: g.spam_checker.submit_spam(self.text, artifact=self, user=self.author()) session(self).flush(self) self.thread.update_stats()
def delete(self): self.deleted = True session(self).flush(self) self.thread.update_stats()
def delete(self): self.deleted = True session(self).flush(self) self.thread.num_replies = max(0, self.thread.num_replies - 1)