def getStylesheet(self, id=None): stylesheets = self.getStylesheets() if id is None: return stylesheets[0] else: for css in stylesheets: if absattr( css.id) == id: return css
def recurse_cleanArtefacts(self, level=0): from OFS.CopySupport import absattr # Recursion. last_id = None for ob in self.objectValues(): if absattr(self.id) == absattr(ob.id): print(" " * level) + "recurse_cleanArtefacts", ob.absolute_url( ), ob.meta_type raise zExceptions.InternalError('InfiniteRecursionError') else: try: recurse_cleanArtefacts(ob, level + 1) except "InfiniteRecursionError": print( " " * level ) + "recurse_cleanArtefacts: clean artefact ", ob.absolute_url( ), ob.meta_type self._delObject(absattr(ob.id), suppress_events=True)
def _set_sort_ids(self, ids, op, REQUEST): _globals.writeLog(self, "[_set_sort_ids]: %s" % self.absolute_url()) copy_of_prefix = 'copy_of_' sort_id = REQUEST.get('_sort_id', 0) + 1 for ob in self.getChildNodes(): id = absattr(ob.id) if id in ids or (op == 1 and copy_of_prefix + id in ids): setattr(ob, 'sort_id', _globals.format_sort_id(sort_id)) sort_id = sort_id + 1
def _normalize_ids_after_move(self, ids=[], forced=0, REQUEST=None): _globals.writeLog( self, "[_normalize_ids_after_move]: %s" % self.absolute_url()) copy_of_prefix = 'copy_of_' id_prefix = REQUEST.get('id_prefix') REQUEST.set('id_prefix', None) ob_ids = copy.copy(self.objectIds(self.dGlobalAttrs.keys())) for ob in self.objectValues(self.dGlobalAttrs.keys()): id = absattr(ob.id) if forced or (id in ids and not copy_of_prefix + id in ob_ids) or ( copy_of_prefix + id in ids): _globals.writeBlock( self, '[_normalize_ids_after_move]: %s(%s)' % (id, ob.meta_id)) if id_prefix: id_prefix = _globals.id_prefix(id_prefix) if id_prefix != _globals.id_prefix(id): new_id = self.getNewId(id_prefix) _globals.writeBlock( self, '[_normalize_ids_after_move]: Rename %s(%s) to %s' % (id, ob.meta_id, new_id)) self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) id = new_id # Re-Assign old id. if id.find(copy_of_prefix) == 0: try: new_id = id[len(copy_of_prefix):] self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) except: pass bk_lang = REQUEST.get('lang') for lang in self.getLangIds(): REQUEST.set('lang', lang) if forced == 0: # Object-State and Version-Manager. if not ob.getAutocommit(): ob.setObjStateModified(REQUEST) ob.onChangeObj(REQUEST) # Process referential integrity. ob.onMoveRefObj(REQUEST) REQUEST.set('lang', bk_lang) # Process tree. ob._normalize_ids_after_move(ids=ids, forced=1, REQUEST=REQUEST)
def _normalize_ids_after_copy(self, ids=[], forced=0, REQUEST=None): _globals.writeLog( self, "[_normalize_ids_after_copy]: %s" % self.absolute_url()) copy_of_prefix = 'copy_of_' id_prefix = REQUEST.get('id_prefix') REQUEST.set('id_prefix', None) ob_ids = copy.copy(self.objectIds(self.dGlobalAttrs.keys())) for ob in self.objectValues(self.dGlobalAttrs.keys()): id = absattr(ob.id) if forced or id in ids: _globals.writeBlock( self, '[_normalize_ids_after_copy]: %s(%s)' % (id, ob.meta_id)) if id_prefix: id_prefix = _globals.id_prefix(id_prefix) if id_prefix != _globals.id_prefix(id): new_id = self.getNewId(id_prefix) _globals.writeBlock( self, '[_normalize_ids_after_copy]: Rename %s(%s) to %s' % (id, ob.meta_id, new_id)) self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) id = new_id # Assign new id. prefix = _globals.id_prefix(id) if prefix.find(copy_of_prefix) == 0: prefix = prefix[len(copy_of_prefix):] if prefix != id: new_id = self.getNewId(prefix) self.manage_renameObject(id=id, new_id=new_id) self.initObjChildren(REQUEST) bk_lang = REQUEST.get('lang') for lang in self.getLangIds(): REQUEST.set('lang', lang) if forced == 0: # Object-State and Version-Manager. if not ob.getAutocommit(): ob.setObjStateNew(REQUEST, reset=0) ob.onChangeObj(REQUEST) # Process referential integrity. ob.onCopyRefObj(REQUEST) REQUEST.set('lang', bk_lang) # Process tree. ob._normalize_ids_after_copy(ids=ids, forced=1, REQUEST=REQUEST)
def isRenameable(self): # Is object renameable? Returns 0 or 1 if not (hasattr(self, '_canCopy') and self._canCopy(1)): return 0 if hasattr(self, '_p_jar') and self._p_jar is None: return 0 try: n=aq_parent(aq_inner(self))._reserved_names except: n=() if absattr(self.id) in n: return 0 if not getSecurityManager().checkPermission(copy_or_move, self): return 0 return 1
def getWorkflowManager(self): manager = [x for x in self.getDocumentElement().objectValues() if absattr(x.id) == 'workflow_manager'] if len(manager) == 0: class DefaultManager(object): def importXml(self, xml): pass def writeProtocol(self, log): pass def getAutocommit(self): return True def getActivities(self): return [] def getActivityIds(self): return [] def getActivity(self, id): return None def getActivityDetails(self, id): return None def getTransitions(self): return [] def getTransitionIds(self): return [] manager = [DefaultManager()] return manager[0]
def getStylesheets(self): ids = [] obs = [] for container in self.getResourceFolders(): for folder in [ getattr( container, 'css', None), container]: if folder is not None: for ob in folder.objectValues(['DTML Method', 'DTML Document', 'File', 'Filesystem File']): id = absattr( ob.id) path = ob.getPhysicalPath() if len([x for x in path if x.endswith('css')]) > 0 and id not in ids: ids.append( id) if id == self.getConfProperty('ZMS.stylesheet', 'style.css'): obs.insert( 0, ob) else: obs.append( ob) return obs
def _verifyObjectPaste(self, object, validate_src=1): # Verify whether the current user is allowed to paste the # passed object into self. This is determined by checking # to see if the user could create a new object of the same # meta_type of the object passed in and checking that the # user actually is allowed to access the passed in object # in its existing context. # # Passing a false value for the validate_src argument will skip # checking the passed in object in its existing context. This is # mainly useful for situations where the passed in object has no # existing context, such as checking an object during an import # (the object will not yet have been connected to the acquisition # heirarchy). if not hasattr(object, "meta_type"): raise CopyError( MessageDialog( title="Not Supported", message=( "The object <em>%s</em> does not support this" " operation" % escape(absattr(object.id)) ), action="manage_main", ) ) if not hasattr(self, "all_meta_types"): raise CopyError( MessageDialog(title="Not Supported", message="Cannot paste into this object.", action="manage_main") ) method_name = None mt_permission = None meta_types = absattr(self.all_meta_types) for d in meta_types: if d["name"] == object.meta_type: method_name = d["action"] mt_permission = d.get("permission") break if mt_permission is not None: sm = getSecurityManager() if sm.checkPermission(mt_permission, self): if validate_src: # Ensure the user is allowed to access the object on the # clipboard. try: parent = aq_parent(aq_inner(object)) except ConflictError: raise except Exception: parent = None if not sm.validate(None, parent, None, object): raise Unauthorized(absattr(object.id)) # --- Patch --- # Disable checking for `Delete objects` permission # if validate_src == 2: # moving # if not sm.checkPermission(delete_objects, parent): # raise Unauthorized('Delete not allowed.') # --- End Patch --- else: raise CopyError( MessageDialog( title="Insufficient Privileges", message=( "You do not possess the %s permission in the " "context of the container into which you are " "pasting, thus you are not able to perform " "this operation." % mt_permission ), action="manage_main", ) ) else: raise CopyError( MessageDialog( title="Not Supported", message=( "The object <em>%s</em> does not support this " "operation." % escape(absattr(object.id)) ), action="manage_main", ) )
def getFilename(self): return absattr(self.f.id)
def _verifyObjectPaste(self, object, validate_src=1): # Verify whether the current user is allowed to paste the # passed object into self. This is determined by checking # to see if the user could create a new object of the same # meta_type of the object passed in and checking that the # user actually is allowed to access the passed in object # in its existing context. # # Passing a false value for the validate_src argument will skip # checking the passed in object in its existing context. This is # mainly useful for situations where the passed in object has no # existing context, such as checking an object during an import # (the object will not yet have been connected to the acquisition # heirarchy). # # We also make sure that we are not pasting a checked-out document if IBaseDocument.providedBy(object) and object.is_checked_out(): raise CopyError('Checked out documents cannot be copied.') if not hasattr(object, 'meta_type'): raise CopyError(MessageDialog( title = 'Not Supported', message = ('The object <em>%s</em> does not support this' \ ' operation' % escape(absattr(object.id))), action = 'manage_main')) if not hasattr(self, 'all_meta_types'): raise CopyError( MessageDialog(title='Not Supported', message='Cannot paste into this object.', action='manage_main')) mt_permission = None meta_types = absattr(self.all_meta_types) for d in meta_types: if d['name'] == object.meta_type: mt_permission = d.get('permission') break if mt_permission is not None: sm = getSecurityManager() if sm.checkPermission(mt_permission, self): if validate_src: # Ensure the user is allowed to access the object on the # clipboard. try: parent = aq_parent(aq_inner(object)) except ConflictError: raise except Exception: parent = None if not sm.validate(None, parent, None, object): raise Unauthorized(absattr(object.id)) # --- Patch --- # Disable checking for `Delete objects` permission # if validate_src == 2: # moving # if not sm.checkPermission(delete_objects, parent): # raise Unauthorized('Delete not allowed.') # --- End Patch --- else: raise CopyError( MessageDialog( title='Insufficient Privileges', message=( 'You do not possess the %s permission in the ' 'context of the container into which you are ' 'pasting, thus you are not able to perform ' 'this operation.' % mt_permission), action='manage_main')) else: raise CopyError( MessageDialog( title='Not Supported', message=( 'The object <em>%s</em> does not support this ' 'operation.' % escape(absattr(object.id))), action='manage_main'))
def manage_customizeDesign(self, btn, lang, REQUEST, RESPONSE): """ ConfManager.manage_customizeDesign """ message = '' cssId = REQUEST.get('cssId', '') # Ex-/Import. # ----------- if btn in [ self.getZMILangStr('BTN_EXPORT'), self.getZMILangStr('BTN_IMPORT') ]: #-- Theme. home = self.getHome() home_id = home.id temp_folder = self.temp_folder # Init exclude-ids. excl_ids = [] # Add clients-folders to exclude-ids. for folder in home.objectValues(['Folder']): if len(folder.objectValues(['ZMS'])) > 0: excl_ids.append(absattr(folder.id)) # Add content-object artefacts to exclude-ids. for metaObjId in self.getMetaobjIds(): for metaObjAttrId in self.getMetaobjAttrIds(metaObjId): metaObjAttr = self.getMetaobjAttr(metaObjId, metaObjAttrId) if metaObjAttr[ 'type'] in self.metaobj_manager.valid_zopetypes: excl_ids.append(metaObjAttrId) # Filter ids. ids = filter(lambda x: x not in excl_ids, home.objectIds(self.metaobj_manager.valid_zopetypes)) if btn == self.getZMILangStr('BTN_EXPORT'): if home_id in temp_folder.objectIds(): temp_folder.manage_delObjects(ids=[home_id]) temp_folder.manage_addFolder(id=home_id, title=home.title_or_id()) folder = getattr(temp_folder, home_id) home.manage_copyObjects(ids, REQUEST) folder.manage_pasteObjects(cb_copy_data=None, REQUEST=REQUEST) return RESPONSE.redirect( self.url_append_params( '%s/manage_exportObject' % temp_folder.absolute_url(), { 'id': home_id, 'download:int': 1 })) if btn == self.getZMILangStr('BTN_IMPORT'): v = REQUEST['theme'] temp_filename = _fileutil.extractFilename(v.filename) temp_id = temp_filename[:temp_filename.rfind('.')] filepath = INSTANCE_HOME + '/import/' + temp_filename _fileutil.exportObj(v, filepath) if temp_id in temp_folder.objectIds(): temp_folder.manage_delObjects(ids=[temp_id]) temp_folder.manage_importObject(temp_filename) folder = getattr(temp_folder, temp_id) home.manage_delObjects(ids=ids) folder.manage_copyObjects(folder.objectIds(), REQUEST) home.manage_pasteObjects(cb_copy_data=None, REQUEST=REQUEST) _fileutil.remove(filepath) temp_folder.manage_delObjects(ids=[temp_id]) # Save. # ----- if btn == self.getZMILangStr('BTN_SAVE'): #-- Stylesheet. if REQUEST.has_key('cssId'): if REQUEST.get('default'): self.setConfProperty('ZMS.stylesheet', REQUEST.get('cssId')) css = self.getStylesheet(REQUEST.get('cssId')) data = REQUEST.get('stylesheet') title = css.title css.manage_edit(data, title) message = self.getZMILangStr('MSG_CHANGED') #-- Sitemap. if REQUEST.has_key('attr_layoutsitemap'): if len(REQUEST['attr_layoutsitemap']) > 0: self.attr_layoutsitemap = int( REQUEST['attr_layoutsitemap']) elif hasattr(self, 'attr_layoutsitemap'): delattr(self, 'attr_layoutsitemap') message = self.getZMILangStr('MSG_CHANGED') # Upload. # ------- elif btn == self.getZMILangStr('BTN_UPLOAD'): #-- ZMI Logo. self.zmi_logo = Image(id='logo', title='', file='') self.zmi_logo.manage_upload(REQUEST['file'], REQUEST) message = self.getZMILangStr('MSG_CHANGED') # Return with message. message = urllib.quote(message) return RESPONSE.redirect( 'manage_customizeDesignForm?lang=%s&manage_tabs_message=%s&cssId=%s' % (lang, message, cssId))
def _get_ids(self, cp): return map(lambda ob: self._get_id(absattr(ob.id)), self._get_obs(cp))