Пример #1
0
 def register_neighborhood_project(self, neighborhood, users, allow_register=False):
     from allura import model as M
     shortname = '--init--'
     name = 'Home Project for %s' % neighborhood.name
     p = M.Project(neighborhood_id=neighborhood._id,
                   shortname=shortname,
                   name=name,
                   short_description='',
                   description=(
                       'You can edit this description in the admin page'),
                   homepage_title = '# ' + name,
                   last_updated = datetime.utcnow(),
                   is_nbhd_project=True,
                   is_root=True)
     try:
         p.configure_project(
             users=users,
             is_user_project=False,
             apps=[
                 ('Wiki', 'wiki', 'Wiki'),
                 ('admin', 'admin', 'Admin')])
     except:
         ThreadLocalORMSession.close_all()
         log.exception('Error registering project %s' % p)
         raise
     if allow_register:
         role_auth = M.ProjectRole.authenticated(p)
         security.simple_grant(p.acl, role_auth._id, 'register')
         state(p).soil()
     return p
Пример #2
0
 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'])
Пример #3
0
 def register_neighborhood_project(self, neighborhood, users, allow_register=False):
     from allura import model as M
     shortname = '--init--'
     name = 'Home Project for %s' % neighborhood.name
     database_uri = M.Project.default_database_uri(shortname)
     p = M.Project(neighborhood_id=neighborhood._id,
                 shortname=shortname,
                 name=name,
                 short_description='',
                 description=('You can edit this description in the admin page'),
                 homepage_title = '# ' + name,
                 database_uri=database_uri,
                 last_updated = datetime.utcnow(),
                 is_nbhd_project=True,
                 is_root=True)
     try:
         p.configure_project(
             users=users,
             is_user_project=False,
             apps=[
                 ('Wiki', 'wiki', 'Wiki'),
                 ('admin', 'admin', 'Admin')])
     except:
         ThreadLocalORMSession.close_all()
         log.exception('Error registering project %s' % p)
         raise
     if allow_register:
         role_auth = M.ProjectRole.authenticated(p)
         security.simple_grant(p.acl, role_auth._id, 'register')
         state(p).soil()
     return p
Пример #4
0
 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])
Пример #5
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()
Пример #6
0
 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])