/// <inheritdoc />
        public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
        {
            ArgumentGuard.NotNull(disableQueryStringAttribute, nameof(disableQueryStringAttribute));

            return(!IsAtomicOperationsRequest &&
                   !disableQueryStringAttribute.ContainsParameter(StandardQueryStringParameters.Sort));
        }
        /// <inheritdoc />
        public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
        {
            ArgumentGuard.NotNull(disableQueryStringAttribute, nameof(disableQueryStringAttribute));

            return(_options.AllowQueryStringOverrideForSerializerNullValueHandling &&
                   !disableQueryStringAttribute.ContainsParameter(StandardQueryStringParameters.Nulls));
        }
Пример #3
0
        /// <inheritdoc />
        public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
        {
            if (disableQueryStringAttribute == null)
            {
                throw new ArgumentNullException(nameof(disableQueryStringAttribute));
            }

            return(!disableQueryStringAttribute.ContainsParameter(StandardQueryStringParameters.Filter));
        }
Пример #4
0
        /// <inheritdoc />
        public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
        {
            if (disableQueryStringAttribute == null)
            {
                throw new ArgumentNullException(nameof(disableQueryStringAttribute));
            }

            return(!IsAtomicOperationsRequest &&
                   !disableQueryStringAttribute.ContainsParameter(StandardQueryStringParameters.Include));
        }
Пример #5
0
        /// <inheritdoc />
        public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
        {
            if (disableQueryStringAttribute == null)
            {
                throw new ArgumentNullException(nameof(disableQueryStringAttribute));
            }

            return(_options.AllowQueryStringOverrideForSerializerDefaultValueHandling &&
                   !disableQueryStringAttribute.ContainsParameter(StandardQueryStringParameters.Defaults));
        }
Пример #6
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            DisableQueryStringAttribute disableQueryStringAttribute = context.Controller.GetType().GetCustomAttribute <DisableQueryStringAttribute>();

            _queryStringReader.ReadAll(disableQueryStringAttribute);
            await next();
        }
Пример #7
0
        /// <inheritdoc />
        public virtual void ReadAll(DisableQueryStringAttribute disableQueryStringAttribute)
        {
            var disableQueryStringAttributeNotNull = disableQueryStringAttribute ?? DisableQueryStringAttribute.Empty;

            foreach (var(parameterName, parameterValue) in _queryStringAccessor.Query)
            {
                if (string.IsNullOrEmpty(parameterValue))
                {
                    throw new InvalidQueryStringParameterException(parameterName,
                                                                   "Missing query string parameter value.",
                                                                   $"Missing value for '{parameterName}' query string parameter.");
                }

                var reader = _parameterReaders.FirstOrDefault(r => r.CanRead(parameterName));
                if (reader != null)
                {
                    _logger.LogDebug(
                        $"Query string parameter '{parameterName}' with value '{parameterValue}' was accepted by {reader.GetType().Name}.");

                    if (!reader.IsEnabled(disableQueryStringAttributeNotNull))
                    {
                        throw new InvalidQueryStringParameterException(parameterName,
                                                                       "Usage of one or more query string parameters is not allowed at the requested endpoint.",
                                                                       $"The parameter '{parameterName}' cannot be used at this endpoint.");
                    }

                    reader.Read(parameterName, parameterValue);
                    _logger.LogDebug($"Query string parameter '{parameterName}' was successfully read.");
                }
                else if (!_options.AllowUnknownQueryStringParameters)
                {
                    throw new InvalidQueryStringParameterException(parameterName, "Unknown query string parameter.",
                                                                   $"Query string parameter '{parameterName}' is unknown. " +
                                                                   $"Set '{nameof(IJsonApiOptions.AllowUnknownQueryStringParameters)}' to 'true' in options to ignore unknown parameters.");
                }
            }
        }
 /// <inheritdoc />
 public virtual bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
 {
     return(true);
 }
 public bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute)
 {
     return(!disableQueryStringAttribute.ParameterNames.Contains(_skipCacheParameterName));
 }