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

COMP-6957 Add roleScope methods and indexQueryBuilder #15

Merged
merged 11 commits into from
Mar 5, 2019

Conversation

DeeWBee
Copy link
Contributor

@DeeWBee DeeWBee commented Mar 1, 2019

What

This PR upgrades the RolyPoly gem to include the RoleScope object and associated methods. Additionally, this PR adds the ResourceIndexQueryBuilder to allow permission checks and roleScoping for index actions.

Why

Over the course of the past year, StatNgin and VenueService have been upgraded to use RolyPoly for permission checks. These POC's were successful, therefore it was decided to simply add the new service classes to the RolyPoly gem, allowing us to replicate permission checks across our platform.

Deploy Plan

Does Platform Operations need to know anything special about this deploy? Are migrations present?

Rollback Plan

  • To roll back this change, revert the merge with: git revert -m 1 MERGE_SHA and perform another deploy.

URLs

Links to bug tickets or user stories.

QA Plan

module InstanceMethods
extend Forwardable

rescue_from NoMethodError, with: :check_rails
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrmm, this seems a bit too greedy. I believe any no-method-error in the application would be caught by this...

role_scopes.allowed_roles(current_user_roles, scope_name)
end

protected def check_rails
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should be done on start in an initializer.

module IndexRoleDSL

def self.included(base)
base.before_filter(:check_where_or) if base.respond_to? :before_filter
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still going to run before every request. I don't think that is necessary or desired. Add it to the documentation if we can't add a check without affecting too much overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will only run before every index request. Is that still too much overhead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I still prefer it doesn't. Running for every index request isn't fool proof anyhow.

def apply_scopes
return query if role_scopes.all_access?(current_user_roles)
return query.none if scope_hash.empty?
return scope_hash.inject(query) { |query, (scope_name, ids)| query.or(query.public_send(scope_name, ids)) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In regards to my comments about rails/rails#24055. The main issue is that query should be an array of possible objects to return, but for some objects, query is just the general class object rather than a specific instance(s). For example in venues_controller, query will be an array of possible venues. However in reservations_controller, query just returns Reservation(id: integer, reserver_type: string, reserver_id: string, reservable_type: string, reservable_id: integer, primary: boolean). It's something to do with object relations I think...

q.joins(join_table)
end

return scope_hash.inject(object_query) do |object_query, (scope_name, ids)|
Copy link
Contributor

Choose a reason for hiding this comment

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

It is more railsy to not use return statements on the last line of the block.
http://sportngin.github.io/styleguide/ruby.html#syntax_L18

Olson3R
Olson3R previously approved these changes Mar 5, 2019
@production-status-check
Copy link

:octocat: Has QA approval

@Olson3R Olson3R merged commit 92cdda2 into master Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants