-
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
Features controller refactor #2480
Features controller refactor #2480
Conversation
… route for redirect
…med route for redirect
Generated by 🚫 Danger |
flash[:warning] = 'Only admins may edit features.' | ||
redirect_to '/features' | ||
redirect_to features_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this auto-generated from the routes, then? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, features_url
and features_path
. The first is recommended for redirection as it contains the full URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to add that I rarely come across named routes in the codebase. And I don't see Rails' link_to
method. Is there a specific reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I've felt that it is more readable for people who just do HTML (which is a lot of people) to just use <a>
tags, and the _url
Rails helpers are a little mysterious to people. I can see the advantage to having managed routes, but I think there's something good about having a literal link where you can see the URL, in a standard HTML format.
But I'm open to discussion on it! What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point, esp. regarding templates. However, controllers are just Ruby so named routes would probably suit them better. The idea is to enable any future change of URLs without breaking things, like what would happen in #2484 (/blog -> /wiki/stories). But I don't want to be disruptive here. Maybe you think it's better to keep things as they are (for now at least). Or maybe we should get input from other contributors too. Let me know your thoughts and I'll be glad to revert relevant changes back if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about in order to move forward, we stick with static string routes for now, and then as you said
get input from other contributors too
That sounds great. I do think we have trouble with route maintenance -- #1841 was trying to think through that one -- and very occasionally routes break since they are not thoroughly tested :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for thinking this through! I agree re: controllers being in ruby, but the named routes are just so mysterious to newcomers! If we could smooth that learning curve a bit I'd be more comfortable using them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the routes file needs a bit of tidying up.
OK I'll use static strings for now. I agree that named routes can be a mystery for newcomers. Very relevant to our newcomer-friendly policy!
Last, this is not a promise, but I'll try to look into the routes issue and see if I can help. Anything you think you should mention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you tell me why the current time is (sometimes) appended to the redirect URL? Like in redirect_to '/features?_=' + Time.now.to_i.to_s
Looks great, is this ready to go? :-) |
Yes, I guess so. But there has been no formal review by anybody, hence the review tag. |
@@ -12,14 +12,14 @@ def embed | |||
end | |||
|
|||
def new | |||
if current_user.role != 'admin' | |||
unless current_user.admin? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @seafr , in all other places, you have used if !current_user.admin?
. how about following the same syntax here too, only if you want to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used if !
elsewhere due to the presence of the else
clause. I find it hard to understand else
after unless
, else I'd use unless
everywhere.
P.S. I have a feeling there is an overuse of else in the above text though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah unless/else
trips me up too. Interestingly -- I think double negatives also vary in use across languages!
# use instead of "user.role == 'admin' || user.role == 'moderator'" | ||
admin? || moderator? | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work !!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
assert_not basic_user.admin? | ||
assert_not basic_user.moderator? | ||
assert_not basic_user.can_moderate? | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test seems fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for review. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work !!!
Thanks @Gauravano for such a thorough review! Thank both of you for your thorough work! I also notice both of you helping others out a lot and with great attitude 😄 Merging away! |
Thanks, Jeff !!! Just performing our part being a member of the PublicLab community 😊 |
@jywarren thank you for the kind words. It's a pleasure to be part of the PL community. We are just trying to give back the welcome we received as newcomers. Ideal place to get into OSS. |
* Add methods to User model for user roles * Add a comment * Edit 'new' to use User#admin? to verify user's role, and to use named route for redirect * Modify 'edit' to use User#admin? to verify user's role, and to use named route for redirect * Modify 'create' & 'update' to use User#admin? to verify user's role * Revert back to literal routes from named routes
No issue opened.
rake test
Thanks!