From 94da1c70dca7e176c4a034509c8bce33b5c7d602 Mon Sep 17 00:00:00 2001 From: Brad Cleaver Date: Wed, 18 May 2022 10:59:22 -0700 Subject: [PATCH 1/4] Expose QuerySettings to derived classes --- src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs b/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs index 95f4036597..f23282a2f1 100644 --- a/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs +++ b/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs @@ -371,6 +371,11 @@ public int MaxOrderByNodeCount } } + /// + /// Gets the query settings. + /// + protected ODataQuerySettings QuerySettings => _querySettings; + /// /// Performs the query composition after action is executed. It first tries to retrieve the IQueryable from the /// returning response message. It then validates the query from uri based on the validation settings on From 75cb419328e7cce95cdc42277a258f00c219b7d4 Mon Sep 17 00:00:00 2001 From: Brad Cleaver Date: Wed, 18 May 2022 12:24:55 -0700 Subject: [PATCH 2/4] Fix public API tests --- .../PublicApi/Microsoft.AspNet.OData.PublicApi.bsl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl index 3837811a4d..59764948b4 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl @@ -434,6 +434,7 @@ public class Microsoft.AspNet.OData.EnableQueryAttribute : System.Web.Http.Filte int MaxSkip { public get; public set; } int MaxTop { public get; public set; } int PageSize { public get; public set; } + ODataQuerySettings QuerySettings { protected get; } public virtual System.Linq.IQueryable ApplyQuery (System.Linq.IQueryable queryable, ODataQueryOptions queryOptions) public virtual object ApplyQuery (object entity, ODataQueryOptions queryOptions) From c81cb16780fb3250f01b51148e9e9cb0ff1d9486 Mon Sep 17 00:00:00 2001 From: Brad Cleaver Date: Wed, 18 May 2022 13:01:47 -0700 Subject: [PATCH 3/4] Add fix the AspNetCore public tests --- .../PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl | 1 + .../PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl | 1 + 2 files changed, 2 insertions(+) diff --git a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl index 4e85dce1ad..ba4e84cf72 100644 --- a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl @@ -449,6 +449,7 @@ public class Microsoft.AspNet.OData.EnableQueryAttribute : Microsoft.AspNetCore. int MaxSkip { public get; public set; } int MaxTop { public get; public set; } int PageSize { public get; public set; } + ODataQuerySettings QuerySettings { protected get; } public virtual System.Linq.IQueryable ApplyQuery (System.Linq.IQueryable queryable, ODataQueryOptions queryOptions) public virtual object ApplyQuery (object entity, ODataQueryOptions queryOptions) diff --git a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl index 6e7ca5b085..d47d3f10c6 100644 --- a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl @@ -453,6 +453,7 @@ public class Microsoft.AspNet.OData.EnableQueryAttribute : Microsoft.AspNetCore. int MaxSkip { public get; public set; } int MaxTop { public get; public set; } int PageSize { public get; public set; } + ODataQuerySettings QuerySettings { protected get; } public virtual System.Linq.IQueryable ApplyQuery (System.Linq.IQueryable queryable, ODataQueryOptions queryOptions) public virtual object ApplyQuery (object entity, ODataQueryOptions queryOptions) From f11aae2dae00f5bd6187174d4cbbfae1039f5de0 Mon Sep 17 00:00:00 2001 From: ificator Date: Tue, 2 Aug 2022 14:31:42 -0700 Subject: [PATCH 4/4] Allowed `IgnoreQueryOptions` to be set. --- .../EnableQueryAttribute.cs | 5 ----- .../Query/ODataQueryOptions.cs | 21 ++++++++++++------- .../Microsoft.AspNet.OData.PublicApi.bsl | 2 +- .../Microsoft.AspNetCore.OData.PublicApi.bsl | 2 +- ...Microsoft.AspNetCore3x.OData.PublicApi.bsl | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs b/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs index f23282a2f1..95f4036597 100644 --- a/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs +++ b/src/Microsoft.AspNet.OData.Shared/EnableQueryAttribute.cs @@ -371,11 +371,6 @@ public int MaxOrderByNodeCount } } - /// - /// Gets the query settings. - /// - protected ODataQuerySettings QuerySettings => _querySettings; - /// /// Performs the query composition after action is executed. It first tries to retrieve the IQueryable from the /// returning response message. It then validates the query from uri based on the validation settings on diff --git a/src/Microsoft.AspNet.OData.Shared/Query/ODataQueryOptions.cs b/src/Microsoft.AspNet.OData.Shared/Query/ODataQueryOptions.cs index b75bc39858..8bd18525e7 100644 --- a/src/Microsoft.AspNet.OData.Shared/Query/ODataQueryOptions.cs +++ b/src/Microsoft.AspNet.OData.Shared/Query/ODataQueryOptions.cs @@ -40,8 +40,6 @@ public partial class ODataQueryOptions private ODataQueryOptionParser _queryOptionParser; - private AllowedQueryOptions _ignoreQueryOptions = AllowedQueryOptions.None; - private ETag _etagIfMatch; private bool _etagIfMatchChecked; @@ -150,6 +148,11 @@ private void Initialize(ODataQueryContext context) /// public ODataQueryValidator Validator { get; set; } + /// + /// Gets or sets the query options that will be ignored. + /// + public AllowedQueryOptions IgnoreQueryOptions { get; set; } + /// /// Gets or sets the request headers. /// @@ -290,7 +293,7 @@ public virtual IQueryable ApplyTo(IQueryable query) /// The new after the query has been applied to. public virtual IQueryable ApplyTo(IQueryable query, AllowedQueryOptions ignoreQueryOptions) { - _ignoreQueryOptions = ignoreQueryOptions; + this.IgnoreQueryOptions = ignoreQueryOptions; return ApplyTo(query, new ODataQuerySettings()); } @@ -301,10 +304,12 @@ public virtual IQueryable ApplyTo(IQueryable query, AllowedQueryOptions ignoreQu /// The settings to use in query composition. /// The query parameters that are already applied in queries. /// The new after the query has been applied to. - 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); } @@ -530,8 +535,8 @@ private static void ExtractGroupingProperties(List result, IEnumerable public virtual object ApplyTo(object entity, ODataQuerySettings querySettings, AllowedQueryOptions ignoreQueryOptions) { - _ignoreQueryOptions = ignoreQueryOptions; - return ApplyTo(entity, new ODataQuerySettings()); + this.IgnoreQueryOptions = ignoreQueryOptions; + return ApplyTo(entity, querySettings); } /// @@ -987,7 +992,7 @@ private void BuildQueryOptions(IDictionary 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 entity, ODataQuerySettings querySettings) diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl index bf896416f2..536da11d4d 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNet.OData.Test/PublicApi/Microsoft.AspNet.OData.PublicApi.bsl @@ -435,7 +435,6 @@ public class Microsoft.AspNet.OData.EnableQueryAttribute : System.Web.Http.Filte int MaxSkip { public get; public set; } int MaxTop { public get; public set; } int PageSize { public get; public set; } - ODataQuerySettings QuerySettings { protected get; } public virtual System.Linq.IQueryable ApplyQuery (System.Linq.IQueryable queryable, ODataQueryOptions queryOptions) public virtual object ApplyQuery (object entity, ODataQueryOptions queryOptions) @@ -2504,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; } diff --git a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl index 73c0c05d20..c50a5e8f0d 100644 --- a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl @@ -450,7 +450,6 @@ public class Microsoft.AspNet.OData.EnableQueryAttribute : Microsoft.AspNetCore. int MaxSkip { public get; public set; } int MaxTop { public get; public set; } int PageSize { public get; public set; } - ODataQuerySettings QuerySettings { protected get; } public virtual System.Linq.IQueryable ApplyQuery (System.Linq.IQueryable queryable, ODataQueryOptions queryOptions) public virtual object ApplyQuery (object entity, ODataQueryOptions queryOptions) @@ -2682,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; } diff --git a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl index b7c4c8c074..ea76068c74 100644 --- a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore3x.OData.PublicApi.bsl @@ -454,7 +454,6 @@ public class Microsoft.AspNet.OData.EnableQueryAttribute : Microsoft.AspNetCore. int MaxSkip { public get; public set; } int MaxTop { public get; public set; } int PageSize { public get; public set; } - ODataQuerySettings QuerySettings { protected get; } public virtual System.Linq.IQueryable ApplyQuery (System.Linq.IQueryable queryable, ODataQueryOptions queryOptions) public virtual object ApplyQuery (object entity, ODataQueryOptions queryOptions) @@ -2857,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; }