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

Improve gem login scope selection #7342

Conversation

williantenfen
Copy link
Contributor

@williantenfen williantenfen commented Dec 31, 2023

What was the end-user or developer problem that led to this PR?

Gem login api scopes is confusing and difficult as show_dashboard permission invalidates the rest.
More details in issue #7238

What is your fix for the problem, implemented in this PR?

Enhance scope selection by prompting first exclusively scopes and message about when one of those is selected (other scopes will be disabled). updated prompt:

Enter your RubyGems.org credentials.
Don't have an account yet? Create one at https://rubygems.org/sign_up
   Email:   [redacted]
Password:   [redacted]

API Key name [redacted]:   test
The default access scope is:
  index_rubygems: y

Do you want to customise scopes? [yN]  y
show_dashboard [yN]  y
You selected show_dashboard, which must be enabled exclusively. Other scopes will be disabled.
Is this fine? (type no for selecting other scopes) [Yn]  y
...

Make sure the following tasks are checked

Copy link

welcome bot commented Dec 31, 2023

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch 3 times, most recently from 22b3d20 to a7e30c1 Compare January 4, 2024 12:26
@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch from a7e30c1 to f542364 Compare January 16, 2024 12:36
@williantenfen
Copy link
Contributor Author

@martinemde any feedback on this?

Copy link
Member

@martinemde martinemde left a comment

Choose a reason for hiding this comment

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

This is great. I think we could clean up a little and then I'm happy to approve.

lib/rubygems/gemcutter_utilities.rb Outdated Show resolved Hide resolved
lib/rubygems/gemcutter_utilities.rb Outdated Show resolved Hide resolved
lib/rubygems/gemcutter_utilities.rb Outdated Show resolved Hide resolved
@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch 2 times, most recently from 7dd92e8 to 4b35f6a Compare January 20, 2024 16:28
@williantenfen
Copy link
Contributor Author

@martinemde thanks! updated with suggestions 😃

@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch from 4b35f6a to 93197b0 Compare January 24, 2024 11:13
Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, left a comment on approach and implementation!

selected = ask_yes_no(s.to_s, false)
scope_params[s] = true if selected
end
end
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 this alternative implementation?

diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 9b50b55ede..1236861eac 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -322,23 +322,23 @@ def get_scope_params(scope)
       say "\n"
       customise = ask_yes_no("Do you want to customise scopes?", false)
       if customise
-        scope_params = {}
-        exclusive_scope = nil
         EXCLUSIVELY_API_SCOPES.each do |s|
           selected = ask_yes_no(s.to_s, false)
-          exclusive_scope = s if selected
-          break if selected
-        end
-        if exclusive_scope
-          say "You selected #{exclusive_scope}, which must be enabled exclusively. Other scopes will be disabled."
+          next unless selected
+
+          say "You selected #{s}, which must be enabled exclusively. Other scopes will be disabled."
           keep_selection = ask_yes_no("Is this fine? (type no for selecting other scopes)", true)
-          scope_params = { exclusive_scope => true } if keep_selection
+
+          return { s => true } if keep_selection
+
+          break
         end
-        if exclusive_scope.nil? || (exclusive_scope && !keep_selection)
-          API_SCOPES.each do |s|
-            selected = ask_yes_no(s.to_s, false)
-            scope_params[s] = true if selected
-          end
+
+        scope_params = {}
+
+        API_SCOPES.each do |s|
+          selected = ask_yes_no(s.to_s, false)
+          scope_params[s] = true if selected
         end
       end
       say "\n"

Seems more straightforward to me. If an exclusive scope is selected, return it if it's fine, or directly skip to non exclusive scopes if it's not.

Alternatively, we could inform of exclusivity while asking, so we don't need yet another prompt?

The default access scope is:
  index_rubygems: y

Do you want to customise scopes? [yN]  y
show_dashboard (answering yes disables other scopes) [yN]  N
index_rubygems [yN]  N
push_rubygem [yN]  y
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

I think the alternative makes sense as well...
I can update to that if we think its better.. let me know...

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 it's a bit simpler and usable, but let's check with @martinemde before you implement anything.

Copy link
Member

Choose a reason for hiding this comment

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

I like it, @deivid-rodriguez. Saying ahead of time what will happen by choosing show_dashboard will produce less mistakes. I'm making a similar change to the web UI so that show_dashboard is presented at the top with the heading "Exclusive Scopes". On the CLI the best we can do is explain it up front.

Btw, no where do we explain why this is the case. What are the scopes? Do we need to add a ?/h option that prints a brief explanation of the scope? (this should be a follow up PR, imho)

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:

show_dashboard (answering yes disables other scopes)

or

show_dashboard (exclusive scope, answering yes will not prompt for other scopes)

?

Copy link
Member

Choose a reason for hiding this comment

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

The latter seems more clear to me 👍.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for the back and forwards, I should have waited for more discussions on the issue itself.. was just looking to contribute to something...

If theres something similar already implemented for adding a ? /h option, or some guidance on how to do that, I can try a PR for that as well... thanks...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is great.

And don't worry, we always go back and forth on stuff like this. I appreciate your patience! 😀

@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch from d25962e to 821ea2d Compare January 26, 2024 20:37
Copy link
Member

@martinemde martinemde left a comment

Choose a reason for hiding this comment

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

Looks ready to me. Could you squash the commits?

@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch 2 times, most recently from 354f71a to 37429c5 Compare January 27, 2024 16:55
@martinemde
Copy link
Member

@deivid-rodriguez ready to merge with your approval.

@williantenfen williantenfen force-pushed the gem-login-select-scopes-enhancement branch from 37429c5 to 26c7abe Compare January 29, 2024 11:16
Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Awesome!

@deivid-rodriguez deivid-rodriguez merged commit d06e104 into rubygems:master Jan 29, 2024
74 checks passed
deivid-rodriguez added a commit that referenced this pull request Feb 5, 2024
…nhancement

Improve gem login scope selection

(cherry picked from commit d06e104)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants