def search_nodes(query, mapping_prefix='Z3950_search_'): """ Search nodes that match the query. 'query' is a tree of QueryBoolNode and QueryMatchNode objects. Query root nodes are configured by a naming convention. The names of mappings that starting with the given 'mapping_prefix' must end with a node ID, which is then used as root node for the search based on that field mapping. """ # find root nodes and their mappings roots_and_mappings = [] for mapping_node in mapping.getMappings(): name = mapping_node.getName() if not name.startswith(mapping_prefix): continue try: node_id = name[len(mapping_prefix):] roots_and_mappings.append((tree.getNode(node_id), mapping_node)) except tree.NoSuchNodeError: logg.error( "Configuration problem detected: Z39.50 search mapping '%s' found, " "but no matching root node with ID '%s'", name, node_id) if not roots_and_mappings: logg.info('no mappings configured, skipping search') return [] logg.debug('using mapping roots: %s', [(n1.id, n2.id) for (n1, n2) in roots_and_mappings]) # run one search per root node node_ids = [] guestaccess = acl.AccessData( user=users.getUser(config.get('user.guestuser'))) for root_node, mapping_node in roots_and_mappings: # map query fields to node attributes field_mapping = {} for field in mapping_node.getChildren(): field_mapping[field.getName()] = field.getDescription().split(';') # FIXME: this is redundant - why build an infix query string # just to parse it afterwards? query_string = query.build_query_string(field_mapping) if query_string is None: logg.info('unable to map query: [%r] using mapping %s', query, field_mapping) continue logg.info('executing query: %s', query_string) for n in root_node.search(query_string): if guestaccess.hasReadAccess(n): node_ids.append(n.id) #node_ids.append( root_node.search(query_string).getIDs() ) # use a round-robin algorithm to merge the separate query results # in order to produce maximally diverse results in the first hits # return merge_ids_as_round_robin(node_ids) return node_ids
def initSetList(req=None): global SET_LIST if req: access = acl.AccessData(req) else: import core.users as users access = acl.AccessData(user=users.getUser('Gast')) oaisets.loadGroups() SET_LIST = oaisets.GROUPS OUT('OAI: initSetList: found %s set groups: %s' % (len(SET_LIST), str(SET_LIST))) if DEBUG: timetable_update(req, "leaving initSetList")
def _prepareData(self, req, words=""): access = acl.AccessData(req) mask = self.getFullView(lang(req)) obj = {'deleted': False, 'access': access} node = self if self.get('deleted') == 'true': node = self.getActiveVersion() obj['deleted'] = True for filenode in node.getFiles(): if filenode.getType() in ["original", "video"]: obj["file"] = "/file/%s/%s" % (node.id, filenode.getName()) break if mask: obj['metadata'] = mask.getViewHTML( [node], VIEW_HIDE_EMPTY, lang(req), mask=mask) # hide empty elements else: obj['metadata'] = [] obj['node'] = node obj['path'] = req.params.get("path", "") obj['canseeoriginal'] = access.hasAccess(node, "data") return obj
def _prepareData(self, req): access = acl.AccessData(req) mask = self.getFullView(lang(req)) obj = {'deleted': False, 'access': access} node = self if self.get('deleted') == 'true': node = self.getActiveVersion() obj['deleted'] = True if mask: obj['metadata'] = mask.getViewHTML( [node], VIEW_HIDE_EMPTY, lang(req), mask=mask) # hide empty elements else: obj['metadata'] = [] obj['node'] = node obj['path'] = req and req.params.get("path", "") or "" obj['audiothumb'] = '/thumb2/{}'.format(node.id) if node.has_object(): obj['canseeoriginal'] = access.hasAccess(node, "data") obj['audiolink'] = '/file/{}/{}'.format(node.id, node.getName()) obj['audiodownload'] = '/download/{}/{}'.format( node.id, node.getName()) else: obj['canseeoriginal'] = False return obj
def GetRecord(req): access = acl.AccessData(req) if "identifier" in req.params: id = identifier2id(req.params.get("identifier")) else: return writeError(req, "badArgument") metadataformat = req.params.get("metadataPrefix", None) if not checkMetaDataFormat(metadataformat): return writeError(req, "badArgument") try: node = tree.getNode(id) except (TypeError, KeyError, tree.NoSuchNodeError): return writeError(req, "idDoesNotExist") if metadataformat and (metadataformat.lower() in FORMAT_FILTERS.keys()) and not filterFormat( node, metadataformat.lower()): return writeError(req, "noPermission") if parentIsMedia(node): return writeError(req, "noPermission") if not access.hasReadAccess(node): return writeError(req, "noPermission") req.write('<GetRecord>') writeRecord(req, node, metadataformat) req.write('</GetRecord>') if DEBUG: timetable_update(req, "leaving GetRecord")
def adduseropts(user): ret = [] dtypes = {} for scheme in filter(lambda x: x.isActive(), acl.AccessData(user=user).filter(loadTypesFromDB())): for dtype in scheme.getDatatypes(): if dtype not in dtypes.keys(): dtypes[dtype] = [] if scheme not in dtypes[dtype]: dtypes[dtype].append(scheme) i = [x.getLongName() for x in dtypes['image']] i.sort() field = tree.Node("ftp.type_image", "metafield") field.set("label", "ftp_image_schema") field.set("type", "list") field.set("valuelist", "\r\n".join(i)) ret.append(field) d = [x.getLongName() for x in dtypes['document']] d.sort() field = tree.Node("ftp.type_document", "metafield") field.set("label", "ftp_document_schema") field.set("type", "list") field.set("valuelist", "\r\n".join(d)) ret.append(field) return ret
def _prepareData(self, req, words=""): access = acl.AccessData(req) mask = self.getFullView(lang(req)) obj = {'deleted': False, 'access': access} node = self if self.get('deleted') == 'true': node = self.getActiveVersion() obj['deleted'] = True if mask: obj['metadata'] = mask.getViewHTML( [node], VIEW_HIDE_EMPTY, lang(req), mask=mask) # hide empty elements else: obj['metadata'] = [] obj['node'] = node obj['path'] = req and req.params.get("path", "") or "" files, sum_size = filebrowser(node, req) obj['attachment'] = files obj['sum_size'] = sum_size obj['bibtex'] = False if node.getMask("bibtex"): obj['bibtex'] = True if node.has_object(): obj['canseeoriginal'] = access.hasAccess(node, "data") if node.get('system.origname') == "1": obj['documentlink'] = '/doc/{}/{}'.format( node.id, node.getName()) obj['documentdownload'] = '/download/{}/{}'.format( node.id, node.getName()) else: obj['documentlink'] = '/doc/{}/{}.pdf'.format(node.id, node.id) obj['documentdownload'] = '/download/{}/{}.pdf'.format( node.id, node.id) else: obj['canseeoriginal'] = False obj['documentthumb'] = '/thumb2/{}'.format(node.id) if "oogle" not in (req.get_header("user-agent") or ""): obj['print_url'] = '/print/{}'.format(node.id) else: # don't confuse search engines with the PDF link obj['print_url'] = None obj['documentdownload'] = None if "style" in req.params.keys(): req.session["full_style"] = req.params.get("style", "full_standard") elif "full_style" not in req.session.keys(): if "contentarea" in req.session.keys(): col = req.session["contentarea"].collection req.session["full_style"] = col.get("style_full") else: req.session["full_style"] = "full_standard" obj['parentInformation'] = self.getParentInformation(req) obj['style'] = req.session["full_style"] return obj
def show_node_big(node, req, template="workflow/workflow.html", macro="object_list"): access = acl.AccessData(req) if not access.hasWriteAccess(node): return '<i>' + t(lang(req), "permission_denied") + '</i>' return req.getTAL( template, { "workflow": node, "access": access, "search": req.params.get( "workflow_search", ""), "items": workflowSearch( [node], req.params.get( "workflow_search", ""), access), "getStep": getNodeWorkflowStep, "format_date": formatItemDate}, macro=macro)
def __init__(self, field, value="", width=400, name="", lock=0, language=None, collection=None, user=None, ip=""): self.field = field self.value = value self.width = width self.name = name self.language = language self.collection = collection self.ip = ip self.user = user self.access = acl.AccessData(user=user) self.lock = lock
def show_workflow_step(self, req): access = acl.AccessData(req) if not access.hasWriteAccess(self): return '<i>' + t(lang(req), "permission_denied") + '</i>' c = [] for item in self.getChildren(): c.append({"id": str(item.id), "creationtime": date.format_date( date.parse_date(item.get('creationtime')), 'dd.mm.yyyy HH:MM:SS'), "name": item.getName()}) c.sort(lambda x, y: cmp(x['name'], y['name'])) return req.getTAL("workflow/workflow.html", {"children": c, "workflow": self.getParents()[ 0], "step": self, "nodelink": "/mask?id=" + self.id + "&obj=", 'currentlang': lang(req)}, macro="workflow_show")
def _prepareData(self, req): mask = self.getFullView(lang(req)) tif = "" try: tifs = req.session["fullresolutionfiles"] except: tifs = [] access = acl.AccessData(req) if access.hasAccess(self, "data"): for f in self.getFiles(): if f.getType() == "original": if self.get('system.origname') == "1": tif = self.getName() else: tif = f.getName() if self.get("archive_path") != "": tif = "file/" + str(self.id) + "/" + self.get("archive_path") files, sum_size = filebrowser(self, req) obj = {'deleted': False, 'access': access} node = self if self.get('deleted') == 'true': node = self.getActiveVersion() obj['deleted'] = True obj['path'] = req and req.params.get("path", "") or "" obj['attachment'] = files obj['sum_size'] = sum_size obj['metadata'] = mask.getViewHTML( [node], VIEW_HIDE_EMPTY) # hide empty elements obj['node'] = node obj['tif'] = tif obj['zoom'] = dozoom(node) obj['tileurl'] = "/tile/{}/".format(node.id) obj['canseeoriginal'] = access.hasAccess(node, "data") obj['originallink'] = "getArchivedItem('{}/{}')".format(node.id, tif) obj['archive'] = node.get('archive_type') if "style" in req.params.keys(): req.session["full_style"] = req.params.get("style", "full_standard") elif "full_style" not in req.session.keys(): if "contentarea" in req.session.keys(): col = req.session["contentarea"].collection req.session["full_style"] = col.get("style_full") else: req.session["full_style"] = "full_standard" obj['style'] = req.session["full_style"] return obj
def show_node_big(node, req, template="workflow/workflow.html", macro="workflowlist"): access = acl.AccessData(req) list = [] for workflow in getWorkflowList(): if access.hasWriteAccess(workflow): list += [workflow] return req.getTAL( template, { "list": list, "search": req.params.get( "workflow_search", ""), "items": workflowSearch( list, req.params.get( "workflow_search", ""), access), "getStep": getNodeWorkflowStep, "format_date": formatItemDate}, macro=macro)
def getContent(req, ids): if len(ids) > 0: ids = ids[0] user = users.getUserFromRequest(req) node = tree.getNode(ids) access = acl.AccessData(req) if "statsfiles" in users.getHideMenusForUser( user) or not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if "update_stat" in req.params.keys(): # reset stored statistics data msg = "user %r requests update of of system.statscontent for node %r (%r, %r)" % ( user.getName(), node.id, node.name, node.type) logger.info(msg) logging.getLogger('editor').info(msg) node.removeAttribute("system.statscontent") node.removeAttribute("system.statsdate") # content if req.params.get("style", "") == "popup": statstring = node.get("system.statscontent") if statstring == "": # load stats from objects/renew stat data = StatTypes() for n in node.getAllChildren(): found_dig = 0 or len([ file for file in n.getFiles() if file.type in ["image", "document", "video"] ]) data.addItem(n.getContentType(), n.getSchema(), found_dig) node.set("system.statscontent", str(data)) node.set("system.statsdate", str(format_date())) statstring = str(data) v = {} v["data"] = StatTypes(statstring) v["stand"] = node.get("system.statsdate") req.writeTAL("web/edit/modules/statsfiles.html", v, macro="edit_stats_popup") return "" return req.getTAL("web/edit/modules/statsfiles.html", {"id": ids}, macro="edit_stats")
def getContent(req, ids): if len(ids) > 0: ids = ids[0] user = users.getUserFromRequest(req) node = tree.getNode(ids) access = acl.AccessData(req) if "statsaccess" in users.getHideMenusForUser( user) or not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if req.params.get("style", "") == "popup": getPopupWindow(req, ids) return "" node = tree.getNode(ids) statfiles = {} p = "" for file in node.getFiles(): if file.getType() == "statistic": period, type = getPeriod(file.retrieveFile()) if period > p: p = period if type not in statfiles.keys(): statfiles[type] = {} if period not in statfiles[type].keys(): statfiles[type][period] = [] statfiles[type][period].append(file) v = {} v["id"] = ids v["files"] = statfiles v["current_period"] = req.params.get("select_period", "frontend_" + p) if len(statfiles) > 0: v["current_file"] = StatisticFile(statfiles[v["current_period"].split( "_")[0]][v["current_period"].split("_")[1]][0]) else: v["current_file"] = StatisticFile(None) v["nodename"] = tree.getNode items = v["current_file"].getProgress('country') return req.getTAL("web/edit/modules/statsaccess.html", v, macro="edit_stats")
def _prepareData(self, req, words=""): access = acl.AccessData(req) mask = self.getFullView(lang(req)) obj = {'deleted': False, 'access': access} node = self if self.get('deleted') == 'true': node = self.getActiveVersion() obj['deleted'] = True if mask: obj['metadata'] = mask.getViewHTML([node], VIEW_HIDE_EMPTY, lang(req), mask=mask) # hide empty elements else: obj['metadata'] = [] obj['node'] = node obj['path'] = req.params.get("path", "") return obj
def show_node_big(self, req, template="", macro=""): mask = self.getFullView(lang(req)) access = acl.AccessData(req) if template == "": styles = getContentStyles("bigview", contenttype=self.getContentType()) if len(styles) >= 1: template = styles[0].getTemplate() # hide empty elements}, macro) return req.getTAL( template, { 'node': self, 'metadata': mask.getViewHTML([self], VIEW_HIDE_EMPTY), 'format_size': format_filesize, 'access': access })
def getContent(req, ids): user = users.getUserFromRequest(req) access = AccessData(user=user) language = lang(req) node = tree.getNode(ids[0]) if not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if req.params.get("upload")=="uploadfile": # try to import file return import_new(req) v = {"error":req.params.get("error")} class SortChoice: def __init__(self, label, value): self.label = label self.value = value col = node if "globalsort" in req.params: col.set("sortfield", req.params.get("globalsort")) v['collection_sortfield'] = col.get("sortfield") sortfields = [SortChoice(t(req,"off"),"")] if col.type not in ["root", "collections", "home"]: for ntype, num in col.getAllOccurences(acl.AccessData(req)).items(): if ntype.getSortFields(): for sortfield in ntype.getSortFields(): sortfields += [SortChoice(sortfield.getLabel(), sortfield.getName())] sortfields += [SortChoice(sortfield.getLabel()+t(req,"descending"), "-"+sortfield.getName())] break v['sortchoices'] = sortfields v['ids'] = ids v['count'] = len(node.getContentChildren()) v['nodelist'] = showdir(req, node) v['language'] = lang(req) v['t'] = t _html = req.getTAL("web/edit/modules/imports.html", v, macro="upload_form") return _html
def ListMetadataFormats(req): if "set" in req.params: return writeError(req, "badArgument") # supported oai metadata formats are configured in section # oai.formats in the mediatum.cfg file d = config.getsubset('oai') formats = [x.strip() for x in d['formats'].split(',') if x.strip()] if "identifier" in req.params: # list only formats available for the given identifier try: node = tree.getNode(identifier2id(req.params.get("identifier"))) except (TypeError, KeyError, tree.NoSuchNodeError): return writeError(req, "badArgument") access = acl.AccessData(req) if not access.hasReadAccess(node): return writeError(req, "noPermission") formats = [x for x in formats if nodeHasOAIExportMask(node, x.lower())] formats = [x for x in formats if filterFormat(node, x.lower())] # write xml for metadata formats list req.write('\n <ListMetadataFormats>\n') for mdf in formats: try: req.write(""" <metadataFormat> <metadataPrefix>%s</metadataPrefix> <schema>%s</schema> <metadataNamespace>%s</metadataNamespace> </metadataFormat> """ % (mdf, d["schema.%s" % mdf], d["namespace.%s" % mdf])) except: OUT( "%s: OAI error reading oai metadata format %s from config file" % (__file__, mdf), 'error') req.write('\n</ListMetadataFormats>') if DEBUG: timetable_update(req, "leaving ListMetadataFormats")
def f(req, node, objnum, link, indent, type): access = acl.AccessData(req) indent *= 10 nodename = node.name try: nodename = node.getLabel() except: log.logException() if type == 1: link = req.makeSelfLink({"tree_unfold": "", "tree_fold": node.id}) + "#node{}".format(node.id) elif type == 2: link = req.makeSelfLink({"tree_unfold": node.id, "tree_fold": ""}) + "#node{}".format(node.id) v = {} v["id"] = str(node.id) v["type"] = type v["link1"] = link v["indent"] = indent + 10 v["nodename"] = nodename v["writeaccess"] = access.hasWriteAccess(node) return req.getTAL("web/edit/modules/frontendparts.html", v, macro="edit_frontendparts_nodeselection")
def getContent(req, ids): user = users.getUserFromRequest(req) if "lza" in users.getHideMenusForUser(user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") v = {} v['error'] = "" nodes = [] for id in ids: node = tree.getNode(id) access = acl.AccessData(req) if not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") nodes.append(node) if "createlza" in req.params: # remove old file if existing for f in node.getFiles(): if f.getType() == "lza": node.removeFile(f) # create new file for f in node.getFiles(): if f.getType() in ("original", "document"): try: archive = l.LZA(f.retrieveFile()) schema = node.getSchema() # test for lza export mask if (getMetaType(schema).getMask("lza")): m = getMetaType(schema).getMask("lza") meta = l.LZAMetadata(m.getViewHTML([node], 8)) else: # generate error message meta = l.LZAMetadata(""" <?xpacket begin="\xef\xbb\xbf" id="mediatum_metadata"?> <lza:data> <lza:error>-definition missing-</lza:error> </lza:data><?xpacket end="w"?> """) archive.writeMediatumData(meta) node.addFile( tree.FileNode(archive.buildLZAName(), "lza", f.getMimeType())) except l.FiletypeNotSupported: v['error'] = "edit_lza_wrongfiletype" elif "removelza" in req.params: for f in node.getFiles(): if f.getType() == "lza": node.removeFile(f) v['id'] = req.params.get("id", "0") v['tab'] = req.params.get("tab", "") v['ids'] = ids v['nodes'] = nodes v['t'] = t v['language'] = lang(req) meta = {} for id in ids: node = tree.getNode(id) for f in node.getFiles(): if f.getType() == "lza": try: archive = l.LZA(f.retrieveFile(), f.getMimeType()) meta[id] = archive.getMediatumData() except IOError: v['error'] = "edit_lza_ioerror" v['meta'] = meta return req.getTAL("web/edit/modules/lza.html", v, macro="edit_lza")
def getContent(req, ids): if len(ids) > 0: ids = ids[0] node = tree.getNode(ids) access = acl.AccessData(req) if not node or node.getContentType() != "collections" or not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if "action" in req.params: if req.params.get("action") == "translate": # translation req.writeTALstr('<tal:block tal:content="key" i18n:translate=""/>', {"key": req.params.get("key")}) if req.params.get("action") == "nodeselection": # tree popup for node selection def f(req, node, objnum, link, indent, type): access = acl.AccessData(req) indent *= 10 nodename = node.name try: nodename = node.getLabel() except: log.logException() if type == 1: link = req.makeSelfLink({"tree_unfold": "", "tree_fold": node.id}) + "#node{}".format(node.id) elif type == 2: link = req.makeSelfLink({"tree_unfold": node.id, "tree_fold": ""}) + "#node{}".format(node.id) v = {} v["id"] = str(node.id) v["type"] = type v["link1"] = link v["indent"] = indent + 10 v["nodename"] = nodename v["writeaccess"] = access.hasWriteAccess(node) return req.getTAL("web/edit/modules/frontendparts.html", v, macro="edit_frontendparts_nodeselection") content = writetree(req, tree.getRoot("collections"), f, "", openednodes=[], sessionkey="nodetree", omitroot=0) req.writeTAL("web/edit/modules/frontendparts.html", {"content": content}, macro="edit_frontendparts_nodepopup") if req.params.get("action") == "iconselection": # image popup for image selection icons = [] for p in athana.getFileStorePaths("/img/"): for root, dirs, files in os.walk(os.path.join(config.basedir, p)): for name in [f for f in files if (f.endswith(".gif") or f.endswith(".png") or f.endswith(".jpg"))]: if "CVS" not in root and not "web/admin/img" in root and not "web/edit/img" in root: try: pic = Image.open(root + name) dimension = "%sx%spx" % (pic.size) icons.append((name, dimension)) except: pass req.writeTAL("web/edit/modules/frontendparts.html", {"icons": icons}, macro="edit_frontendparts_iconpopup") return "" if "do_action" in req.params: c = do_action(req, node) if c != "": return c v = {} v["id"] = node.id v["header_content"] = req.getTAL( "web/edit/modules/frontendparts.html", {"items": node.getCustomItems("header"), "type": "header"}, macro="frontendparts_section") v["footer_left_content"] = req.getTAL("web/edit/modules/frontendparts.html", {"items": node.getCustomItems("footer_left"), "type": "footer_left"}, macro="frontendparts_section") v["footer_right_content"] = req.getTAL("web/edit/modules/frontendparts.html", {"items": node.getCustomItems("footer_right"), "type": "footer_right"}, macro="frontendparts_section") return req.getTAL("web/edit/modules/frontendparts.html", v, macro="edit_frontendparts")
def getContent(req, ids): user = users.getUserFromRequest(req) node = tree.getNode(ids[0]) access = acl.AccessData(req) if not access.hasWriteAccess( node) or "changeschema" in users.getHideMenusForUser(user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") error = req.params.get("error") currentContentType = node.getContentType() try: currentSchema = node.type.split('/')[1] # string except: currentSchema = '' currentCategoryName = node.getCategoryName() currentTypeAlias = node.getTypeAlias() schemes = AccessData(req).filter(loadTypesFromDB()) _schemes = [] for scheme in schemes: if scheme.isActive(): _schemes.append(scheme) schemes = _schemes schemeNames2LongNames = {'': ''} for s in schemes: schemeNames2LongNames[s.getName()] = s.getLongName() try: currentSchemaLongName = schemeNames2LongNames[currentSchema] except KeyError: currentSchemaLongName = '' # find out which schema allows which datatype, and hence, # which overall data types we should display dtypes = [] datatypes = loadAllDatatypes() for scheme in schemes: for dtype in scheme.getDatatypes(): if dtype not in dtypes: for t in datatypes: if t.getName() == dtype and not elemInList( dtypes, t.getName()): dtypes.append(t) dtypes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) admissible_objtypes = getTypes(datatypes) admissible_datatypes = [ n for n in admissible_objtypes if tree.Node('', n.name).getCategoryName() in ['document', 'image', 'video', 'audio'] ] admissible_containers = [ n for n in admissible_objtypes if tree.Node('', n.name).getCategoryName() in ['container'] ] admissible_objtypes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) admissible_datatypes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) admissible_containers.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) available_schemes = [ s for s in schemes if currentContentType in s.getDatatypes() ] # filter schemes for special datatypes if req.params.get("objtype", "") != "": _schemes = [] for scheme in schemes: if req.params.get("objtype", "") in scheme.getDatatypes(): _schemes.append(scheme) schemes = _schemes schemes.sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) newObjectType = req.params.get("objtype") newSchema = req.params.get("schema") if not newSchema: newSchema = '' newType = newObjectType if newSchema: newType += '/' + newSchema oldType = currentContentType if currentSchema: oldType = oldType + '/' + currentSchema if newType != oldType: node.setTypeName(newType) msg = "%s changed node schema for node %s '%s' from '%s' to '%s'" % ( user.name, node.id, node.name, oldType, newType) logger.info(msg) logging.getLogger('usertracing').info(msg) node.setDirty() # cache clean / reload because object type changed tree.remove_from_nodecaches(node) node = tree.getNode(node.id) currentContentType = node.getContentType() currentSchema = newSchema currentSchemaLongName = schemeNames2LongNames[currentSchema] currentCategoryName = node.getCategoryName() currentTypeAlias = node.getTypeAlias() available_schemes = [ s for s in schemes if newObjectType in s.getDatatypes() ] isContainer = False if hasattr(node, "isContainer"): isContainer = node.isContainer() if "action" in req.params.keys(): if req.params.get("action").startswith("get_schemes_for_"): newObjectType = req.params.get("action").replace( "get_schemes_for_", "") available_schemes = [ s for s in schemes if newObjectType in s.getDatatypes() ] req.writeTAL("web/edit/modules/changeschema.html", { 'schemes': available_schemes, 'currentSchema': currentSchema }, macro="changeschema_selectscheme") return "" containers = getContainers(datatypes) d = {"id": req.params.get("id"), "error": error, "node": node} d['currentContentType'] = currentContentType d['currentSchema'] = currentSchema d['currentSchemaLongName'] = currentSchemaLongName d['currentCategoryName'] = currentCategoryName d['currentTypeAlias'] = currentTypeAlias d['isContainer'] = int(isContainer) d['nodes'] = [node] if currentContentType in [dtype.name for dtype in containers]: d['schemes'] = [] d['datatypes'] = admissible_containers # containers else: d['schemes'] = available_schemes d['datatypes'] = admissible_datatypes # dtypes return req.getTAL("web/edit/modules/changeschema.html", d, macro="changeschema_popup")
'ret': content, 'state': state, 'filename': req.params.get('file'), 'new_tree_labels': new_tree_labels, } req.write(json.dumps(_d)) return None schemes = getSchemes(req) node = tree.getNode(ids[0]) v = {} if node.isContainer(): schemes = [] dtypes = [] access = acl.AccessData(req) if access.hasWriteAccess(node): schemes = getSchemes(req) dtypes = getDatatypes(req, schemes) col = node if "globalsort" in req.params: col.set("sortfield", req.params.get("globalsort")) v['collection_sortfield'] = col.get("sortfield") sortfields = [SortChoice(translation_t(req, "off"), "")] if col.type not in ["root", "collections", "home"]: for ntype, num in col.getAllOccurences(acl.AccessData(req)).items(): if ntype.getSortFields(): for sortfield in ntype.getSortFields(): sortfields += [SortChoice(sortfield.getLabel(), sortfield.getName())]
def sendmailUser_mask(req, id, err=0): v = getAdminStdVars(req) v["path"] = req.path[1:] if id in ["execute", "execu"]: userid = req.params.get("userid") user = getUser(userid) if not user: path = req.path[1:].split("/") user = getExternalUser(userid, path[-1]) password = makeRandomPassword() user.resetPassword(password) text = req.params.get("text") text = text.replace("[wird eingesetzt]", password) try: mail.sendmail(req.params.get("from"), req.params.get("email"), req.params.get("subject"), text) except mail.SocketError: print "Socket error while sending mail" req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR) return req.getTAL("web/admin/modules/user.html", v, macro="sendmailerror") return req.getTAL("web/admin/modules/user.html", v, macro="sendmaildone") user = getUser(id) if not user: path = req.path[1:].split("/") user = getExternalUser(id, path[-1]) collections = [] seen = {} access = acl.AccessData(user=user) for node in getAllCollections(): if access.hasReadAccess(node): if access.hasWriteAccess(node): collections.append(node.name + " (lesen/schreiben)") seen[node.id] = None for node in tree.getRoot("collections").getChildren(): if access.hasReadAccess(node) and node.id not in seen: collections.append(node.name + " (nur lesen)") x = {} x["name"] = "%s %s" % (user.getFirstName(), user.getLastName()) if (x["name"] == ""): x["name"] = user.getName() x["host"] = config.get("host.name") x["login"] = user.getName() x["isEditor"] = user.isEditor() x["collections"] = list() x["groups"] = user.getGroups() x["groups"].sort() x["language"] = lang(req) x["collections"] = collections x["collections"].sort() v["mailtext"] = req.getTAL("web/admin/modules/user.html", x, macro="emailtext").strip() v["email"] = user.getEmail() v["userid"] = user.getName() return req.getTAL("web/admin/modules/user.html", v, macro="sendmail")
def getContent(req, ids): ret = "" user = users.getUserFromRequest(req) access = acl.AccessData(req) for id in ids: if not access.hasWriteAccess( tree.getNode(id)) or "acls" in users.getHideMenusForUser(user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") idstr = ",".join(ids) if "save" in req.params: # save acl level userdir = users.getHomeDir(user) logging.getLogger('usertracing').info(access.user.name + " change access " + idstr) if req.params.get("type") == "acl": for type in acl_types: rights = req.params.get("left" + type, "").replace(";", ",") for id in ids: node = tree.getNode(id) error = 0 if access.hasWriteAccess(node) and userdir.id != node.id: node.setAccess(type, rights) else: error = 1 if error: req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") # save userlevel elif req.params.get("type") == "user": for type in acl_types: for id in ids: node = tree.getNode(id) error = 0 if access.hasWriteAccess(node) and userdir.id != node.id: r = [] r_acls = [] if req.params.get("leftuser" + type, "") != "": for right in req.params.get("leftuser" + type, "").split(";"): if len(right.split(": ")) == 2: r.append("(user " + right.split(": ")[1] + ")") else: r_acls.append(right) if len(r) > 0: rstr = "{" + " OR ".join(r) + "}" else: rstr = req.params.get( "leftuser" + type, "") if len(rstr) > 0: rstr += "," for x in r_acls: rstr += x + "," rstr = rstr[:-1] else: rstr = "" node.setAccess(type, rstr) else: error = 1 if error: req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") runsubmit = "\nfunction runsubmit(){\n" retacl = "" rights = {} parent_rights = {} overload = {} for type in acl_types: s = None parent_rights[type] = {} overload[type] = 0 runsubmit += "\tmark(document.myform.left" + type + ");\n" runsubmit += "\tmark(document.myform.leftuser" + type + ");\n" if type in ("read", "data"): overload[type] = 1 for id in ids: node = tree.getNode(id) r = node.getAccess(type) if r is None: r = "" log.debug(node.name + " " + type + " " + r) if not s or r == s: s = r else: s = "" def addNode(node): for p in node.getParents(): aclright = p.getAccess(type) for right in removeEmptyStrings((aclright or "").split(",")): parent_rights[type][right] = None if aclright and overload[type]: return else: addNode(p) addNode(node) rights[type] = removeEmptyStrings(s.split(",")) for type in acl_types: retacl += req.getTAL("web/edit/modules/acls.html", makeList(req, type, rights[type], parent_rights[type].keys(), overload[type], type=type), macro="edit_acls_selectbox") if "action" in req.params.keys(): # load additional rights by ajax retuser = "" for type in acl_types: retuser += req.getTAL("web/edit/modules/acls.html", makeUserList(req, type, rights[type], parent_rights[type].keys(), overload[type], type=type), macro="edit_acls_userselectbox") req.write(retuser) return "" runsubmit += "\tdocument.myform.submit();\n}\n" return req.getTAL("web/edit/modules/acls.html", { "runsubmit": runsubmit, "idstr": idstr, "contentacl": retacl, "adminuser": access.getUser().isAdmin() }, macro="edit_acls")
def create(): """ Creates the sitemap files and the sitemap index files which are located at /web/root/ """ logging.getLogger('everything').info( 'Creating Sitemaps and Sitemap Index...') base_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir)) hostname = config.get('host.name') root = tree.getRoot('collections') all_nodes = root.getAllChildren() user = users.getUser('Gast') access = acl.AccessData(user=user) sitemaps = [] node_dict = { 'collection': [], 'directory': [], 'document': [], 'dissertation': [], 'image': [], 'video': [], 'audio': [], } for node in all_nodes: # Arkitekt had a guest field that is actually not visible if access.hasAccess(node, 'read'): for node_type in node_dict.keys(): if node_type in tree.getNode(node.id).type: node_dict[node_type].append( (node.id, tree.getNode(node.id).get('updatetime'))) # Reassign node_dict to a dict where empty values were removed node_dict = dict((k, v) for k, v in node_dict.iteritems() if v) # Sitemap can have at most 50k entries for key in node_dict.keys(): if key in ('dissertation', 'document', 'image'): priority_level = '1.0' elif key == 'videos': priority_level = '0.8' else: priority_level = '0.5' # Create multiple sitemaps for node lists > 50k if len(node_dict[key]) > 50000: partitions = int(ceil((len(node_dict[key]) / 50000.))) for partition_number in range(partitions): sitemap = Sitemap( base_dir, ''.join( ['sitemap-', str(key), str(partition_number), '.xml']), hostname) sitemaps.append(sitemap.name) sitemap.create_sitemap( node_dict[key][partition_number * 50000:(partition_number + 1) * 50000], priority_level) else: sitemap = Sitemap(base_dir, ''.join(['sitemap-', key, '.xml']), hostname) sitemaps.append(sitemap.name) sitemap.create_sitemap(node_dict[key], priority_level) siteindex = SitemapIndex(base_dir, 'sitemap-index.xml', hostname) now = '+'.join( [datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'), '02:00']) siteindex.create_sitemap_index(sitemaps, now) logging.getLogger('everything').info( 'Generation of Sitemaps and SitemapIndex Complete')
def getContent(req, ids): """ The standard method, which has to be implemented by every module. It's called in edit.py, where all the modules will be identified. """ user = users.getUserFromRequest(req) access = acl.AccessData(req) node = tree.getNode(ids[0]) access_nobody = 'nicht Jeder' # first prove if the user has the required rights to call this module if 'sortfiles' in users.getHideMenusForUser( user) or not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL('web/edit/edit.html', {}, macro='access_error') if node.isContainer(): nodes = ', '.join(node.getChildren().getIDs()) else: nodes = node.get('node.id') v = { 'msg': '', 'urn_institutionid': config.get('urn.institutionid'), 'urn_pubtypes': config.get('urn.pubtypes').split(';'), 'namespaces': config.get('urn.namespace').split(';'), 'user': user, 'nodes': nodes, 'type': req.params.get('id_type'), 'show_form': True, 'namespace': req.params.get('namespace'), 'urn_type': req.params.get('urn_type'), 'host': config.get('host.name'), 'creator': users.getUser(node.get('creator')) } if user.isAdmin(): if 'id_type' in req.params: if req.params.get('id_type') == 'hash': createHash(node) if req.params.get('id_type') == 'urn': createUrn(node, req.params.get('namespace'), req.params.get('urn_type')) if req.params.get('id_type') == 'doi': try: createDOI(node) except: return req.error(500, "doi was not successfully registered") if any(identifier in node.attributes for identifier in ('hash', 'urn', 'doi')): if not node.get('system.identifierdate'): node.set('system.identifierdate', date.now()) if node.get('system.identifierstate') != '2': node.set('system.identifierstate', '2') # add nobody rule if not set if node.getAccess('write') is None: node.setAccess('write', access_nobody) else: if access_nobody not in node.getAccess('write'): node.setAccess( 'write', ','.join( [node.getAccess('write'), access_nobody])) try: mailtext = req.getTAL( 'web/edit/modules/identifier.html', v, macro='generate_identifier_usr_mail_2') mail.sendmail( config.get('email.admin'), users.getUser(node.get('creator')).get('email'), 'Vergabe eines Idektifikators / Generation of an Identifier', mailtext) except mail.SocketError: logging.getLogger('backend').error( 'failed to send Autorenvertrag mail to user %s' % node.get('creator')) v['msg'] = t(lang(req), 'edit_identifier_mail_fail') if node.get('system.identifierstate') != '2': v['msg'] = t(lang(req), 'edit_identifier_state_0_1_admin') else: v['msg'] = t(lang(req), 'edit_identifier_state_2_admin') else: if pathutils.isDescendantOf(node, tree.getRoot('collections')): if not node.get('system.identifierstate'): if 'id_type' in req.params: try: # fetch autorenvertrag attachment = [] autorenvertrag_name = 'formular_autorenvertrag.pdf' autorenvertrag_path = os.path.join( config.get('paths.tempdir'), autorenvertrag_name) if not os.path.isfile(autorenvertrag_path): logging.getLogger('backend').error( "Unable to attach Autorenvergrag. Attachment file not found: '%s'" % autorenvertrag_path) raise IOError( 'Autorenvertrag was not located on disk at %s. Please send this error message to %s' % (autorenvertrag_path, config.get('email.admin'))) else: attachment.append( (autorenvertrag_path, 'Autorenvertrag.pdf')) # notify user mailtext_user = req.getTAL( 'web/edit/modules/identifier.html', v, macro='generate_identifier_usr_mail_1_' + lang(req)) mail.sendmail( config.get('email.admin'), user.get('email'), t(lang(req), 'edit_identifier_mail_title_usr_1'), mailtext_user, attachments_paths_and_filenames=attachment) # notify admin mailtext_admin = req.getTAL( 'web/edit/modules/identifier.html', v, macro='generate_identifier_admin_mail') mail.sendmail( config.get('email.admin'), config.get('email.admin'), 'Antrag auf Vergabe eines Identifikators', mailtext_admin) node.set('system.identifierstate', '1') # add nobody rule print node.getAccess('write') if node.getAccess('write') is None: node.setAccess('write', access_nobody) else: if access_nobody not in node.getAccess('write'): node.setAccess( 'write', ','.join([ node.getAccess('write'), access_nobody ])) except mail.SocketError: logging.getLogger('backend').error( 'failed to send identifier request mail') v['msg'] = t(lang(req), 'edit_identifier_mail_fail') else: v['msg'] = t(lang(req), 'edit_identifier_state_0_usr') if node.get('system.identifierstate') == '1': v['show_form'] = False v['msg'] = t(lang(req), 'edit_identifier_state_1_usr') else: v['show_form'] = False v['msg'] = t(lang(req), 'edit_identifier_state_published') v['hash_val'] = node.get('hash') v['urn_val'] = node.get('urn') v['doi_val'] = node.get('doi') # hides form if all identifier types are already set if all(idents != '' for idents in (v['hash_val'], v['urn_val'], v['doi_val'])): v['show_form'] = False v['msg'] = t(lang(req), 'edit_identifier_all_types_set') return req.getTAL('web/edit/modules/identifier.html', v, macro='set_identifier')
def getContent(req, ids): user = users.getUserFromRequest(req) node = tree.getNode(ids[0]) access = acl.AccessData(req) if not access.hasWriteAccess(node) or "admin" in users.getHideMenusForUser( user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") if req.params.get('action') == 'getsearchdata': req.writeTAL("web/edit/modules/admin.html", { 'searchdata': node.search('searchcontent=%s' % node.id), 'node': node }, macro="searchdata") return '' if req.params.get("type", "") == "addattr" and req.params.get( "new_name", "") != "" and req.params.get("new_value", "") != "": node.set(req.params.get("new_name", ""), req.params.get("new_value", "")) logging.getLogger('editor').info( "new attribute %s for node %s added" % (req.params.get("new_name", ""), node.id)) for key in req.params.keys(): # update localread value of current node if key.startswith("del_localread"): node.resetLocalRead() logging.getLogger('editor').info( "localread attribute of node %s updated" % node.id) break # set current node 'dirty' (reindex for search) if key.startswith("set_dirty"): node.setDirty() logging.getLogger('editor').info("set node %s dirty" % node.id) if node.isContainer(): for child_node in node.getChildren(): child_node.setDirty() logging.getLogger('editor').info("set node %s dirty" % child_node.id) break # delete node from cache (e.g. after changes in db) if key.startswith("del_cache"): for n in node.getAllChildren(): remove_from_nodecaches(n) break # remove attribute if key.startswith("attr_"): node.removeAttribute(key[5:-2]) logging.getLogger('editor').info( "attribute %s of node %s removed" % (key[5:-2], node.id)) break fields = node.getType().getMetaFields() fieldnames = [] for field in fields: fieldnames += [field.name] attrs = node.items() metafields = {} technfields = {} obsoletefields = {} tattr = {} try: tattr = node.getTechnAttributes() except AttributeError: pass tattr = formatTechAttrs(tattr) for key, value in attrs: if key in fieldnames: metafields[key] = formatdate(value, getFormat(fields, key)) elif key in tattr.keys(): technfields[key] = formatdate(value) else: obsoletefields[key] = value # remove all technical attributes if req.params.get("type", "") == "technical": for key in technfields: node.removeAttribute(key) technfields = {} logging.getLogger('editor').info( "technical attributes of node %s removed" % node.id) return req.getTAL("web/edit/modules/admin.html", { "id": req.params.get("id", "0"), "tab": req.params.get("tab", ""), "node": node, "obsoletefields": obsoletefields, "metafields": metafields, "fields": fields, "technfields": technfields, "tattr": tattr, "fd": formatdate, "gf": getFormat, "adminuser": user.isAdmin(), "canedit": access.hasWriteAccess(node) }, macro="edit_admin_file")
def getContent(req, ids): user = users.getUserFromRequest(req) if "ftp" in users.getHideMenusForUser(user): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") ids = ids[0] # use only first selected node node = tree.getNode(ids) error = "" def processFile(node, file, ftype): nname = file.retrieveFile().split("/") nname = "/".join(nname[:-1]) + "/" + nname[-1][4:] try: os.rename(file.retrieveFile(), nname) except: nname = file.retrieveFile() fnode = tree.Node(nname.split("/")[-1], ftype) node.removeFile(file) file._path = file._path.replace(config.get("paths.datadir"), "") file._path = "/".join( file._path.split("/")[:-1]) + "/" + fnode.getName() fnode.addFile(file) fnode.event_files_changed() node.addChild(fnode) return fnode for key in req.params.keys(): if key.startswith("process|"): # process selected file (single) fname = key[:-2].split("|")[-1] ftype = req.params.get("schema").replace(";", "") if ftype != "": for f in node.getFiles(): if f.getName() == fname: processFile(node, f, ftype) break break else: error = "edit_ftp_error1" elif key.startswith("del|"): for f in node.getFiles(): if f.getName() == key[4:-2]: node.removeFile(f) break break elif key.startswith("delall"): # delete all selected files delfiles = [ f.split("|")[-1] for f in req.params.get("selfiles").split(";") ] for f in node.getFiles(): if f.getName() in delfiles: node.removeFile(f) break elif key.startswith("processall"): # process all selected files for file in req.params.get("selfiles", "").split(";"): if file: ftype, fname = file.split("|") if "multschema|" + ftype in req.params and req.params.get( "multschema|" + ftype) != "": for f in node.getFiles(): if f.getName() == fname: print "use", ftype + "/" + req.params.get( "multschema|" + ftype) processFile( node, f, ftype + "/" + req.params.get("multschema|" + ftype)) break else: error = "edit_ftp_error2" break break files = filter(lambda x: x.getName().startswith("ftp_"), node.getFiles()) types = [] for f in files: if f.getType() not in types: if f.getType() != "other": types.append(f.getType()) dtypes = {} for scheme in filter(lambda x: x.isActive(), acl.AccessData(req).filter(loadTypesFromDB())): for dtype in scheme.getDatatypes(): if dtype not in dtypes.keys(): dtypes[dtype] = [] if scheme not in dtypes[dtype]: dtypes[dtype].append(scheme) for t in dtypes: dtypes[t].sort(lambda x, y: cmp( translate(x.getLongName(), request=req).lower(), translate(y.getLongName(), request=req).lower())) access = acl.AccessData(req) if not access.hasWriteAccess(node): req.setStatus(httpstatus.HTTP_FORBIDDEN) return req.getTAL("web/edit/edit.html", {}, macro="access_error") v = {} v['error'] = error v['files'] = files v['node'] = node v['schemes'] = dtypes # schemes v['usedtypes'] = types v['tab'] = req.params.get("tab", "") v['ids'] = ids v["script"] = "<script> parent.reloadTree('" + req.params.get( "id") + "');</script>" return req.getTAL("web/edit/modules/ftp.html", v, macro="edit_ftp")
def getNodes(req): global tokenpositions, CHUNKSIZE access = acl.AccessData(req) nodes = None if "resumptionToken" in req.params: token = req.params.get("resumptionToken") if token in tokenpositions: pos, nodes, metadataformat = tokenpositions[token] else: return None, "badResumptionToken", None if not checkParams(req, ["verb", "resumptionToken"]): OUT("OAI: getNodes: additional arguments (only verb and resumptionToken allowed)" ) return None, "badArgument", None else: token, metadataformat = new_token(req) if not checkMetaDataFormat(metadataformat): OUT('OAI: ListRecords: metadataPrefix missing', 'error') return None, "badArgument", None pos = 0 if not nodes: string_from, string_to = None, None try: string_from = req.params["from"] date_from = parseDate(string_from) if date_from.year < EARLIEST_YEAR: date_from = date.DateTime(0, 0, 0, 0, 0, 0) except: if "from" in req.params: return None, "badArgument", None date_from = None try: date_to = parseDate(req.params["until"]) string_to = req.params.get("until") if not date_to.has_time: date_to.hour = 23 date_to.minute = 59 date_to.second = 59 if date_to.year < EARLIEST_YEAR - 1: raise except: if "until" in req.params: return None, "badArgument", None date_to = None setspec = None if "set" in req.params: setspec = req.params.get("set") if string_from and string_to and (string_from > string_to or len(string_from) != len(string_to)): return None, "badArgument", None try: nodes = retrieveNodes(req, access, setspec, date_from, date_to, metadataformat) nodes = [n for n in nodes if not parentIsMedia(n)] # filter out nodes that are inactive or older versions of other nodes nodes = [n for n in nodes if n.isActiveVersion()] except tree.NoSuchNodeError: # collection doesn't exist return None, "badArgument", None with token_lock: tokenpositions[token] = pos + CHUNKSIZE, nodes, metadataformat tokenstring = '<resumptionToken expirationDate="' + ISO8601(date.now().add(3600 * 24)) + '" ' + \ 'completeListSize="' + str(len(nodes)) + '" cursor="' + str(pos) + '">' + token + '</resumptionToken>' if pos + CHUNKSIZE >= len(nodes): tokenstring = None with token_lock: del tokenpositions[token] OUT( req.params.get('verb') + ": set=" + str(req.params.get('set')) + ", " + str(len(nodes)) + " objects, format=" + metadataformat) res = tree.NodeList(nodes[pos:pos + CHUNKSIZE]) if DEBUG: timetable_update( req, "leaving getNodes: returning %d nodes, tokenstring='%s', metadataformat='%s'" % (len(res), tokenstring, metadataformat)) return res, tokenstring, metadataformat