def get_archived(req): print "send archived" id, filename = splitpath(req.path) node = tree.getNode(id) node.set("archive_state", "1") if not archivemanager: req.write("-no archive module loaded-") return archiveclass = "" for item in config.get("archive.class").split(";"): if item.endswith(node.get("archive_type")): archiveclass = item + ".py" break if archiveclass: # start process from archive os.chdir(config.basedir) os.system("python %s %s" % (archiveclass, node.id)) st = "" while True: # test if process is still running attrs = tree.db.getAttributes(id) if "archive_state" in attrs.keys(): st = attrs['archive_state'] time.sleep(1) if st == "2": break for n in node.getAllChildren(): tree.remove_from_nodecaches(n) req.write('done')
def upload_new_node(req, path, params, data): try: uploadfile = params['data'] del params['data'] except KeyError: uploadfile = None # get the user and verify the signature if params.get('user'): # user=users.getUser(params.get('user')) #userAccess = AccessData(user=user) _user = users.getUser(params.get('user')) if not _user: # user of dynamic class dummyuser: # dummy user class # return all groups with given dynamic user def getGroups(self): return [g.name for g in tree.getRoot('usergroups').getChildren() if g.get( 'allow_dynamic') == '1' and params.get('user') in g.get('dynamic_users')] def getName(self): return params.get('user') def getDirID(self): # unique identifier return params.get('user') def isAdmin(self): return 0 _user = dummyuser() userAccess = AccessData(user=_user) if userAccess.user: user = userAccess.user if not userAccess.verify_request_signature( req.fullpath + '?', params): userAccess = None else: userAccess = None else: user = users.getUser(config.get('user.guestuser')) userAccess = AccessData(user=user) parent = tree.getNode(params.get('parent')) # check user access if userAccess and userAccess.hasAccess(parent, "write"): pass else: s = "No Access" req.write(s) d = { 'status': 'fail', 'html_response_code': '403', 'errormessage': 'no access'} logger.error("user has no edit permission for node %s" % parent) return d['html_response_code'], len(s), d datatype = params.get('type') uploaddir = users.getUploadDir(user) n = tree.Node(name=params.get('name'), type=datatype) if isinstance(uploadfile, types.InstanceType): # file object used nfile = importFile(uploadfile.filename, uploadfile.tempname) else: # string used nfile = importFileFromData( 'uploadTest.jpg', base64.b64decode(uploadfile)) if nfile: n.addFile(nfile) else: logger.error("error in file uploadservice") try: # test metadata metadata = json.loads(params.get('metadata')) except ValueError: metadata = dict() # set provided metadata for key, value in metadata.iteritems(): n.set(u(key), u(value)) # service flags n.set("creator", user.getName()) n.set("creationtime", format_date()) parent.addChild(n) # process the file, we've added to the new node if hasattr(n, "event_files_changed"): try: n.event_files_changed() except OperationException as e: for file in n.getFiles(): if os.path.exists(file.retrieveFile()): os.remove(file.retrieveFile()) raise OperationException(e.value) # make sure the new node is visible immediately from the web service and # the search index gets updated n.setDirty() tree.remove_from_nodecaches(parent) d = { 'status': 'Created', 'html_response_code': '201', 'build_response_end': time.time()} s = "Created" # provide the uploader with the new node ID req.reply_headers['NodeID'] = n.id # we need to write in case of POST request, send as buffer will not work req.write(s) return d['html_response_code'], len(s), d
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")
def upload_new_node(req, path, params, data): try: uploadfile = params['data'] del params['data'] except KeyError: uploadfile = None # get the user and verify the signature if params.get('user'): # user=users.getUser(params.get('user')) #userAccess = AccessData(user=user) _user = users.getUser(params.get('user')) if not _user: # user of dynamic class dummyuser: # dummy user class # return all groups with given dynamic user def getGroups(self): return [ g.name for g in tree.getRoot('usergroups').getChildren() if g.get('allow_dynamic') == '1' and params.get('user') in g.get('dynamic_users') ] def getName(self): return params.get('user') def getDirID(self): # unique identifier return params.get('user') def isAdmin(self): return 0 _user = dummyuser() userAccess = AccessData(user=_user) if userAccess.user: user = userAccess.user if not userAccess.verify_request_signature(req.fullpath + '?', params): userAccess = None else: userAccess = None else: user = users.getUser(config.get('user.guestuser')) userAccess = AccessData(user=user) parent = tree.getNode(params.get('parent')) # check user access if userAccess and userAccess.hasAccess(parent, "write"): pass else: s = "No Access" req.write(s) d = { 'status': 'fail', 'html_response_code': '403', 'errormessage': 'no access' } logger.error("user has no edit permission for node %s" % parent) return d['html_response_code'], len(s), d datatype = params.get('type') uploaddir = users.getUploadDir(user) n = tree.Node(name=params.get('name'), type=datatype) if isinstance(uploadfile, types.InstanceType): # file object used nfile = importFile(uploadfile.filename, uploadfile.tempname) else: # string used nfile = importFileFromData('uploadTest.jpg', base64.b64decode(uploadfile)) if nfile: n.addFile(nfile) else: logger.error("error in file uploadservice") try: # test metadata metadata = json.loads(params.get('metadata')) except ValueError: metadata = dict() # set provided metadata for key, value in metadata.iteritems(): n.set(u(key), u(value)) # service flags n.set("creator", user.getName()) n.set("creationtime", format_date()) parent.addChild(n) # process the file, we've added to the new node if hasattr(n, "event_files_changed"): try: n.event_files_changed() except OperationException as e: for file in n.getFiles(): if os.path.exists(file.retrieveFile()): os.remove(file.retrieveFile()) raise OperationException(e.value) # make sure the new node is visible immediately from the web service and # the search index gets updated n.setDirty() tree.remove_from_nodecaches(parent) d = { 'status': 'Created', 'html_response_code': '201', 'build_response_end': time.time() } s = "Created" # provide the uploader with the new node ID req.reply_headers['NodeID'] = n.id # we need to write in case of POST request, send as buffer will not work req.write(s) return d['html_response_code'], len(s), d
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 scheduler_thread(): global count import utils.scheduleutils as scheduleutils if not time: return ensureSchedulesRoot() TRIGGER_COUNT = 0 while True: count += 1 TT = [] HAS_FIRED = HAS_ERROR = False atime0 = atime = time.time() now_obj = datetime.now() now_str = now_obj.isoformat() # example: '2012-05-29T13:15:17.557000' if athana.ATHANA_STARTED: if count % scheduleutils.TRIGGER_INTERVAL == 0: TRIGGER_COUNT += 1 sched_root = tree.getRoot("schedules") try: tree.remove_from_nodecaches(sched_root) msg = "flushed schedules" TT.append([msg, time.time() - atime]) atime = time.time() except TypeError: msg = "scheduler thread failed to remove schedules root from cache" OUT(msg, logger='backend', level='warning') sched_list = [c for c in sched_root.getChildren() if c.type == 'schedule'] # to do: sort? msg = "%d schedule(s) found" % len(sched_list) TT.append([msg, time.time() - atime]) atime = time.time() SCHEDULES_IMPORT_ERROR = False try: reload(scheduleutils) msg = "reloaded module utils.scheduleutils" TT.append([msg, time.time() - atime]) atime = time.time() except: msg = "Error reloading module 'scheduleutils': %s %s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1])) TT.append([msg, time.time() - atime]) atime = time.time() OUT(msg, logger='backend', print_stdout=True, level='error') SCHEDULES_IMPORT_ERROR = True if not SCHEDULES_IMPORT_ERROR: interval_seconds = scheduleutils.SLEEP_INTERVAL * scheduleutils.TRIGGER_INTERVAL OUT("scheduler_thread (interval: %s sec.): %s" % (str(interval_seconds), now_str)) now_obj = datetime.now() now_str = now_obj.isoformat() for s in sched_list: has_fired, has_error, tt = scheduleutils.handle_single_trigger(s, now_str, OUT) TT = TT + tt atime = time.time() if has_fired: HAS_FIRED = True if has_error: HAS_ERROR = True try: has_fired, has_error, tt = scheduleutils.handle_cron_dict(s, now_obj, OUT) except: has_fired, has_error, tt = False, True, [] TT = TT + tt atime = time.time() if has_fired: HAS_FIRED = True if has_error: HAS_ERROR = True sys.stdout.flush() else: msg = 'scheduler: check no: %d: athana not yet started' % (count) OUT(msg, print_stdout=False) def OUT_TT(TT): msg = "scheduler: timetable (scheduleutils.DEBUG = '%s')\n|" % (scheduleutils.DEBUG) + '-' * 60 + '\n' msg += '| check no %d at %s:\n' % (TRIGGER_COUNT, now_str) for s, t in TT: msg = msg + '| %.3f: %s\n' % (t, str(s)) msg += '| duration: %.3f sec.\n' % (time.time() - atime0) msg += '|' + '-' * 60 OUT(msg) if scheduleutils.DEBUG: if TT: OUT_TT(TT) else: if (HAS_FIRED or HAS_ERROR) and TT: OUT_TT(TT) correction = int((time.time() - atime0) / scheduleutils.SLEEP_INTERVAL) count += correction time.sleep(scheduleutils.SLEEP_INTERVAL)
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")
def scheduler_thread(): global count import utils.scheduleutils as scheduleutils if not time: return ensureSchedulesRoot() TRIGGER_COUNT = 0 while True: count += 1 TT = [] HAS_FIRED = HAS_ERROR = False atime0 = atime = time.time() now_obj = datetime.now() now_str = now_obj.isoformat() # example: '2012-05-29T13:15:17.557000' if athana.ATHANA_STARTED: if count % scheduleutils.TRIGGER_INTERVAL == 0: TRIGGER_COUNT += 1 sched_root = tree.getRoot("schedules") try: tree.remove_from_nodecaches(sched_root) msg = "flushed schedules" TT.append([msg, time.time() - atime]) atime = time.time() except TypeError: msg = "scheduler thread failed to remove schedules root from cache" OUT(msg, logger='backend', level='warning') sched_list = [ c for c in sched_root.getChildren() if c.type == 'schedule' ] # to do: sort? msg = "%d schedule(s) found" % len(sched_list) TT.append([msg, time.time() - atime]) atime = time.time() SCHEDULES_IMPORT_ERROR = False try: reload(scheduleutils) msg = "reloaded module utils.scheduleutils" TT.append([msg, time.time() - atime]) atime = time.time() except: msg = "Error reloading module 'scheduleutils': %s %s" % ( str(sys.exc_info()[0]), str(sys.exc_info()[1])) TT.append([msg, time.time() - atime]) atime = time.time() OUT(msg, logger='backend', print_stdout=True, level='error') SCHEDULES_IMPORT_ERROR = True if not SCHEDULES_IMPORT_ERROR: interval_seconds = scheduleutils.SLEEP_INTERVAL * scheduleutils.TRIGGER_INTERVAL OUT("scheduler_thread (interval: %s sec.): %s" % (str(interval_seconds), now_str)) now_obj = datetime.now() now_str = now_obj.isoformat() for s in sched_list: has_fired, has_error, tt = scheduleutils.handle_single_trigger( s, now_str, OUT) TT = TT + tt atime = time.time() if has_fired: HAS_FIRED = True if has_error: HAS_ERROR = True try: has_fired, has_error, tt = scheduleutils.handle_cron_dict( s, now_obj, OUT) except: has_fired, has_error, tt = False, True, [] TT = TT + tt atime = time.time() if has_fired: HAS_FIRED = True if has_error: HAS_ERROR = True sys.stdout.flush() else: msg = 'scheduler: check no: %d: athana not yet started' % (count) OUT(msg, print_stdout=False) def OUT_TT(TT): msg = "scheduler: timetable (scheduleutils.DEBUG = '%s')\n|" % ( scheduleutils.DEBUG) + '-' * 60 + '\n' msg += '| check no %d at %s:\n' % (TRIGGER_COUNT, now_str) for s, t in TT: msg = msg + '| %.3f: %s\n' % (t, str(s)) msg += '| duration: %.3f sec.\n' % (time.time() - atime0) msg += '|' + '-' * 60 OUT(msg) if scheduleutils.DEBUG: if TT: OUT_TT(TT) else: if (HAS_FIRED or HAS_ERROR) and TT: OUT_TT(TT) correction = int((time.time() - atime0) / scheduleutils.SLEEP_INTERVAL) count += correction time.sleep(scheduleutils.SLEEP_INTERVAL)
def clearFromCache(node): if node is tree.getRoot("collections"): return for n in node.getAllChildren(): remove_from_nodecaches(n)
def clearFromCache(node): if node is tree.getRoot('collections'): return for n in node.getAllChildren(): remove_from_nodecaches(n)
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")