Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow EnableQueryAttribute derived classes to specify IgnoreQueryOptions #2648

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/Microsoft.AspNet.OData.Shared/Query/ODataQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public partial class ODataQueryOptions

private ODataQueryOptionParser _queryOptionParser;

private AllowedQueryOptions _ignoreQueryOptions = AllowedQueryOptions.None;

private ETag _etagIfMatch;

private bool _etagIfMatchChecked;
Expand Down Expand Up @@ -150,6 +148,11 @@ private void Initialize(ODataQueryContext context)
/// </summary>
public ODataQueryValidator Validator { get; set; }

/// <summary>
/// Gets or sets the query options that will be ignored.
/// </summary>
public AllowedQueryOptions IgnoreQueryOptions { get; set; }

/// <summary>
/// Gets or sets the request headers.
/// </summary>
Expand Down Expand Up @@ -290,7 +293,7 @@ public virtual IQueryable ApplyTo(IQueryable query)
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
public virtual IQueryable ApplyTo(IQueryable query, AllowedQueryOptions ignoreQueryOptions)
{
_ignoreQueryOptions = ignoreQueryOptions;
this.IgnoreQueryOptions = ignoreQueryOptions;
return ApplyTo(query, new ODataQuerySettings());
}

Expand All @@ -301,10 +304,12 @@ public virtual IQueryable ApplyTo(IQueryable query, AllowedQueryOptions ignoreQu
/// <param name="querySettings">The settings to use in query composition.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
public virtual IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings,
public virtual IQueryable ApplyTo(
IQueryable query,
ODataQuerySettings querySettings,
AllowedQueryOptions ignoreQueryOptions)
{
_ignoreQueryOptions = ignoreQueryOptions;
this.IgnoreQueryOptions = ignoreQueryOptions;
return ApplyTo(query, querySettings);
}

Expand Down Expand Up @@ -530,8 +535,8 @@ private static void ExtractGroupingProperties(List<string> result, IEnumerable<G
/// query options.</remarks>
public virtual object ApplyTo(object entity, ODataQuerySettings querySettings, AllowedQueryOptions ignoreQueryOptions)
{
_ignoreQueryOptions = ignoreQueryOptions;
return ApplyTo(entity, new ODataQuerySettings());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this was a bug...

this.IgnoreQueryOptions = ignoreQueryOptions;
return ApplyTo(entity, querySettings);
}

/// <summary>
Expand Down Expand Up @@ -987,7 +992,7 @@ private void BuildQueryOptions(IDictionary<string, string> queryParameters)

private bool IsAvailableODataQueryOption(object queryOption, AllowedQueryOptions queryOptionFlag)
{
return ((queryOption != null) && ((_ignoreQueryOptions & queryOptionFlag) == AllowedQueryOptions.None));
return (queryOption != null) && ((this.IgnoreQueryOptions & queryOptionFlag) == AllowedQueryOptions.None);
}

private T ApplySelectExpand<T>(T entity, ODataQuerySettings querySettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ public class Microsoft.AspNet.OData.Query.ODataQueryOptions {
FilterQueryOption Filter { public get; }
ETag IfMatch { public virtual get; }
ETag IfNoneMatch { public virtual get; }
AllowedQueryOptions IgnoreQueryOptions { public get; public set; }
OrderByQueryOption OrderBy { public get; }
ODataRawQueryOptions RawValues { public get; }
System.Net.Http.HttpRequestMessage Request { public get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,7 @@ public class Microsoft.AspNet.OData.Query.ODataQueryOptions {
FilterQueryOption Filter { public get; }
ETag IfMatch { public virtual get; }
ETag IfNoneMatch { public virtual get; }
AllowedQueryOptions IgnoreQueryOptions { public get; public set; }
OrderByQueryOption OrderBy { public get; }
ODataRawQueryOptions RawValues { public get; }
Microsoft.AspNetCore.Http.HttpRequest Request { public get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,7 @@ public class Microsoft.AspNet.OData.Query.ODataQueryOptions {
FilterQueryOption Filter { public get; }
ETag IfMatch { public virtual get; }
ETag IfNoneMatch { public virtual get; }
AllowedQueryOptions IgnoreQueryOptions { public get; public set; }
OrderByQueryOption OrderBy { public get; }
ODataRawQueryOptions RawValues { public get; }
Microsoft.AspNetCore.Http.HttpRequest Request { public get; }
Expand Down