def getPermissionMapping(name, obj, st=type('')): obj = getattr(obj, 'aq_base', obj) name = getPermissionIdentifier(name) r = getattr(obj, name, '') if type(r) is not st: r = '' return r
def getPermissionMapping(name, obj, st=type('')): obj = getattr(obj, 'aq_base', obj) name = getPermissionIdentifier(name) r = getattr(obj, name, '') if type(r) is not st: r = '' return r
def rolesForPermissionOn(perm, object, default=_default_roles, n=None): """Return the roles that have the given permission on the given object """ n = n or getPermissionIdentifier(perm) r = None while 1: if hasattr(object, n): roles = getattr(object, n) if roles is None: if _embed_permission_in_roles: return ('Anonymous', n) return 'Anonymous' t = type(roles) if t is tuple: # If we get a tuple, then we don't acquire if r is None: if _embed_permission_in_roles: return roles + (n,) return roles if _embed_permission_in_roles: return r + list(roles) + [n] return r + list(roles) if t is str: # We found roles set to a name. Start over # with the new permission name. If the permission # name is '', then treat as private! if roles: n = roles else: return _what_not_even_god_should_do elif roles: if r is None: r = list(roles) else: r = r + list(roles) object = aq_inner(object) if object is None: break object = aq_parent(object) if r is None: if _embed_permission_in_roles: if default: if isinstance(default, tuple): return default + (n,) else: return default + [n] else: return [n] return default if _embed_permission_in_roles: return r + [n] return r
def rolesForPermissionOn(perm, object, default=_default_roles, n=None): """Return the roles that have the given permission on the given object """ n = n or getPermissionIdentifier(perm) r = None while 1: if hasattr(object, n): roles = getattr(object, n) if roles is None: if _embed_permission_in_roles: return ('Anonymous', n) return 'Anonymous' t = type(roles) if t is tuple: # If we get a tuple, then we don't acquire if r is None: if _embed_permission_in_roles: return roles + (n, ) return roles if _embed_permission_in_roles: return r + list(roles) + [n] return r + list(roles) if t is str: # We found roles set to a name. Start over # with the new permission name. If the permission # name is '', then treat as private! if roles: n = roles else: return _what_not_even_god_should_do elif roles: if r is None: r = list(roles) else: r = r + list(roles) object = aq_inner(object) if object is None: break object = aq_parent(object) if r is None: if _embed_permission_in_roles: if default: if isinstance(default, tuple): return default + (n, ) else: return default + [n] else: return [n] return default if _embed_permission_in_roles: return r + [n] return r
def manage_getPermissionMapping(self): """Return the permission mapping for the object This is a list of dictionaries with: permission_name -- The name of the native object permission class_permission -- The class permission the permission is mapped to. """ wrapper = getattr(self, '_permissionMapper', None) if wrapper is None: wrapper = PM() perms = {} for p in self.possible_permissions(): perms[getPermissionIdentifier(p)] = p r = [] a = r.append for ac_perms in self.ac_inherited_permissions(1): p = perms.get(getPermissionMapping(ac_perms[0], wrapper), '') a({'permission_name': ac_perms[0], 'class_permission': p}) return r
def manage_getPermissionMapping(self): """Return the permission mapping for the object This is a list of dictionaries with: permission_name -- The name of the native object permission class_permission -- The class permission the permission is mapped to. """ wrapper = getattr(self, '_permissionMapper', None) if wrapper is None: wrapper = PM() perms = {} for p in self.possible_permissions(): perms[getPermissionIdentifier(p)] = p r = [] a = r.append for ac_perms in self.ac_inherited_permissions(1): p = perms.get(getPermissionMapping(ac_perms[0], wrapper), '') a({'permission_name': ac_perms[0], 'class_permission': p}) return r
def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None, obj_searchterm=None, obj_expr=None, obj_mtime=None, obj_mspec=None, obj_permission=None, obj_roles=None, search_sub=0, REQUEST=None, result=None, pre='', apply_func=None, apply_path=''): """Zope Find interface and apply This is a *great* hack. Zope find just doesn't do what we need here; the ability to apply a method to all the objects *as they're found* and the need to pass the object's path into that method. """ if result is None: result = [] if obj_metatypes and 'all' in obj_metatypes: obj_metatypes = None if obj_mtime and isinstance(obj_mtime, str): obj_mtime = DateTime(obj_mtime).timeTime() if obj_permission: obj_permission = getPermissionIdentifier(obj_permission) if obj_roles and isinstance(obj_roles, str): obj_roles = [obj_roles] if obj_expr: # Setup expr machinations md = td() obj_expr = (Eval(obj_expr), md, md._push, md._pop) base = aq_base(obj) if not hasattr(base, 'objectItems'): return result try: items = obj.objectItems() except Exception: return result try: add_result = result.append except Exception: raise AttributeError(repr(result)) for id, ob in items: if pre: p = "%s/%s" % (pre, id) else: p = id dflag = 0 if hasattr(ob, '_p_changed') and (ob._p_changed is None): dflag = 1 bs = aq_base(ob) if ((not obj_ids or absattr(bs.id) in obj_ids) and (not obj_metatypes or (hasattr(bs, 'meta_type') and bs.meta_type in obj_metatypes)) and (not obj_searchterm or (hasattr(ob, 'PrincipiaSearchSource') and ob.PrincipiaSearchSource().find(obj_searchterm) >= 0) ) # noqa: E501 and (not obj_expr or expr_match(ob, obj_expr)) and (not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec)) and ((not obj_permission or not obj_roles) or role_match(ob, obj_permission, obj_roles))): if apply_func: apply_func(ob, (apply_path + '/' + p)) else: add_result((p, ob)) dflag = 0 if search_sub and hasattr(bs, 'objectItems'): self.ZopeFindAndApply(ob, obj_ids, obj_metatypes, obj_searchterm, obj_expr, obj_mtime, obj_mspec, obj_permission, obj_roles, search_sub, REQUEST, result, p, apply_func, apply_path) if dflag: ob._p_deactivate() return result
def __init__(self, name, default=('Manager',)): self.__name__ = name self._p = getPermissionIdentifier(name) self._d = self.__roles__ = default
def __init__(self, name, default=('Manager', )): self.__name__ = name self._p = getPermissionIdentifier(name) self._d = self.__roles__ = default
def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None, obj_searchterm=None, obj_expr=None, obj_mtime=None, obj_mspec=None, obj_permission=None, obj_roles=None, search_sub=0, REQUEST=None, result=None, pre='', apply_func=None, apply_path=''): """Zope Find interface and apply.""" if result is None: result = [] if obj_metatypes and 'all' in obj_metatypes: obj_metatypes = None if obj_mtime and isinstance(obj_mtime, str): obj_mtime = DateTime(obj_mtime).timeTime() if obj_permission: obj_permission = getPermissionIdentifier(obj_permission) if obj_roles and isinstance(obj_roles, str): obj_roles = [obj_roles] if obj_expr: # Setup expr machinations md = td() obj_expr = (Eval(obj_expr), md, md._push, md._pop) base = aq_base(obj) if not hasattr(base, 'objectItems'): return result try: items = obj.objectItems() except Exception: return result try: add_result = result.append except Exception: raise AttributeError(repr(result)) for id, ob in items: if pre: p = "%s/%s" % (pre, id) else: p = id dflag = 0 if hasattr(ob, '_p_changed') and (ob._p_changed is None): dflag = 1 bs = aq_base(ob) if obj_searchterm: if isinstance(obj_searchterm, TaintedString): obj_searchterm = str(obj_searchterm) if not isinstance(obj_searchterm, str): obj_searchterm = obj_searchterm.decode( default_encoding) if hasattr(ob, 'PrincipiaSearchSource'): pss = ob.PrincipiaSearchSource() if not isinstance(pss, str): try: pss = pss.decode(default_encoding) except UnicodeDecodeError: pss = '' if hasattr(ob, 'SearchableText'): st = ob.SearchableText() if not isinstance(st, str): try: st = st.decode(default_encoding) except UnicodeDecodeError: st = '' else: pss = st = '' if ((not obj_ids or absattr(bs.getId()) in obj_ids) and (not obj_metatypes or (hasattr(bs, 'meta_type') and bs.meta_type in obj_metatypes)) and (not obj_searchterm or (hasattr(ob, 'PrincipiaSearchSource') and obj_searchterm in pss) or (hasattr(ob, 'SearchableText') and obj_searchterm in st)) and (not obj_expr or expr_match(ob, obj_expr)) and (not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec)) and ((not obj_permission or not obj_roles) or role_match(ob, obj_permission, obj_roles))): if apply_func: apply_func(ob, (apply_path + '/' + p)) else: add_result((p, ob)) dflag = 0 if search_sub and hasattr(bs, 'objectItems'): self.ZopeFindAndApply(ob, obj_ids, obj_metatypes, obj_searchterm, obj_expr, obj_mtime, obj_mspec, obj_permission, obj_roles, search_sub, REQUEST, result, p, apply_func, apply_path) if dflag: ob._p_deactivate() return result
def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None, obj_searchterm=None, obj_expr=None, obj_mtime=None, obj_mspec=None, obj_permission=None, obj_roles=None, search_sub=0, REQUEST=None, result=None, pre='', apply_func=None, apply_path=''): """Zope Find interface and apply""" if result is None: result = [] if obj_metatypes and 'all' in obj_metatypes: obj_metatypes = None if obj_mtime and isinstance(obj_mtime, str): obj_mtime = DateTime(obj_mtime).timeTime() if obj_permission: obj_permission = getPermissionIdentifier(obj_permission) if obj_roles and isinstance(obj_roles, str): obj_roles = [obj_roles] if obj_expr: # Setup expr machinations md = td() obj_expr = (Eval(obj_expr), md, md._push, md._pop) base = aq_base(obj) if not hasattr(base, 'objectItems'): return result try: items = obj.objectItems() except Exception: return result try: add_result = result.append except Exception: raise AttributeError(repr(result)) for id, ob in items: if pre: p = "%s/%s" % (pre, id) else: p = id dflag = 0 if hasattr(ob, '_p_changed') and (ob._p_changed is None): dflag = 1 bs = aq_base(ob) if ((not obj_ids or absattr(bs.getId()) in obj_ids) and (not obj_metatypes or (hasattr(bs, 'meta_type') and bs.meta_type in obj_metatypes)) and (not obj_searchterm or (hasattr(ob, 'PrincipiaSearchSource') and obj_searchterm in ob.PrincipiaSearchSource()) or (hasattr(ob, 'SearchableText') and obj_searchterm in ob.SearchableText()) ) and (not obj_expr or expr_match(ob, obj_expr)) and (not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec)) and ((not obj_permission or not obj_roles) or role_match(ob, obj_permission, obj_roles))): if apply_func: apply_func(ob, (apply_path + '/' + p)) else: add_result((p, ob)) dflag = 0 if search_sub and hasattr(bs, 'objectItems'): self.ZopeFindAndApply(ob, obj_ids, obj_metatypes, obj_searchterm, obj_expr, obj_mtime, obj_mspec, obj_permission, obj_roles, search_sub, REQUEST, result, p, apply_func, apply_path) if dflag: ob._p_deactivate() return result
def setPermissionMapping(name, obj, v): name = getPermissionIdentifier(name) if v: setattr(obj, name, getPermissionIdentifier(v)) elif name in obj.__dict__: delattr(obj, name)
def setPermissionMapping(name, obj, v): name = getPermissionIdentifier(name) if v: setattr(obj, name, getPermissionIdentifier(v)) elif name in obj.__dict__: delattr(obj, name)