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

Introduce a UserAccess model #1242

Merged
merged 3 commits into from
Aug 25, 2020
Merged

Introduce a UserAccess model #1242

merged 3 commits into from
Aug 25, 2020

Conversation

kitallis
Copy link
Contributor

Story card: https://app.clubhouse.io/simpledotorg/story/128/support-for-adding-and-removing-permissions-to-an-access-level

Because

The User class is lifting a lot of access-related weight, move it out to a more dedicated place.

I first pulled it out into a concern, but it didn't deserve one.

Then I pulled it out into a module/mixin, but mixins are a very poor abstraction that don't mean anything, esp not a great place to put concrete domain logic.

So I eventually pulled up everything from User and Access up into a concrete class that defines the Access behavior between User and Access and just use the Delegator pattern to forward methods from User to UserAccess for convenience.

This also makes the behavior easier to test and doesn't spill over the specs in 2 places.

This addresses

  • Add UserAccess
  • Delegate methods from User to UserAccess
  • Migrate Access and User permissions-related specs to UserAccess

@harimohanraj89 harimohanraj89 temporarily deployed to simple-review-pr-1242 August 25, 2020 06:09 Inactive
@@ -0,0 +1,82 @@
class UserAccess < Struct.new(:user)
class NotAuthorizedError < StandardError; end
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 come in handy later.


def resources_for(resource_model, action)
return resource_model.all if user.power_user?
return resource_model.none unless ACTION_TO_LEVEL.fetch(action).include?(user.access_level.to_sym)
Copy link
Contributor Author

@kitallis kitallis Aug 25, 2020

Choose a reason for hiding this comment

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

This clause has been moved up, it used to be like this before. It makes more sense this way since we're just pulling accesses off a concrete User.

Copy link
Contributor

@harimohanraj89 harimohanraj89 left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Shipit :shipit:

@kitallis kitallis temporarily deployed to simple-review-pr-1242 August 25, 2020 06:19 Inactive
@kitallis kitallis temporarily deployed to simple-review-pr-1242 August 25, 2020 06:25 Inactive
@kitallis kitallis merged commit 6512b84 into master Aug 25, 2020
@kitallis kitallis deleted the permissions-user-access-model branch August 25, 2020 06:37
danySam added a commit that referenced this pull request Aug 25, 2020
…le-server into permissions-ui

* 'permissions-ui' of https://github.com/simpledotorg/simple-server:
  Remove unused packages
  Introduce a UserAccess model (#1242)
  Various reports fixes (#1240)
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.

None yet

2 participants