-
Notifications
You must be signed in to change notification settings - Fork 164
fix: adding users to group with invites is broken in non interactive mode #8781
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
Closed
+17
−8
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ func AddCmd(ch *cmdutil.Helper) *cobra.Command { | |
| var explores []string | ||
| var canvases []string | ||
| var restrictResources bool | ||
| var autoInvite bool | ||
|
|
||
| addCmd := &cobra.Command{ | ||
| Use: "add", | ||
|
|
@@ -132,14 +133,17 @@ func AddCmd(ch *cmdutil.Helper) *cobra.Command { | |
| if !strings.Contains(err.Error(), "user is not a member of the org") { | ||
| return err | ||
| } | ||
| if !ch.Interactive { | ||
| if !ch.Interactive && !autoInvite { | ||
| return err | ||
| } | ||
| ok, err := cmdutil.ConfirmPrompt(fmt.Sprintf("The user must be a member of %q to join one of its groups. Do you want to invite the user to join %q?", ch.Org, ch.Org), "", false) | ||
| if err != nil { | ||
| return err | ||
| // prompt only if explicit flag not set | ||
| if !cmd.Flags().Changed("auto-invite") { | ||
| autoInvite, err = cmdutil.ConfirmPrompt(fmt.Sprintf("The user must be a member of %q to join one of its groups. Do you want to invite the user to join %q?", ch.Org, ch.Org), "", false) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| if !ok { | ||
| if !autoInvite { | ||
| return fmt.Errorf("aborted: user needs to be part of the organization to be added to the user group") | ||
| } | ||
|
|
||
|
|
@@ -150,9 +154,13 @@ func AddCmd(ch *cmdutil.Helper) *cobra.Command { | |
| orgRole = "" | ||
| } | ||
| if orgRole == "" { | ||
| err := cmdutil.SelectPromptIfEmpty(&orgRole, "Select organization role", orgRoles, orgRoles[len(orgRoles)-1]) | ||
| if err != nil { | ||
| return err | ||
| if !ch.Interactive { | ||
| orgRole = "guest" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not too sure about this. |
||
| } else { | ||
| err := cmdutil.SelectPromptIfEmpty(&orgRole, "Select organization role", orgRoles, orgRoles[len(orgRoles)-1]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -195,6 +203,7 @@ func AddCmd(ch *cmdutil.Helper) *cobra.Command { | |
| addCmd.Flags().StringVar(&ch.Org, "org", ch.Org, "Organization") | ||
| addCmd.Flags().StringVar(&projectName, "project", "", "Project") | ||
| addCmd.Flags().StringVar(&group, "group", "", "User group") | ||
| addCmd.Flags().BoolVar(&autoInvite, "auto-invite", false, "Automatically invite the user to the organization if they are not already a member when adding to a group") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If required this can be removed as well and the default behaviour in non interactive mode can be to auto invite as well. |
||
| addCmd.Flags().StringVar(&email, "email", "", "Email of the user") | ||
| addCmd.Flags().StringVar(&role, "role", "", fmt.Sprintf("Role of the user (options: %s)", strings.Join(orgRoles, ", "))) | ||
| addCmd.Flags().StringArrayVar(&explores, "explore", nil, "Explore resource to restrict to (repeat for multiple)") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe I'm missing something, but the previous behavior kind of seems expected to me. What I mean is, adding a user to a group when they are not in the org is arguably a "mistake" – in interactive mode, we try to help the user to fix the mistake, but in non-interactive mode, it's okay to just tell them about the mistake.
To work around it, can't you just do it in two steps? Like:
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 I also suggested that as a workaround to Himadri.
But a question to consider, is it okay for commands to diverge in their interactive and non interactive behaviour ?
Uh oh!
There was an error while loading. Please reload this page.
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 it's definitely okay. Consider the example when there's a common user error (like here): in non-interactive mode, we should be strict and return the error, but in interactive mode, we have an opportunity to help the user to fix it.