Return the name of the permission for a given model and action.

    By default it returns the full permission name `app_label.perm_codename`. If `full=False`, it returns only the
    `perm_codename`.
559153
def get_perm_name(cls, action, full=True):
    
    codename = "{}_{}".format(action, cls.__name__.lower())
    if full:
        return "{}.{}".format(cls._meta.app_label, codename)
    return codename
154692
def find_permission_view_menu(self, permission_name, view_menu_name):
        
        permission = self.find_permission(permission_name)
        view_menu = self.find_view_menu(view_menu_name)
        if permission and view_menu:
            return (
                self.get_session.query(self.permissionview_model)
                .filter_by(permission=permission, view_menu=view_menu)
                .first()
            )
1123199
public function getPermissionIdFromName($perm_name)
    {
        $permission = static::$app['db']->connection()
            ->table('permissions')->where('name', '=', $perm_name)->first();

        return $permission->id;
    }
525063
def get_perms_object(obj, action):
    
    def get_one(pf):
        if isinstance(pf, str):
            return pf
        else:
            return str(reduce(lambda o, f: getattr(o, f), pf, obj))
    return Object([get_one(pf) for pf in obj.__class__.TutelaryMeta.pfs])
900611
def build_permission_name(model_class, prefix):
    
    model_name = model_class._meta.object_name.lower()
    app_label = model_class._meta.app_label
    action_name = prefix
    perm = '%s.%s_%s' % (app_label, action_name, model_name)
    return perm
255739
def validate_permission(self, key, permission):
        
        if permission.perm_name not in self.__possible_permissions__:
            raise AssertionError(
                "perm_name is not one of {}".format(self.__possible_permissions__)
            )
        return permission
516657
def _get_all_permissions(opts):
    ""
    perms = []
    for action in settings.DEFAULT_PERMISSIONS:
        perms.append((_get_permission_codename(action, opts), 'Can %s %s' % (action, opts.verbose_name_raw)))
    return perms + list(opts.permissions)
434449
public function getActionName()
    {
        $action = $this->app->getAction();
        if (isset($this->actionPermissions[$action])) {
            return $this->actionPermissions[$action];
        }

        foreach ($this->actionPermissions as $actions => $name) {
            $actions = explode(',', $actions);
            if (in_array($action, $actions)) {
                return $name;
            }
        }

        return null;
    }
1061858
function (perm) {
                        var permObjId;

                        // Look for a matching action type and object type first
                        if (perm.get('action_type') !== actType || perm.get('object_type') !== objType) {
                            return false;
                        }

                        // Grab the object id (if specified, could be null)
                        permObjId = perm.get('object_id');

                        // If we didn't specify a model (any thing)
                        // or the permission didn't have an id scope set
                        // then the "thing" has permission
                        if (!modelId || !permObjId) {
                            return true;
                        }

                        // Otherwise, check if the id's match
                        // TODO: String vs Int comparison possibility here?
                        return modelId === permObjId;
                    }
410985
def permission_for_action(self, action):
        
        return "%s.%s_%s" % (self.app_name.lower(), self.model_name.lower(), action)
1096730
def get_full_perm(perm, obj):
    
    ctype = ContentType.objects.get_for_model(obj)
    # Camel case class names are converted into a space-separated
    # content types, so spaces have to be removed.
    ctype = str(ctype).replace(' ', '')

    return '{}_{}'.format(perm.lower(), ctype)
591784
def permission_required(perm, *lookup_variables, **kwargs):
    
    login_url = kwargs.pop('login_url', settings.LOGIN_URL)
    redirect_field_name = kwargs.pop('redirect_field_name', REDIRECT_FIELD_NAME)
    redirect_to_login = kwargs.pop('redirect_to_login', True)

    def decorate(view_func):
        def decorated(request, *args, **kwargs):
            if request.user.is_authenticated():
                params = []
                for lookup_variable in lookup_variables:
                    if isinstance(lookup_variable, string_types):
                        value = kwargs.get(lookup_variable, None)
                        if value is None:
                            continue
                        params.append(value)
                    elif isinstance(lookup_variable, (tuple, list)):
                        model, lookup, varname = lookup_variable
                        value = kwargs.get(varname, None)
                        if value is None:
                            continue
                        if isinstance(model, string_types):
                            model_class = apps.get_model(*model.split("."))
                        else:
                            model_class = model
                        if model_class is None:
                            raise ValueError(
                                "The given argument '%s' is not a valid model." % model)
                        if (inspect.isclass(model_class) and
                                not issubclass(model_class, Model)):
                            raise ValueError(
                                'The argument %s needs to be a model.' % model)
                        obj = get_object_or_404(model_class, **{lookup: value})
                        params.append(obj)
                check = get_check(request.user, perm)
                granted = False
                if check is not None:
                    granted = check(*params)
                if granted or request.user.has_perm(perm):
                    return view_func(request, *args, **kwargs)
            if redirect_to_login:
                path = urlquote(request.get_full_path())
                tup = login_url, redirect_field_name, path
                return HttpResponseRedirect('%s?%s=%s' % tup)
            return permission_denied(request)
        return wraps(view_func)(decorated)
    return decorate
5479
def has_permission(self, request, view):
        """"""
        if view.suffix == 'Instance':
            return True

        filter_and_actions = self._get_filter_and_actions(
            request.query_params.get('sign'),
            view.action,
            '{}.{}'.format(
                view.queryset.model._meta.app_label,
                view.queryset.model._meta.model_name
            )
        )
        if not filter_and_actions:
            return False
        if request.method == 'POST':
            for key, value in request.data.iteritems():
                # Do unicode conversion because value will always be a
                # string
                if (key in filter_and_actions['filters'] and not
                        unicode(filter_and_actions['filters'][key]) == unicode(value)):
                    return False
        return True
904089
def permissions(self, perms):
        

        if not isinstance(perms, (list, tuple)):
            perms = [perms]

        instances = []

        for perm in perms:
            if isclass(perm):
                instances.append(perm())
            else:
                instances.append(perm)

        def decorator(func):
            func.permissions = instances
            return func
        return decorator
1205608
def has_permission(self, request, view):
        
        if not self.global_permissions:
            return True

        serializer_class = view.get_serializer_class()

        assert serializer_class.Meta.model is not None, (
            "global_permissions set to true without a model "
            "set on the serializer for '%s'" % view.__class__.__name__
        )

        model_class = serializer_class.Meta.model

        action_method_name = None
        if hasattr(view, 'action'):
            action = self._get_action(view.action)
            action_method_name = "has_{action}_permission".format(action=action)
            # If the specific action permission exists then use it, otherwise use general.
            if hasattr(model_class, action_method_name):
                return getattr(model_class, action_method_name)(request)

        if request.method in permissions.SAFE_METHODS:
            assert hasattr(model_class, 'has_read_permission'), \
                self._get_error_message(model_class, 'has_read_permission', action_method_name)
            return model_class.has_read_permission(request)
        else:
            assert hasattr(model_class, 'has_write_permission'), \
                self._get_error_message(model_class, 'has_write_permission', action_method_name)
            return model_class.has_write_permission(request)
406619
def get_perm(perm_id,**kwargs):
    

    try:
        perm = db.DBSession.query(Perm).filter(Perm.id==perm_id).one()
        return perm
    except NoResultFound:
        raise ResourceNotFoundError("Permission not found (perm_id={})".format(perm_id))
188486
def find_permission(self, name):
        
        return (
            self.get_session.query(self.permission_model).filter_by(name=name).first()
        )