Esempio n. 1
0
def importfile(filename):
    global node
    child = xmlnode.readNodeXML(filename)
    if child:
        node.addChild(child)
    else:
        print "\tfile '%s' not found" % filename
Esempio n. 2
0
def importfile(filename):
    global node
    child = xmlnode.readNodeXML(filename)
    if child:
        node.addChild(child)
    else:
        print "\tfile '%s' not found" % filename
Esempio n. 3
0
def importMapping(filename):
    n = readNodeXML(filename)
    importlist = list()
    if n.getContentType() == "mapping":
        importlist.append(n)
    elif n.getContentType() == "mappings":
        for ch in n.getChildren():
            importlist.append(ch)

    mappings = tree.getRoot("mappings")
    for m in importlist:
        m.setName("import-" + m.getName())
        mappings.addChild(m)
Esempio n. 4
0
def importMetaSchema(filename):
    n = readNodeXML(filename)
    importlist = list()
    if n.getContentType() == "metadatatype":
        importlist.append(n)
    elif n.getContentType() == "metadatatypes":
        for ch in n.getChildren():
            importlist.append(ch)

    metadatatypes = tree.getRoot("metadatatypes")
    for m in importlist:
        m.setName("import-" + m.getName())
        metadatatypes.addChild(m)
Esempio n. 5
0
def importMapping(filename):
    n = readNodeXML(filename)
    importlist = list()
    if n.getContentType() == "mapping":
        importlist.append(n)
    elif n.getContentType() == "mappings":
        for ch in n.getChildren():
            importlist.append(ch)

    mappings = tree.getRoot("mappings")
    for m in importlist:
        m.setName("import-" + m.getName())
        mappings.addChild(m)
Esempio n. 6
0
def importWorkflow(filename):
    n = readNodeXML(filename)
    importlist = list()

    if n.getContentType() == "workflow":
        importlist.append(n)
    elif n.getContentType() == "workflows":
        for ch in n.getChildren():
            importlist.append(ch)
    workflows = tree.getRoot("workflows")
    for w in importlist:
        w.setName("import-" + w.getName())
        workflows.addChild(w)
Esempio n. 7
0
def importWorkflow(filename):
    n = readNodeXML(filename)
    importlist = list()

    if n.getContentType() == "workflow":
        importlist.append(n)
    elif n.getContentType() == "workflows":
        for ch in n.getChildren():
            importlist.append(ch)
    workflows = tree.getRoot("workflows")
    for w in importlist:
        w.setName("import-" + w.getName())
        workflows.addChild(w)
Esempio n. 8
0
def importMapping(filename):
    n = readNodeXML(filename)
    importlist = list()
    if n.getContentType() == "mapping":
        importlist.append(n)
    elif n.getContentType() == "mappings":
        for ch in n.children:
            importlist.append(ch)

    mappings = q(Mappings).one()
    for m in importlist:
        m.name = u"import-" + m.getName()
        mappings.children.append(m)
    db.session.commit()
Esempio n. 9
0
def importWorkflow(filename):
    n = readNodeXML(filename)
    importlist = list()

    if n.type == "workflow":
        importlist.append(n)
    elif n.type == "workflows":
        for ch in n.children:
            importlist.append(ch)
    workflows = q(Workflows).one()
    for w in importlist:
        w.name = "import_" + w.name
        workflows.children.append(w)
    db.session.commit()
Esempio n. 10
0
def importMapping(filename):
    n = readNodeXML(filename)
    importlist = list()
    if n.getContentType() == "mapping":
        importlist.append(n)
    elif n.getContentType() == "mappings":
        for ch in n.children:
            importlist.append(ch)

    mappings = q(Mappings).one()
    for m in importlist:
        m.name = u"import-" + m.getName()
        mappings.children.append(m)
    db.session.commit()
Esempio n. 11
0
def importWorkflow(filename):
    n = readNodeXML(filename)
    importlist = list()

    if n.type == "workflow":
        importlist.append(n)
    elif n.type == "workflows":
        for ch in n.children:
            importlist.append(ch)
    workflows = q(Workflows).one()
    for w in importlist:
        w.name = "import_" + w.name
        workflows.children.append(w)
    db.session.commit()
Esempio n. 12
0
def init_database_values(s, default_admin_password=None):
    from core import config
    from core import User, UserGroup, AuthenticatorInfo, AccessRule
    from core.systemtypes import Root, Metadatatypes, Mappings, Searchmasks
    from contenttypes import Collections, Home
    from workflow.workflow import Workflows
    from core.auth import INTERNAL_AUTHENTICATOR_KEY, create_password_hash
    from core.permission import get_or_add_access_rule
    from core.database.postgres.permission import AccessRuleset, AccessRulesetToRule, NodeToAccessRule
    from web.admin.adminutils import adminNavigation
    from core.xmlnode import readNodeXML
    """
    :type s: Session
    """

    # every database must have an everybody rule
    everybody_rule = AccessRule()
    s.add(everybody_rule)

    # node tree setup
    root = Root(u"root", id=1)
    metadatatypes = Metadatatypes(u"metadatatypes", id=3)
    workflows = Workflows(u"workflows", id=4)
    mappings = Mappings(u"mappings", id=9)
    collections = Collections(u"collections", schema=u"collection", id=10)
    collections.attrs[u"label"] = u"Collections"
    collections.access_rule_assocs.append(
        NodeToAccessRule(ruletype=u"read", rule=everybody_rule))
    home = Home(u"home", id=11)
    searchmasks = Searchmasks(u"searchmasks", id=15)

    root.children.extend(
        [metadatatypes, workflows, mappings, collections, home, searchmasks])

    # finally, add node tree. All nodes will be added automatically
    s.add(root)
    # activate menuitems metadatatypes, workflows etc.
    adminNavigation()
    logg.info(u"loaded initial values")

    # default users and groups setup
    # add internal authenticator
    auth_type, auth_name = INTERNAL_AUTHENTICATOR_KEY
    internal_auth = AuthenticatorInfo(id=0,
                                      auth_type=auth_type,
                                      name=auth_name)

    default_admin_password = config.get(u"user.default_admin_password",
                                        default_admin_password)
    if default_admin_password:
        admin_hash, admin_salt = create_password_hash(default_admin_password)
    else:
        # admin user cannot login when no default_admin_password is set
        admin_hash, admin_salt = None, None

    adminuser = User(login_name=config.get(u"user.adminuser", u"admin"),
                     password_hash=admin_hash,
                     salt=admin_salt,
                     email=u"admin@mediatum",
                     authenticator_info=internal_auth,
                     can_change_password=True)

    guestuser = User(login_name=config.get_guest_name(),
                     email=u"guest@mediatum",
                     authenticator_info=internal_auth)

    admingroup = UserGroup(name=config.get(u"user.admingroup",
                                           u"administration"),
                           is_workflow_editor_group=True,
                           is_editor_group=True,
                           is_admin_group=True)
    admingroup.users.append(adminuser)
    s.add(admingroup)
    guestgroup = UserGroup(name=u"guests")
    guestgroup.users.append(guestuser)
    s.add(guestgroup)

    # add rules for admingroup, guestgroup
    for usergroup in [admingroup, guestgroup]:
        rule = get_or_add_access_rule(group_ids=[usergroup.id])
        ruleset = AccessRuleset(name=usergroup.name,
                                description=usergroup.name)
        arr = AccessRulesetToRule(rule=rule)
        ruleset.rule_assocs.append(arr)

    # add example metadatatypes
    example_path_collection = os.path.join(config.basedir,
                                           u"examples/content/collection.xml")
    metadatatype_collection = readNodeXML(example_path_collection)

    example_path_directory = os.path.join(config.basedir,
                                          u"examples/content/directory.xml")
    metadatatype_directory = readNodeXML(example_path_directory)

    example_path_image = os.path.join(config.basedir,
                                      u"examples/content/image.xml")
    metadatatype_image = readNodeXML(example_path_image)

    example_path_document = os.path.join(config.basedir,
                                         u"examples/content/document.xml")
    metadatatype_document = readNodeXML(example_path_document)

    metadatatypes.children.extend([
        metadatatype_collection, metadatatype_directory, metadatatype_image,
        metadatatype_document
    ])
Esempio n. 13
0
def init_database_values(s, default_admin_password=None):
    from core import config
    from core import User, UserGroup, AuthenticatorInfo, AccessRule
    from core.systemtypes import Root, Metadatatypes, Mappings, Searchmasks
    from contenttypes import Collections, Home
    from workflow.workflow import Workflows
    from core.auth import INTERNAL_AUTHENTICATOR_KEY, create_password_hash
    from core.permission import get_or_add_access_rule
    from core.database.postgres.permission import AccessRuleset, AccessRulesetToRule, NodeToAccessRule
    from web.admin.adminutils import adminNavigation
    from core.xmlnode import readNodeXML

    """
    :type s: Session
    """

    # every database must have an everybody rule
    everybody_rule = AccessRule()
    s.add(everybody_rule)

    # node tree setup
    root = Root(u"root", id=1)
    metadatatypes = Metadatatypes(u"metadatatypes", id=3)
    workflows = Workflows(u"workflows", id=4)
    mappings = Mappings(u"mappings", id=9)
    collections = Collections(u"collections", schema=u"collection", id=10)
    collections.attrs[u"label"] = u"Collections"
    collections.access_rule_assocs.append(NodeToAccessRule(ruletype=u"read", rule=everybody_rule))
    home = Home(u"home", id=11)
    searchmasks = Searchmasks(u"searchmasks", id=15)

    root.children.extend([metadatatypes, workflows, mappings, collections, home, searchmasks])

    # finally, add node tree. All nodes will be added automatically
    s.add(root)
    # activate menuitems metadatatypes, workflows etc.
    adminNavigation()
    logg.info(u"loaded initial values")

    # default users and groups setup
    # add internal authenticator
    auth_type, auth_name = INTERNAL_AUTHENTICATOR_KEY
    internal_auth = AuthenticatorInfo(id=0, auth_type=auth_type, name=auth_name)

    default_admin_password = config.get(u"user.default_admin_password", default_admin_password)
    if default_admin_password:
        admin_hash, admin_salt = create_password_hash(default_admin_password)
    else:
        # admin user cannot login when no default_admin_password is set
        admin_hash, admin_salt = None, None

    adminuser = User(login_name=config.get(u"user.adminuser", u"admin"),
                     password_hash=admin_hash,
                     salt=admin_salt,
                     email=u"admin@mediatum",
                     authenticator_info=internal_auth,
                     can_change_password=True
                     )

    guestuser = User(login_name=config.get_guest_name(),
                     email=u"guest@mediatum",
                     authenticator_info=internal_auth
                     )

    admingroup = UserGroup(name=config.get(u"user.admingroup", u"administration"),
                           is_workflow_editor_group=True,
                           is_editor_group=True,
                           is_admin_group=True
                           )
    admingroup.users.append(adminuser)
    s.add(admingroup)
    guestgroup = UserGroup(name=u"guests")
    guestgroup.users.append(guestuser)
    s.add(guestgroup)

    # add rules for admingroup, guestgroup
    for usergroup in [admingroup, guestgroup]:
        rule = get_or_add_access_rule(group_ids=[usergroup.id])
        ruleset = AccessRuleset(name=usergroup.name, description=usergroup.name)
        arr = AccessRulesetToRule(rule=rule)
        ruleset.rule_assocs.append(arr)

    # add example metadatatypes
    example_path_collection = os.path.join(config.basedir, u"examples/content/collection.xml")
    metadatatype_collection = readNodeXML(example_path_collection)

    example_path_directory = os.path.join(config.basedir, u"examples/content/directory.xml")
    metadatatype_directory = readNodeXML(example_path_directory)

    example_path_image = os.path.join(config.basedir, u"examples/content/image.xml")
    metadatatype_image = readNodeXML(example_path_image)

    example_path_document = os.path.join(config.basedir, u"examples/content/document.xml")
    metadatatype_document = readNodeXML(example_path_document)

    metadatatypes.children.extend([metadatatype_collection, metadatatype_directory, metadatatype_image,
                                   metadatatype_document])