def show_node(req): """ opens administration window with content """ p = req.path[1:].split("/") style = req.params.get("style", "") user = users.getUserFromRequest(req) v = {} v["user"] = user v["guestuser"] = config.get("user.guestuser") v["version"] = mediatum_version v["content"] = show_content(req, p[0]) v["navigation"] = adminNavigation() v["breadcrumbs"] = getMenuItemID(v["navigation"], req.path[1:]) v["spc"] = list() spc = list() v["spc"].append(Menu("sub_header_frontend", "/")) v["spc"].append(Menu("sub_header_edit", "/edit")) if user.isWorkflowEditor(): v["spc"].append(Menu("sub_header_workflow", "../publish")) v["spc"].append(Menu("sub_header_logout", "/logout")) v["hashelp"] = help.getHelpPath( ['admin', 'modules', req.path.split('/')[1]]) if len(p) > 0: if style == "": req.writeTAL("web/admin/frame.html", v, macro="frame") else: req.write(v["content"])
def show_node(req): """ opens administration window with content """ p = req.path[1:].split("/") style = req.params.get("style", u"") user = current_user v = {} v["user"] = user v["guestuser"] = get_guest_user().login_name v["version"] = core.__version__ v["content"] = show_content(req, p[0]) v["navigation"] = adminNavigation() v["breadcrumbs"] = getMenuItemID(v["navigation"], req.path[1:]) spc = [ Menu("sub_header_frontend", u"/"), Menu("sub_header_edit", u"/edit"), Menu("sub_header_logout", u"/logout") ] if user.is_workflow_editor: spc.append(Menu("sub_header_workflow", u"../publish/")) v["spc"] = spc if len(p) > 0: if style == "": req.writeTAL("web/admin/frame.html", v, macro="frame") else: req.write(v["content"])
def show_node(req): """ opens administration window with content """ p = req.path[1:].split("/") style = req.params.get("style", "") user = users.getUserFromRequest(req) v = {} v["user"] = user v["guestuser"] = config.get("user.guestuser") v["version"] = mediatum_version v["content"] = show_content(req, p[0]) v["navigation"] = adminNavigation() v["breadcrumbs"] = getMenuItemID(v["navigation"], req.path[1:]) v["spc"] = list() spc = list() v["spc"].append(Menu("sub_header_frontend", "/")) v["spc"].append(Menu("sub_header_edit", "/edit")) if user.isWorkflowEditor(): v["spc"].append(Menu("sub_header_workflow", "../publish")) v["spc"].append(Menu("sub_header_logout", "/logout")) v["hashelp"] = help.getHelpPath(['admin', 'modules', req.path.split('/')[1]]) if len(p) > 0: if style == "": req.writeTAL("web/admin/frame.html", v, macro="frame") else: req.write(v["content"])
def validate(req, op): v = {} items = [] for menu in adminNavigation(): itemdata = {} itemdata["name"] = menu.getName() itemdata["icon"] = adminModules[menu.getName()].getInformation("icon") itemdata["submenu"] = menu.getItemList() items.append(itemdata) v["navitems"] = items return req.getTAL("/web/admin/modules/menumain.html", v, macro="view")
def getAdminModuleHierarchy(): _menu = {} _menu[-1] = [] _items = {} adminMenus = adminNavigation() # activated menuitems for module in adminModules: if module.startswith("menu"): active = -1 for m in adminMenus: if m.getName() == module: active = adminMenus.index(m) break if active not in _menu.keys(): _menu[active] = [] _menu[active].append(module) else: active = -1 for m in adminMenus: items = m.getItemList() for item in items: if item == module: active = adminMenus.index(m) if active not in _items.keys(): _items[active] = [] _items[active].append((module, items.index(item))) break if active == -1: if active not in _items.keys(): _items[active] = [] _items[active].append((module, 0)) for key in _menu.keys(): if key in _items.keys(): items = _items[key] items.sort(lambda x, y: cmp(x[0], y[0])) for item in items: _menu[key].append(item[0]) return _menu
def validate(req, op): v = {} v["navigation"] = adminNavigation() return req.getTAL("/web/admin/modules/default.html", v, macro="view")
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 ])
def adminModuleActions(req): for key in req.params.keys(): root = q(Root).one() if key == "adminmodules_default": root.system_attrs["admin.menu"] = config.get("admin.defaultmenu", "") if not root.system_attrs["admin.menu"]: # load default admin.menu adminNavigation() break elif key.startswith("move|") and req.params.get(key) != "": # move item to menu dest = req.params.get(key) dest_id = -1 mod = key.split("|")[-1] items = getAdminModuleHierarchy() for k in items: if dest in items[k]: dest_id = k if mod in items[k]: items[k].remove(mod) items[dest_id].append(mod) ret = "" for k in items: if len(items[k]) == 0: pass elif items[k][0].startswith("menu"): ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" root.system_attrs["admin.menu"] = ret[:-1] elif key.startswith("hide|"): # hide module m = key[:-2].split("|")[-1] ret = "" items = getAdminModuleHierarchy() for k in items: if k >= 0 and not (m.startswith("menu") and items[k][0] == m): i = [item for item in items[k] if item != m] if len(i) > 1: ret += i[0] + "(" + ";".join(i[1:]) + ");" else: ret += i[0] + "();" root.system_attrs["admin.menu"] = ret[:-1] break elif key.startswith("show|"): # show module (menu) ret = "" m = key[:-2].split("|")[-1] items = getAdminModuleHierarchy() for k in items: if k >= 0: if len(items[k]) > 1: ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" else: ret += items[k][0] + "();" if m.startswith("menu"): ret += m + "()" elif len(ret) > 2: ret = ret[:-2] + ";" + m + ")" root.system_attrs["admin.menu"] = ret break elif key.startswith("up|"): # move module or module item up m = key[:-2].split("|")[-1] items = getAdminModuleHierarchy() for k in items: if m in items[k] and items[k].index(m) == 0: # menu src = items[k] items[k] = items[k - 1] items[k - 1] = src break elif m in items[k] and items[k].index > 0: # menu item src_id = items[k].index(m) items[k][src_id] = items[k][src_id - 1] items[k][src_id - 1] = m break ret = "" for k in items: if len(items[k]) == 0: pass elif items[k][0].startswith("menu"): ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" root.system_attrs["admin.menu"] = ret[:-1] break elif key.startswith("down|"): # move module or module item down m = key[:-2].split("|")[-1] items = getAdminModuleHierarchy() for k in items: if m in items[k] and items[k].index(m) == 0: # menu src = items[k] items[k] = items[k + 1] items[k + 1] = src break elif m in items[k] and items[k].index > 0: # menu item src_id = items[k].index(m) items[k][src_id] = items[k][src_id + 1] items[k][src_id + 1] = m break ret = "" for k in items: if len(items[k]) == 0: pass elif items[k][0].startswith("menu"): ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" root.system_attrs["admin.menu"] = ret[:-1] break db.session.commit()
def adminModuleActions(req): for key in req.params.keys(): root = q(Root).one() if key == "adminmodules_default": root.system_attrs["admin.menu"] = config.get( "admin.defaultmenu", "") if not root.system_attrs["admin.menu"]: # load default admin.menu adminNavigation() break elif key.startswith("move|") and req.params.get(key) != "": # move item to menu dest = req.params.get(key) dest_id = -1 mod = key.split("|")[-1] items = getAdminModuleHierarchy() for k in items: if dest in items[k]: dest_id = k if mod in items[k]: items[k].remove(mod) items[dest_id].append(mod) ret = "" for k in items: if len(items[k]) == 0: pass elif items[k][0].startswith("menu"): ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" root.system_attrs["admin.menu"] = ret[:-1] elif key.startswith("hide|"): # hide module m = key[:-2].split("|")[-1] ret = "" items = getAdminModuleHierarchy() for k in items: if k >= 0 and not (m.startswith("menu") and items[k][0] == m): i = [item for item in items[k] if item != m] if len(i) > 1: ret += i[0] + "(" + ";".join(i[1:]) + ");" else: ret += i[0] + "();" root.system_attrs["admin.menu"] = ret[:-1] break elif key.startswith("show|"): # show module (menu) ret = "" m = key[:-2].split("|")[-1] items = getAdminModuleHierarchy() for k in items: if k >= 0: if len(items[k]) > 1: ret += items[k][0] + "(" + ";".join( items[k][1:]) + ");" else: ret += items[k][0] + "();" if m.startswith("menu"): ret += m + "()" elif len(ret) > 2: ret = ret[:-2] + ";" + m + ")" root.system_attrs["admin.menu"] = ret break elif key.startswith("up|"): # move module or module item up m = key[:-2].split("|")[-1] items = getAdminModuleHierarchy() for k in items: if m in items[k] and items[k].index(m) == 0: # menu src = items[k] items[k] = items[k - 1] items[k - 1] = src break elif m in items[k] and items[k].index > 0: # menu item src_id = items[k].index(m) items[k][src_id] = items[k][src_id - 1] items[k][src_id - 1] = m break ret = "" for k in items: if len(items[k]) == 0: pass elif items[k][0].startswith("menu"): ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" root.system_attrs["admin.menu"] = ret[:-1] break elif key.startswith("down|"): # move module or module item down m = key[:-2].split("|")[-1] items = getAdminModuleHierarchy() for k in items: if m in items[k] and items[k].index(m) == 0: # menu src = items[k] items[k] = items[k + 1] items[k + 1] = src break elif m in items[k] and items[k].index > 0: # menu item src_id = items[k].index(m) items[k][src_id] = items[k][src_id + 1] items[k][src_id + 1] = m break ret = "" for k in items: if len(items[k]) == 0: pass elif items[k][0].startswith("menu"): ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");" root.system_attrs["admin.menu"] = ret[:-1] break db.session.commit()
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])