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

[WIP] Ensure preservation of return_to through OAuth login flow #3879

Closed
wants to merge 5 commits into from
Closed

[WIP] Ensure preservation of return_to through OAuth login flow #3879

wants to merge 5 commits into from

Conversation

Radhikadua123
Copy link
Contributor

Fixes #3384

@jywarren I didn't have push access to oauth-return-to branch. That's why I pushed to new one in my forked repo.

Reference: #3762

@ghost ghost assigned Radhikadua123 Nov 1, 2018
@ghost ghost added the in progress label Nov 1, 2018
@Radhikadua123
Copy link
Contributor Author

@jywarren I couldn't test the whole functionality because oauth is disabled for local setup. How can I test it out ?

@plotsbot
Copy link
Collaborator

plotsbot commented Nov 1, 2018

2 Messages
📖 @Radhikadua123 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.
📖 Pull Request is marked as Work in Progress

Generated by 🚫 Danger

@jywarren
Copy link
Member

jywarren commented Nov 1, 2018

Oh, this is cool! I'll add you as a contributor and you'll be able to push to unstable.publiclab.org where we do testing. It'll build for a bit (follow at https://jenkins.laboratoriopublico.org) and then you should be able to try this out. I'm not 100% sure OAuth will work the same, but it's worth a try.

@jywarren
Copy link
Member

jywarren commented Nov 1, 2018

Also Code Climate has made some suggestions about your code, we don't have to adopt all of them but they're at least interesting to look at: https://codeclimate.com/github/publiclab/plots2/pull/3879

I can approve this to get CodeClimate to return an OK, if you like, or adopt some but not all -- up to you!

@jywarren
Copy link
Member

jywarren commented Nov 1, 2018

Oh i'm sorry i already added you! So, to start testing on unstable, first just chime in on the chatroom to warn others (since it only supports one build at a time, maybe someone else is using it... best to ask!) then run git push -f [email protected]:publiclab/plots2.git unstable and it will begin to build.

@Radhikadua123
Copy link
Contributor Author

Radhikadua123 commented Nov 1, 2018

you'll be able to push to unstable.publiclab.org where we do testing. It'll build for a bit (follow at https://jenkins.laboratoriopublico.org) and then you should be able to try this out. I'm not 100% sure OAuth will work the same, but it's worth a try.

I see.

I can approve this to get CodeClimate to return an OK, if you like, or adopt some but not all -- up to you!

Sure, I'll check them out.

Oh i'm sorry i already added you! So, to start testing on unstable, first just chime in on the chatroom to warn others (since it only supports one build at a time, maybe someone else is using it... best to ask!) then run git push -f [email protected]:publiclab/plots2.git unstable and it will begin to build.

Oh. Where can I access chatroom ? Nevermind, I found it. I didn't know we also had a chatroom.

@jywarren
Copy link
Member

jywarren commented Nov 1, 2018 via email

@Radhikadua123
Copy link
Contributor Author

@jywarren It's working fine now on https://unstable.publiclab.org

@publiclab/reviewers @SidharthBansal Please review the code.

Also it involves some UI related changes. I removed the "Login" dropdown from the navigation bar. And clicking on "Login" redirects to login page. This removes up duplicate code and also has better UX for mobile users.

You can check it out at https://unstable.publiclab.org


if @user&.drupal_user&.status == 1
# an existing Rails user
if @user
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jywarren Is there any difference in @user and @user.nil in this case ? If not, then we can remove if condition because we already have check for that in above code.

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right, here. Let's just be very careful and make changes incrementally since this is a pretty complex piece of code. It'll be easier to track any bugs we may introduce if we change fewer things at a time. I know this is not as satisfying as more thorough refactor here, but our login code is relatively critical, so we have to be careful, and not every thing can be protected by tests. Thanks!

return
end

if @user&.drupal_user&.status.zero?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Banned users have status code 0, right ? I got to know that from the tests. Just wanted to confirm this.

Copy link
Member

Choose a reason for hiding this comment

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

This is a little different, this is our legacy drupal users status. We should check against status of just @user. But I believe that is correct, yes! And statuses should be synced but let's not rely on that as we are slowly working to remove drupal_user code in #2838

end

if @user.nil?
flash[:warning] = "There is nobody in our system by that name, are you sure you have the right username?"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally sites don't tell this up. They just say "Invalid username or password".

Copy link
Member

Choose a reason for hiding this comment

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

yeah, you can change it if you think that'd be best, good catch!

return
end

params[:user_session][:username] = params[:openid] if params[:openid] # second runthrough must preserve username
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought of simplifying these parts but I don't know internals of the system. So, I didn't touch them. Things which I changed, I commented about them. :)

Copy link
Member

Choose a reason for hiding this comment

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

GREAT approach! As i mention below, we want to be conservative about refactoring the signup process.

@jywarren
Copy link
Member

jywarren commented Nov 2, 2018

OK, sounds like there are a couple spots you'd like to refine before merging this? Thanks so much!!!

@Radhikadua123
Copy link
Contributor Author

I know this is not as satisfying as more thorough refactor here, but our login code is relatively critical, so we have to be careful, and not every thing can be protected by tests.
OK, sounds like there are a couple spots you'd like to refine before merging this? Thanks so much!!!

I can't agree more to this. I'll split this PR into multiple small patches by which it would be easier to catch bugs in whole process. But before doing that, just wanted to confirm if you agree with the following:

Also it involves some UI related changes. I removed the "Login" dropdown from the navigation bar. And clicking on "Login" redirects to login page. This removes up duplicate code and also has better UX for mobile users.

You can check it out at https://unstable.publiclab.org

@jywarren
Copy link
Member

jywarren commented Nov 3, 2018 via email

@Radhikadua123
Copy link
Contributor Author

Hmm, I think this is ok, though I do wonder about if the non mobile page is slightly smoother with the drop-down... Are we able to have a separate page just for mobile, even if it is still code duplication a bit?

May be in future, we can create a modal for the login page ? So, on any page, clicking on "Login", will just open popup in which user will enter details and login. There won't be any separate login page.

@Radhikadua123
Copy link
Contributor Author

Deferring to #3883 and #3884

@ghost ghost removed the in progress label Nov 3, 2018
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.

3 participants