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

Support strict with_role queries. Issue #362 #543

Merged
merged 6 commits into from
Jun 28, 2020
Merged

Support strict with_role queries. Issue #362 #543

merged 6 commits into from
Jun 28, 2020

Conversation

Mrjaco12
Copy link
Contributor

@Mrjaco12 Mrjaco12 commented May 29, 2020

Why:

How:

  • Pass a strict flag to the scope function
  • call where or where_strict depending on strict flag in active_record adapter
  • Add tests for strict mode resource queries

Note:

  • This PR does not address strict mode for mongoid since I am unfamiliar with that ORM

Why:

* There is an outstanding issues #362
* strict mode should be enforced on role queries and resource queries

How:

* Pass a strict flag to the scope function
* call where or where_strict depending on strict flag in active_record adapter
* Add tests for strict mode resource queries

Note:

* This PR does not address strict mode for mongoid since I am unfamiliar with that ORM
@coveralls
Copy link

coveralls commented May 29, 2020

Coverage Status

Coverage decreased (-0.09%) to 93.302% when pulling 22d1ab3 on Mrjaco12:master into 8c3e829 on RolifyCommunity:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 92.584% when pulling c4e169f on Mrjaco12:master into 21a5051 on RolifyCommunity:master.

Why:

* The tests will fail until mongo works with strict resource querying

This change addresses the need by:

* Copy the where_strict implementation from the active record adapter
@Mrjaco12
Copy link
Contributor Author

OK, I've updated the PR to cover mongo. The tests are passing although it would be good for someone with deeper mongo experience than I to double check the changes there make sense.

@stevenbuccini
Copy link

Amazing work, hoping to see this get merged and released!

Copy link
Member

@thomas-mcdonald thomas-mcdonald left a comment

Choose a reason for hiding this comment

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

Just a small comment to improve legibility of the branches. Rest of the change looks good - thanks for the contribution!

return relation.where(conditions) if args[:resource].blank?

if args[:resource].is_a?(Class)
processed_args[:resource_type] = args[:resource].to_s
Copy link
Member

Choose a reason for hiding this comment

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

And apparently I didn't actually submit my comment... Would refactor this code to avoid mutating processed_args w/reliance on it being referenced within the conditions hash. It's a bit tough because of the wrapping logic, not sure I have a magic proposal at the moment

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 tried a few approaches and the mutating was probably the simplest but I understand why it might be objectionable. I'll take another look in the coming days to see if I can reason something better.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah - my only suggestion without moving too much of this code around could be doing the wrapping at the return sites? I think it would be more legible at the cost of being a little more repetitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I've updated things to avoid the nested hash mutating. There's still a tiny mutation in there but I think it's a bit cleaner. What do you think?

Copy link
Member

@thomas-mcdonald thomas-mcdonald left a comment

Choose a reason for hiding this comment

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

nice work on the refactor!

@v-kumar
Copy link
Contributor

v-kumar commented Feb 7, 2022

Found a bug with the changes from this PR. Fix is here: #575

Would love to have a quick review and merge/release. Thanks @thomas-mcdonald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants