-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Role based code cleanup #268
Comments
I just noticed that the highlighted section of the partial has two different ways to check if a user is defined. If we write a |
Alright it turns out the differences are intentional. Misread that one is looking for no, the user does not exist and one is looking for yes, the user does exist. At any rate, same logic still applies for DRY to prevent the possibility of copy/paste mistakes :) |
We should consolidate using this code:
|
@jywarren please update the issue. Thanks! |
I'll open a new issue! I think we can build out our model code to make this simpler, without yet planning out a full multi-role system. If we go there, then we might merge this into profile tags! |
Until #264 is pursued, it might be a good idea to compress as much of the role based logic as possible into one place.
For example, we could make partial templates which render the following:
plots2/app/views/users/profile.html.erb
Lines 6 to 17 in fe2ba03
All of the if/then logic would move into the partial, and that highlighted section would include the partial. That allows us to change how the template logic works later in one place. If we have a few partials, they can all go in the same directory under maybe
templates/roles/
.Another copy/paste logic can be seen here:
plots2/app/controllers/admin_controller.rb
Lines 6 to 13 in ad7fa8d
If this were Python, I'd write a decorator which checks user credentials and returns an error if they are not met. Since this is Ruby, I don't know a good way. Here's what I'd do in my naivety: write a function which takes the user and required role in; if there is a failed match, it would set the flash error and return False. Then you could copy paste
if not has_permission(user, 'admin') return
or something more Ruby-like.The above is a little ugly, but such a function could probably be rewritten for RBAC later without needing to make wide sweeping code changes (though this change itself would be such a wide-sweeping code change).
The text was updated successfully, but these errors were encountered: