scim icon indicating copy to clipboard operation
scim copied to clipboard

Publish filters package

Open Bladrak opened this issue 2 years ago • 2 comments

I've stumbled upon a need to use the filters package, which is internal at the moment. This proposal aims at making it usable from other packages. What do you think?

Bladrak avatar Apr 08 '22 07:04 Bladrak

Any chance this can be merged or commented upon?

As it stands, I believe there's a problem with the code flow. I am trying to implement my resource handler. In the GetAll method, I need to apply query filters. I cannot do that in the persistence layer.

I am using schemasHandler in handlers.go as an example - I was hoping I can just call PassesFilter on the ListRequestParams.Filter parameter. However, that is a expression.Expression - I would have to convert it to a validator, which is inside an internal package.

There are two ways out of my dilemma:

  • wait for this patch to be merged, and re-implement the validator
  • or change the signature of ListRequestParams.Params to be internal.filter.Validator, and change getFilter to return a Validator instead. Then a small amount of code in handlers.go can be removed since it would immediately benefit from it.

Thank you!

mibanescu avatar Jun 06 '22 19:06 mibanescu

I have run into this problem as well. Because the validator is on the internal package there is no way for the end user to use it. It feels like ListRequestParams should have a function that returns the validator for the filter so you can do

func (t userHandler) GetAll(r *http.Request, params scim.ListRequestParams) (scim.Page, error) {
	validator := params.GetValidator()
	users, _ := MyClient().ListUsers()
	for _, user := range users {
	        attributes := scim.ResourceAttributes{}
		attributes["userName"] = user.Email
		if validator.Passes(attributes) != nil {
			continue
		}
		... Continue Processing User ...
	}
}

Currently as it stands there is literally no way for an end user of this library to use filters without forking the codebase.

rocktavious avatar Jul 11 '22 01:07 rocktavious