Check if the user has permissions to run URL debug tools,
else redirect them to log in.
770962
public static function require_developer_login()
    {
        // Don't require login for dev mode
        if (Director::isDev()) {
            return;
        }

        if (isset($_SESSION['loggedInAs'])) {
            // We have to do some raw SQL here, because this method is called in Object::defineMethods().
            // This means we have to be careful about what objects we create, as we don't want Object::defineMethods()
            // being called again.
            // This basically calls Permission::checkMember($_SESSION['loggedInAs'], 'ADMIN');

            // @TODO - Rewrite safely using DataList::filter
            $memberID = $_SESSION['loggedInAs'];
            $permission = DB::prepared_query(
                '
				SELECT "ID" FROM "Permission"
				INNER JOIN "Group_Members" ON "Permission"."GroupID" = "Group_Members"."GroupID"
				WHERE "Permission"."Code" = ?
				AND "Permission"."Type" = ?
				AND "Group_Members"."MemberID" = ?',
                array(
                    'ADMIN', // Code
                    Permission::GRANT_PERMISSION, // Type
                    $memberID // MemberID
                )
            )->value();

            if ($permission) {
                return;
            }
        }

        // This basically does the same as
        // Security::permissionFailure(null, "You need to login with developer access to make use of debugging tools.")
        // We have to do this because of how early this method is called in execution.
        $_SESSION['SilverStripe\\Security\\Security']['Message']['message']
            = "You need to login with developer access to make use of debugging tools.";
        $_SESSION['SilverStripe\\Security\\Security']['Message']['type'] =  'warning';
        $_SESSION['BackURL'] = $_SERVER['REQUEST_URI'];
        header($_SERVER['SERVER_PROTOCOL'] . " 302 Found");
        header("Location: " . Director::baseURL() . Security::login_url());
        die();
    }
1170867
def _permission_denied_check(request):
    '''

    '''
    allowed_ips = settings.EUL_INDEXER_ALLOWED_IPS
    if allowed_ips != "ANY" and not request.META['REMOTE_ADDR'] in allowed_ips:
        return True

    return False
165221
def has_permission(self, *args, **kwargs):
        """"""
        def wrapper(view):
            if getattr(view, '_has_permissions_decorator', False) is True:
                return view

            @wraps(view)
            @jsonapi_exception_formatter
            def decorated(*view_args, **view_kwargs):
                self.check_permissions(view, view_args, view_kwargs, *args, **kwargs)
                return view(*view_args, **view_kwargs)
            decorated._has_permissions_decorator = True
            return decorated
        return wrapper
338383
def _check_logged_user(self):
        """"""
        if not self._env or not self._password or not self._login:
            raise error.InternalError("Login required")
1354520
def check_rights_and_access(request, meta, project=None):
    """"""
    # User must be logged ?
    if ('only_logged_user' in meta and meta['only_logged_user']):
        if not request.user.is_authenticated():
            return gen403(request, baseURI, 'only_logged_user', project)

    # User must be member of the project ?
    if ('only_member_user' in meta and meta['only_member_user']):
        if not request.user.ebuio_member:
            return gen403(request, baseURI, 'only_member_user', project)

    # User must be administrator of the project ?
    if ('only_admin_user' in meta and meta['only_admin_user']):
        if not request.user.ebuio_admin:
            return gen403(request, baseURI, 'only_admin_user', project)

    # User must be member of the orga ?
    if ('only_orga_member_user' in meta and meta['only_orga_member_user']):
        if not request.user.ebuio_orga_member:
            return gen403(request, baseURI, 'only_orga_member_user', project)

    # User must be administrator of the orga ?
    if ('only_orga_admin_user' in meta and meta['only_orga_admin_user']):
        if not request.user.ebuio_orga_admin:
            return gen403(request, baseURI, 'only_orga_admin_user', project)

    # Remote IP must be in range ?
    if ('address_in_networks' in meta):
        if not is_requestaddress_in_networks(request, meta['address_in_networks']):
            return gen403(request, baseURI, 'address_in_networks', project)
169981
def run(self, value, errors, request):
        """"""
        thing = super(AccessibleDBThing, self).run(value, errors, request)
        if errors:
            return None
        if not thing.can_access(request.user):
            message = 'Insufficient permissions for {0}'.format(self.param)
            raise HTTPForbidden(message)
        return thing
476668
def has_project_permissions(user: 'User', project: 'Project', request_method: str) -> bool:
    """"""
    # Superusers and the creator is allowed to do everything
    if user.is_staff or user.is_superuser or project.user == user:
        return True

    # Other user
    return request_method in permissions.SAFE_METHODS and project.is_public
1347708
def get_user_permissions(self, username):
        

        path = Client.urls['user_permissions'] % (username,)
        conns = self._call(path, 'GET')
        return conns
813871
def has_permission(self):
        """"""
        objs = [None]
        if hasattr(self, 'get_perms_objects'):
            objs = self.get_perms_objects()
        else:
            if hasattr(self, 'get_object'):
                try:
                    objs = [self.get_object()]
                except Http404:
                    raise
                except:
                    pass
            if objs == [None]:
                objs = self.get_queryset()

        if (hasattr(self, 'permission_filter_queryset') and
           self.permission_filter_queryset is not False and
           self.request.method == 'GET'):
            if objs != [None]:
                self.perms_filter_queryset(objs)
            return True
        else:
            return check_perms(self.request.user,
                               self.get_permission_required(),
                               objs, self.request.method)
1209190
def check_permissions(self, request):
        """"""

        if not self.predicates:
            return True

        # All registered authentication predicates must return True
        return all(
            predicate(request, *self.predicates_params[i])
            for i, predicate in enumerate(self.predicates)
        )
124269
def process_request(self, request):
        """"""
        assert hasattr(request, 'user')
        if not request.user.is_authenticated():
            path = request.path_info.lstrip('/')
            if not any(m.match(path) for m in EXEMPT_URLS):
                return HttpResponseRedirect(reverse(settings.LOGIN_URL))
1157871
def has_permission(user, permission_name):
    """"""
    if user and user.is_superuser:
        return True

    return permission_name in available_perm_names(user)
369059
def can_view(self, user):
        """"""
        return user.is_admin or user in self.users \
            or self.project.class_ in user.admin_for
177715
private function checkPermission()
    {
        // creates system acl
        $acl = $this->initAcl();

        $identity = $this->getUser()->getIdentity();
        $permissions = $this->initPermissions($identity);
        foreach ($permissions as $key => $p) {
            if ($p && $acl->hasResource($key)) {
                $acl->allow($identity->roles[0], $key, Nette\Security\Permission::ALL);
            }
        }

        // homepage and login page can access everyone
        $acl->allow(Nette\Security\Permission::ALL, 'admin:Homepage', Nette\Security\Permission::ALL);
        $acl->allow(Nette\Security\Permission::ALL, 'admin:Login', Nette\Security\Permission::ALL);

        // superadmin has access to everywhere
        $acl->allow('superadmin', Nette\Security\Permission::ALL, Nette\Security\Permission::ALL);

        $roles = $this->getUser()->getRoles();

        if (!$this->checkRights($acl, $roles)) {
            $this->presenter->flashMessage($this->translation['You do not have a permission to do this operation!'], 'danger');
            $this->redirect(":Admin:Homepage:");
        }
    }
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
457790
def user_is_allowed(resource, action, json = false)
      if !logged_in?
        if json
          render :json => false
        else
          redirect_to "/login?return_url=" + URI.encode(request.fullpath)
        end
        return false
      end
      
      @user = logged_in_user
      if !@user.is_allowed(resource, action)        
        if json
          render :json => false
        else
          @error = "You don't have permission to " + action + " " + resource
          @return_url = request.fullpath
          render :template => "caboose/extras/error"
        end
        return false
      end
      
      return true    
    end
929044
def has_permission_to_view(page, user):
    
    if page.permissions.count() == 0:
        return True
    for perm in page.permissions.all():
        perm_label = '%s.%s' % (perm.content_type.app_label, perm.codename)
        if user.has_perm(perm_label):
            return True
    return False