Esempio n. 1
0
 def fset(self, new_root_page_name):
     globals = WM.Globals.query.get(app_config_id=self.config._id)
     if globals is not None:
         globals.root = new_root_page_name
     elif new_root_page_name != self.default_root_page_name:
         globals = WM.Globals(app_config_id=self.config._id, root=new_root_page_name)
     if globals is not None:
         session(globals).flush()
Esempio n. 2
0
 def install(self, project):
     'Set up any default permissions and roles here'
     self.config.options['project_name'] = project.name
     super(ForgeWikiApp, self).install(project)
     # Setup permissions
     role_admin = M.ProjectRole.by_name('Admin')._id
     role_developer = M.ProjectRole.by_name('Developer')._id
     role_member = M.ProjectRole.by_name('Member')._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_member, 'create'),
         M.ACE.allow(role_member, 'edit'),
         M.ACE.allow(role_developer, 'delete'),
         M.ACE.allow(role_developer, 'moderate'),
         M.ACE.allow(role_admin, 'configure'),
         M.ACE.allow(role_admin, 'admin'),
     ]
     root_page_name = self.default_root_page_name
     WM.Globals(app_config_id=c.app.config._id, root=root_page_name)
     self.upsert_root(root_page_name, notify=False)
Esempio n. 3
0
def import_wiki(project, pid, nbhd):
    from forgewiki import model as WM

    def upload_attachments(page, pid, beginning):
        dirpath = os.path.join(options.output_dir, pid, 'wiki', beginning)
        if not os.path.exists(dirpath):
            return
        files = os.listdir(dirpath)
        for f in files:
            with open(os.path.join(options.output_dir, pid, 'wiki', beginning, f)) as fp:
                page.attach(f, fp, content_type=utils.guess_mime_type(f))
    pages = os.listdir(os.path.join(options.output_dir, pid, 'wiki'))
    # handle the homepage content
    if 'homepage_text.markdown' in pages:
        home_app = project.app_instance('home')
        h.set_context(project.shortname, 'home', neighborhood=nbhd)
        # set permissions and config options
        role_admin = M.ProjectRole.by_name('Admin')._id
        role_anon = M.ProjectRole.by_name('*anonymous')._id
        home_app.config.options['show_discussion'] = False
        home_app.config.options['show_left_bar'] = False
        home_app.config.options['show_right_bar'] = False
        home_app.config.acl = [
            M.ACE.allow(role_anon, 'read'),
            M.ACE.allow(role_admin, 'create'),
            M.ACE.allow(role_admin, 'edit'),
            M.ACE.allow(role_admin, 'delete'),
            M.ACE.allow(role_admin, 'moderate'),
            M.ACE.allow(role_admin, 'configure'),
            M.ACE.allow(role_admin, 'admin')]
        p = WM.Page.upsert('Home')
        p.text = wiki2markdown(load(pid, 'wiki', 'homepage_text.markdown'))
        upload_attachments(p, pid, 'homepage')
    if 'HomePage.json' in pages and 'HomePage.markdown' in pages:
        wiki_app = project.app_instance('wiki')
        if not wiki_app:
            wiki_app = project.install_app('Wiki', 'wiki')
        h.set_context(project.shortname, 'wiki', neighborhood=nbhd)
        # set permissions and config options
        role_admin = M.ProjectRole.by_name('Admin')._id
        role_anon = M.ProjectRole.by_name('*anonymous')._id
        wiki_app.config.options['show_discussion'] = False
        wiki_app.config.options['show_left_bar'] = False
        wiki_app.config.options['show_right_bar'] = False
        wiki_app.config.acl = [
            M.ACE.allow(role_anon, 'read'),
            M.ACE.allow(role_admin, 'create'),
            M.ACE.allow(role_admin, 'edit'),
            M.ACE.allow(role_admin, 'delete'),
            M.ACE.allow(role_admin, 'moderate'),
            M.ACE.allow(role_admin, 'configure'),
            M.ACE.allow(role_admin, 'admin')]
        # make all the wiki pages
        for page in pages:
            ending = page[-5:]
            beginning = page[:-5]
            markdown_file = '%s.markdown' % beginning
            if '.json' == ending and markdown_file in pages:
                page_data = loadjson(pid, 'wiki', page)
                content = load(pid, 'wiki', markdown_file)
                if page == 'HomePage.json':
                    globals = WM.Globals.query.get(
                        app_config_id=wiki_app.config._id)
                    if globals is not None:
                        globals.root = page_data.title
                    else:
                        globals = WM.Globals(
                            app_config_id=wiki_app.config._id, root=page_data.title)
                p = WM.Page.upsert(page_data.title)
                p.viewable_by = ['all']
                p.text = wiki2markdown(content)
                # upload attachments
                upload_attachments(p, pid, beginning)
                if not p.history().first():
                    p.commit()
    ThreadLocalORMSession.flush_all()