Check if a request is allowed to perform sudo actions
342669
def has_sudo_privileges(request):
    
    if getattr(request, '_sudo', None) is None:
        try:
            request._sudo = (
                request.user.is_authenticated() and
                constant_time_compare(
                    request.get_signed_cookie(COOKIE_NAME, salt=COOKIE_SALT, max_age=COOKIE_AGE),
                    request.session[COOKIE_NAME]
                )
            )
        except (KeyError, BadSignature):
            request._sudo = False
    return request._sudo
666005
def revoke_sudo_privileges(request):
    
    request._sudo = False
    if COOKIE_NAME in request.session:
        del request.session[COOKIE_NAME]
874906
public function can($action, $method_code = null, $module_id = null) : bool {
		if (empty($this->controller_id)) return false;
		// module id
		if (empty($module_id)) {
			$module_id = $this->module_id;
			if (empty($module_id)) {
				Throw new \Exception('You must specify correct module #');
			}
		}
		// run permission
		return $this->canExtended($this->controller_id, $method_code ?? $this->method_code, $action, $module_id);
	}
1340217
def is_authorized(self, request):
        
        if self._is_request_in_include_path(request):
            if self._is_request_in_exclude_path(request):
                return True
            else:
                auth = request.authorization
                if auth and auth[0] == 'Basic':
                    credentials = b64decode(auth[1]).decode('UTF-8')
                    username, password = credentials.split(':', 1)
                    return self._users.get(username) == password
                else:
                    return False
        else:
            return True
1097635
def has_privileges(self, body, user=None, params=None):
        
        if body in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'body'.")
        return self.transport.perform_request(
            "GET",
            _make_path("_security", "user", user, "_has_privileges"),
            params=params,
            body=body,
        )
244332
protected function _isActionEnabled(ServerRequest $request) {
		$actions = $this->getConfig('actions');
		if (!$actions) {
			return true;
		}

		return in_array($request->getParam('action'), $actions, true);
	}
81698
public function get_item_permissions_check( $request ) {

		$tax_obj = get_taxonomy( $request['taxonomy'] );

		if ( $tax_obj ) {
			if ( empty( $tax_obj->show_in_rest ) ) {
				return false;
			}
			if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->manage_terms ) ) {
				return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage this resource.' ), array( 'status' => rest_authorization_required_code() ) );
			}
		}

		return true;
	}
528608
def has_read_permission(self, request, path):
        
        user = request.user
        if not user.is_authenticated():
            return False
        elif user.is_superuser:
            return True
        elif user.is_staff:
            return True
        else:
            return False
1024033
def has_add_permission(self, request):
        
        opts = self.opts
        return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission())
1343271
def can(self):
        """"""
        return str(current_user.get_id()) == str(self.community.id_user) or \
            DynamicPermission(ActionNeed('admin-access')).can()
845784
def sudo_required(func):
    
    @wraps(func)
    def inner(request, *args, **kwargs):
        if not request.is_sudo():
            return redirect_to_sudo(request.get_full_path())
        return func(request, *args, **kwargs)
    return inner
298497
def check_public_permissions(payload):
    """"""
    allowed_public_permissions = ['view', 'add', 'download']
    for perm_type in ['add', 'remove']:
        for perm in payload.get('public', {}).get(perm_type, []):
            if perm not in allowed_public_permissions:
                raise exceptions.PermissionDenied("Permissions for public users are too open")
431798
private function checkPermissions()
    {
        foreach ($this->writableDirectories as $path) {
            if (!$this->filesystem->isWritable(base_path($path))) {
                $this->console->error($path . ' is not writable');
                $this->errors = true;
            }
        }
    }
899293
def has_moderator_permissions(self, request):
        
        return any(request.user.has_perm(perm) for perm in self.permission_required)
1191715
def sudo_scan(options={},exec_options={},&block)
      sudo_task(Task.new(options,&block),exec_options)
    end
1015074
def isAuthorized(self, request):
        
        restrictions = self.get_view_restrictions()
        if restrictions and request is None:
            return False
        else:
            return all(restriction.accept_request(request)
                       for restriction in restrictions)
36410
def allow(self, privilege):
        """"""
        assert privilege in PERMISSIONS['user'].keys()
        reading = PERMISSIONS['user'][privilege] + PERMISSIONS['group'][privilege] + PERMISSIONS['other'][privilege]
        os.chmod(self.file_path, reading)