WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Allow to modify ODataQueryOptions in controller action

Open chrisspre opened this issue 4 years ago • 2 comments

There are scenarios where a service needs more control over the supplied query options before they are handed over to the QueryProvider (before they are "applied" to IQueryable : queryOptions.ApplyTo(data)).

One recent scenario is the ability to drop a certain property for less privileged clients (based on the Authorization token.)

For that I imagine some code like


  var data = /* ... query data store */

  if (! privileged) 
  {
    foreach(var property in privilegedProperties) 
    {
      queryOptions.SelectExpand.SelectExpandClause.SelectedItems.Remove ( property );
    }
  }
  return queryOptions.ApplyTo(data); 
}

chrisspre avatar Oct 08 '21 17:10 chrisspre

There are (at least) two issues --

  1. How to modify the SelectExpandClause in the query options. Seems like we should be able to clone/copy a new SelectExpandClause without the privileged properties, but could do something to make this easier.
  2. Verify that, if we modify the select expand clause used in apply, the rest of the pipeline works (i.e., the missing properties don't cause an issue with the serializer).

mikepizzo avatar Oct 12 '21 16:10 mikepizzo

i would be also very interested to be able to dynamically add/remove expand property in the controller. Sometime i would like that when i'm getting a lot of result, by default nothing is expanded but when i got one result some properties are extended. AutoExpandAttribute does not seems to allow that.

Angelinsky7 avatar Aug 19 '22 00:08 Angelinsky7