Finds and returns a Permission by name
188486
def find_permission(self, name):
        
        return (
            self.get_session.query(self.permission_model).filter_by(name=name).first()
        )
415653
def check_permission(*permissions, **args_map):
    
    def f1(func, permissions=permissions):
        @wraps(func)
        def f2(*args, **kwargs):
            from uliweb import request, error

            arguments = {}
            for k, v in args_map.items():
                if v in kwargs:
                    arguments[k] = kwargs[v]
            if not has_permission(request.user, *permissions, **arguments):
                error(_("You have no permissions to visit this page."))
            return func(*args, **kwargs)
        return f2
    return f1
58588
def get_permissions(self):
        
        return [p.permission.code for p in self.Permissions if p.permission.code]
517507
public static function findByName(string $name, $guardName = null): PermissionContract
    {
        $guardName = $guardName ?? Guard::getDefaultName(static::class);

        $permission = static::getPermissions()->where('name', $name)->where('guard_name', $guardName)->first();

        if (! $permission) {
            throw PermissionDoesNotExist::create($name, $guardName);
        }

        return $permission;
    }
449979
def findUserByVanityName(name)
      method = 'findUser'
      type = User
      args = {:vanityName=>name}
      return_object type,method,args
    end
752269
def get_by_name(self, name):
        """"""
        for section in self.values():
            for preference in section.values():
                if preference.name == name:
                    return preference
        raise NotFoundInRegistry("No such preference in {0} with name={1}".format(
            self.__class__.__name__, name))
944968
def object_permission_set(self):
        ''''''
        return Or(
            AllowOnlySafeHttpMethod,
            AllowAdmin,
            And(
                AllowPermission('org:admin'),
                ObjAttrTrue(lambda _, u: not u.is_superuser),
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True)
            ),
            And(
                AllowModify,
                ObjAttrTrue(
                    lambda req, user: user == req.user),
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True)
            ),
        )
346237
def filer_has_permission(context, item, action):
    
    permission_method_name = 'has_{action}_permission'.format(action=action)
    permission_method = getattr(item, permission_method_name, None)
    request = context.get('request')

    if not permission_method or not request:
        return False
    # Call the permission method.
    # This amounts to calling `item.has_X_permission(request)`
    return permission_method(request)
434246
def get_permissions(self, rights=[]):
        
        aces = []
        if rights:
            for right in rights:
                ace = self.request(
                    'GetPermission',
                    {'ace': {
                        'right': {'_content': right}}})

                if 'ace' in ace.keys() and isinstance(ace, list):
                    aces.extend(ace['ace'])
                elif 'ace' in ace.keys() and isinstance(ace, dict):
                    aces.append(ace['ace'])
            return {'ace': aces}

        else:
            ace = self.request('GetPermission', {})
            if 'ace' in ace.keys() and isinstance(ace['ace'], list):
                return ace
            elif 'ace' in ace.keys() and isinstance(ace['ace'], dict):
                return ace
            else:
                return {'ace': []}
1223157
def get(self, name):
        

        # check read permission
        sm = getSecurityManager()
        permission = permissions.View
        if not sm.checkPermission(permission, self.context):
            raise Unauthorized("Not allowed to view the Plone portal")

        # read the attribute
        attr = getattr(self.context, name, None)
        if callable(attr):
            return attr()

        # XXX no really nice, but we want the portal to behave like an ordinary
        # content type. Therefore we need to inject the neccessary data.
        if name == "uid":
            return "0"
        if name == "path":
            return "/%s" % self.context.getId()
        return attr
357420
protected function findPermission($name)
    {
        $permission = $this->authManager->getPermission($name);

        if ($permission instanceof Permission) {
            return $permission;
        }

        return null;
    }
460407
def permission_set(self, name, func=None):
        
        if func is None:
            return functools.partial(self.predicate, name)
        self.permission_sets[name] = func
        return func
317087
def _permission_trees(permissions):
        """"""
        treecache = PermissionTreeCache()
        cached = treecache.get()
        if not cached:
            tree = PermissionTreeBuilder()
            for permission in permissions:
                tree.insert(permission)
            result = tree.serialize()
            treecache.set(result)
            return result
        return cached
644023
def trusted_permission(f):
    """"""

    @functools.wraps(f)
    def wrapper(request, *args, **kwargs):
        trusted(request)
        return f(request, *args, **kwargs)

    return wrapper
252702
def get_project_by_name(project_name,**kwargs):
    
    user_id = kwargs.get('user_id')

    projects_i = db.DBSession.query(Project).join(ProjectOwner).filter(
                                                    Project.name==project_name,
                                                    ProjectOwner.user_id==user_id).order_by('name').all()

    ret_projects = []
    for project_i in projects_i:
        try:
            project_i.check_read_permission(user_id)
            ret_projects.append(project_i)
        except:
            log.info("Can't return project %s. User %s does not have permission to read it.", project_i.id, user_id)

    return ret_projects
157785
def has_access(f):
    
    if hasattr(f, '_permission_name'):
        permission_str = f._permission_name
    else:
        permission_str = f.__name__

    def wraps(self, *args, **kwargs):
        permission_str = PERMISSION_PREFIX + f._permission_name
        if self.appbuilder.sm.has_access(
                permission_str,
                self.__class__.__name__
        ):
            return f(self, *args, **kwargs)
        else:
            log.warning(
                LOGMSG_ERR_SEC_ACCESS_DENIED.format(
                    permission_str,
                    self.__class__.__name__
                )
            )
            flash(as_unicode(FLAMSG_ERR_SEC_ACCESS_DENIED), "danger")
        return redirect(
            url_for(
                self.appbuilder.sm.auth_view.__class__.__name__ + ".login",
                next=request.url
            )
        )
    f._permission_name = permission_str
    return functools.update_wrapper(wraps, f)
698230
def get_permissions(self):
        
        user_role = self.last_login_role() if self.last_login_role_key else self.role_set[0].role
        return user_role.get_permissions()