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

Features controller refactor #2480

Merged
merged 6 commits into from
Mar 16, 2018

Conversation

seafr
Copy link
Member

@seafr seafr commented Mar 12, 2018

No issue opened.

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled

Thanks!

@PublicLabBot
Copy link

PublicLabBot commented Mar 12, 2018

2 Messages
📖 @seafr Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.
📖 This pull request doesn’t link to a issue number. Please refer to the issue it fixes (if any) in the body of your PR, in the format: Fixes #123.

Generated by 🚫 Danger

@seafr
Copy link
Member Author

seafr commented Mar 12, 2018

@jywarren this is related to the refactor in #2448

flash[:warning] = 'Only admins may edit features.'
redirect_to '/features'
redirect_to features_url
Copy link
Member

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!

Copy link
Member Author

@seafr seafr Mar 12, 2018

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.

Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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 :-(

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

@seafr seafr Mar 21, 2018

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

@seafr
Copy link
Member Author

seafr commented Mar 12, 2018

@jywarren, please note that the first 2 commits have already been merged (#2448).
In fact, only changes in app/controllers/features_controller.rb are relevant.

@jywarren
Copy link
Member

Looks great, is this ready to go? :-)

@seafr
Copy link
Member Author

seafr commented Mar 15, 2018

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?
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

Nice work !!!

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for review. 👍

@seafr seafr added ready and removed review-me labels Mar 15, 2018
Copy link
Member

@grvsachdeva grvsachdeva left a comment

Choose a reason for hiding this comment

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

Awesome work !!!

@jywarren
Copy link
Member

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! ✈️

@jywarren jywarren merged commit 4517567 into publiclab:master Mar 16, 2018
@grvsachdeva
Copy link
Member

grvsachdeva commented Mar 16, 2018

Thanks, Jeff !!! Just performing our part being a member of the PublicLab community 😊

@seafr
Copy link
Member Author

seafr commented Mar 16, 2018

@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.

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants