Exemplo n.º 1
0
    def rootify_site(self, app, portal):
        print "Ensuring site is visible at '/'"

        if not "rootify" in app.objectIds():
            print "    Adding DTMLMethod 'rootify'..."
            app.addDTMLMethod('rootify', file="""
              <dtml-let stack="REQUEST['TraversalRequestNameStack']">
                <dtml-if "stack and stack[-1]=='zmi'">
                  <dtml-call "stack.pop()">
                  <dtml-call "REQUEST.setVirtualRoot('zmi')">
                <dtml-else>
                  <dtml-call "stack.append('%s')">
                </dtml-if>
              </dtml-let>
              """ % portal.getId())
        else:
            print "    Skipped adding DTMLMethod."

        if getAccessRule(app) != "rootify":
            print "    Adding AccessRule..."
            manage_addAccessRule(app, "rootify")
        else:
            print "    Skipped adding AccessRule."

        if not "SiteRoot" in portal.objectIds():
            print "    Adding SiteRoot..."
            manage_addSiteRoot(portal, title="SiteRoot", base="", path="/")
        else:
            print "    Skipped adding SiteRoot."

        transaction.savepoint()
Exemplo n.º 2
0
def create(app, admin_username="******"):
    out = []
    oids = app.objectIds()

    # these are the two set elements...
    # (accessRule.py external method and SiteRoot)
    eid = "accessRule.py"
    pid = "Plone"
    emod = "CMFPlone.accessRule"
    efn = "accessRule"
    sid = "SiteRoot"

    if pid in oids:
        out.append("A Plone site already exists")
        return out

    # 1 .get the admin user (dont bother making it, it's done before you
    #                        get a chance)

    acl_users = app.acl_users
    #    info = User.readUserAccessFile('inituser')
    #    if info:
    #        acl_users._doAddUser(info[0], info[1], ('manage',), [])

    user = acl_users.getUser(admin_username)
    if user:
        user = user.__of__(acl_users)
        newSecurityManager(None, user)
        out.append("Retrieved the admin user")
    else:
        out.append("Retrieving admin user failed")

    # 2. create the access rule external method
    if eid not in oids:
        # this is the actual access rule
        manage_addExternalMethod(app, eid, "Plone Access Rule", emod, efn)
        out.append("Added external method")
        # this sets the access rule
        manage_addAccessRule(app, eid)
        out.append("Set an access rule")
    ##         if user:
    ##             getattr(app, eid).changeOwnership(user)

    # 3. actually add in Plone
    if pid not in oids:
        factory = app.manage_addProduct["CMFPlone"]
        factory.addPloneSite(pid, create_userfolder=1)
        out.append("Added Plone")
    ##         if user:
    ##             getattr(app, pid).changeOwnership(user, recursive=1)

    # 4. adding the site root in
    plone = getattr(app, pid)
    if sid not in plone.objectIds():
        manage_addSiteRoot(plone)
        out.append("Added Site Root")
    ##         if user:
    ##             getattr(plone, sid).changeOwnership(user)

    # 5. add in products
    qit = plone.portal_quickinstaller

    products_to_install = ["kupu"]
    ids = [x["id"] for x in qit.listInstallableProducts(skipInstalled=1)]
    for product in products_to_install:
        if product in ids:
            qit.installProduct(product)

    # 6. commit
    transaction.commit()

    noSecurityManager()
    out.append("Finished")
    return out