예제 #1
0
    def install(self, project):
        'Set up any default permissions and roles here'
        # Don't call super install here, as that sets up discussion for a tool

        # Setup permissions
        role_admin = M.ProjectRole.by_name('Admin')._id
        role_developer = M.ProjectRole.by_name('Developer')._id
        role_auth = M.ProjectRole.by_name('*authenticated')._id
        role_anon = M.ProjectRole.by_name('*anonymous')._id
        self.config.acl = [
            M.ACE.allow(role_anon, 'read'),
            M.ACE.allow(role_auth, 'post'),
            M.ACE.allow(role_auth, 'unmoderated_post'),
            M.ACE.allow(role_developer, 'moderate'),
            M.ACE.allow(role_admin, 'configure'),
            M.ACE.allow(role_admin, 'admin'),
        ]

        utils.create_forum(self, new_forum=dict(
            shortname='general',
            create='on',
            name='General Discussion',
            description='Forum about anything you want to talk about.',
            parent='',
            members_only=False,
            anon_posts=False,
            monitoring_email=None))
예제 #2
0
    def test_import_tool_forum_import_id(self, tlos, h, session, m, g, c):
        """ This method tests if an import id is added to a forum """

        importer = discussion.ForgeDiscussionImporter()

        # Test with import id
        import_id = "qwert258"
        _json = {
            "forums": [{
                "description": "Forum about anything you want to talk about.",
                "shortname": "general",
                "name": "General Discussion",
                "import_id": import_id,
                "threads": []
            }]
        }

        importer._load_json = mock.Mock(return_value=_json)
        importer.add_posts = mock.Mock()
        importer._clear_forums = mock.Mock()

        project, user = mock.Mock(), mock.Mock()
        app = project.install_app.return_value
        app.config.options.mount_point = 'mount_point'
        app.config.options.import_id = {'source': 'Allura'}
        app.config.options.get = lambda *a: getattr(app.config.options, *a)
        app.url = 'foo'
        app.forums = []

        forum = mock.Mock()
        utils.create_forum = mock.Mock(return_value=forum)
        forum.get_discussion_thread.return_value = (mock.Mock(), mock.Mock())

        utils.create_forum.return_value = forum

        g.post_event = mock.Mock()
        m.AuditLog.log = mock.Mock()

        importer.import_tool(project, user, 'mount_point', 'mount_label')

        self.assertEqual(import_id, forum.import_id)

        # Test without import id
        _json = {
            "forums": [{
                "description": "Forum about anything you want to talk about.",
                "shortname": "general",
                "name": "General Discussion",
                "threads": []
            }]
        }

        importer._load_json = mock.Mock(return_value=_json)
        forum = mock.Mock()
        forum.import_id = ''
        utils.create_forum(return_value=forum)

        importer.import_tool(project, user, 'mount_point', 'mount_label')

        self.assertEqual('', forum.import_id)
예제 #3
0
 def add_forum_short(self, add_forum=None, **kw):
     require_access(c.app, 'configure')
     f = utils.create_forum(c.app, add_forum)
     redirect(f.url())
예제 #4
0
 def add_forum(self, add_forum=None, **kw):
     f = utils.create_forum(self.app, add_forum)
     redirect(f.url())
예제 #5
0
 def add_forum_short(self, add_forum=None, **kw):
     require_access(c.app, 'configure')
     f = utils.create_forum(c.app, add_forum)
     redirect(f.url())
예제 #6
0
    def import_tool(self,
                    project,
                    user,
                    mount_point=None,
                    mount_label=None,
                    **kw):
        discussion_json = self._load_json(project)

        mount_point = mount_point or 'discussion'
        mount_label = mount_label or 'Discussion'

        app = project.install_app('discussion',
                                  mount_point,
                                  mount_label,
                                  import_id={'source': self.source})
        ThreadLocalORMSession.flush_all()

        with h.push_config(c, app=app):

            # Deleting the forums that are created by default
            self._clear_forums(app)

            try:
                M.session.artifact_orm_session._get().skip_mod_date = True

                for forum_json in discussion_json['forums']:

                    new_forum = dict(
                        app_config_id=app.config._id,
                        shortname=forum_json['shortname'],
                        description=forum_json['description'],
                        name=forum_json['name'],
                        create='on',
                        parent='',
                        members_only=False,
                        anon_posts=False,
                        monitoring_email=None,
                    )

                    forum = utils.create_forum(app, new_forum=new_forum)

                    if "import_id" in list(forum_json.keys()):
                        forum.import_id = forum_json["import_id"]

                    for thread_json in forum_json["threads"]:
                        thread = forum.get_discussion_thread(
                            dict(headers=dict(
                                Subject=thread_json['subject'])))[0]

                        if "import_id" in thread_json:
                            thread.import_id = thread_json["import_id"]

                        self.add_posts(thread, thread_json['posts'], app)

                    session(forum).flush(forum)
                    session(forum).expunge(forum)

                M.AuditLog.log(
                    "import tool %s from exported Allura JSON" %
                    (app.config.options.mount_point, ),
                    project=project,
                    user=user,
                    url=app.url,
                )

                g.post_event('project_updated')
                ThreadLocalORMSession.flush_all()
                return app
            except Exception:
                h.make_app_admin_only(app)
                raise
            finally:
                M.session.artifact_orm_session._get().skip_mod_date = False