-
Notifications
You must be signed in to change notification settings - Fork 37
feat: update 'collaborator' command to support read-only permission type #272
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
Changes from 6 commits
22ed643
ccaf2df
1100c37
48841e0
236dad9
9c46e30
6c020f7
8e68452
b12ed2b
fa544dd
ea994f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ import ( | |
|
|
||
| "github.com/opentracing/opentracing-go" | ||
| "github.com/slackapi/slack-cli/internal/cmdutil" | ||
| "github.com/slackapi/slack-cli/internal/experiment" | ||
| "github.com/slackapi/slack-cli/internal/iostreams" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
|
|
@@ -62,8 +61,7 @@ func NewAddCommand(clients *shared.ClientFactory) *cobra.Command { | |
| return runAddCommandFunc(ctx, clients, cmd, args) | ||
| }, | ||
| } | ||
| cmd.Flags().StringVarP(&addFlags.permissionType, "permission-type", "P", "", "collaborator permission type: reader, owner") | ||
| cmd.Flag("permission-type").Hidden = true | ||
| cmd.Flags().StringVarP(&addFlags.permissionType, "permission-type", "P", "", "collaborator permission type: [reader|owner]") | ||
| return cmd | ||
| } | ||
|
|
||
|
|
@@ -87,7 +85,7 @@ func runAddCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd * | |
| } | ||
| err = clients.API().AddCollaborator(ctx, selection.Auth.Token, selection.App.AppID, slackUser) | ||
| if err != nil { | ||
| if clients.Config.WithExperimentOn(experiment.ReadOnlyAppCollaborators) && strings.Contains(err.Error(), "user_already_owner") { | ||
| if strings.Contains(err.Error(), "user_already_owner") { | ||
| cmd.Println() | ||
| cmd.Println(style.Sectionf(style.TextSection{ | ||
| Emoji: "bulb", | ||
|
|
@@ -123,14 +121,15 @@ func promptCollaboratorsAdd( | |
| if err != nil { | ||
| return types.SlackUser{}, err | ||
| } | ||
|
|
||
| switch clients.Config.Flags.Lookup("permission-type").Changed { | ||
| case true: | ||
| slackUser.PermissionType, err = promptCollaboratorsAddPermissionFlags(ctx, clients, addFlags.permissionType) | ||
| if err != nil { | ||
| return types.SlackUser{}, err | ||
| } | ||
| default: | ||
| slackUser.PermissionType, err = promptCollaboratorsAddPermissionPrompts(ctx, clients) | ||
| } | ||
| if err != nil { | ||
| return types.SlackUser{}, err | ||
| slackUser.PermissionType = types.OWNER | ||
| } | ||
| return slackUser, nil | ||
| } | ||
|
|
@@ -181,40 +180,7 @@ func promptCollaboratorsAddSlackUserPrompts( | |
| return slackUser, nil | ||
| } | ||
|
|
||
| // promptCollaboratorsAddPermissionPrompts gathers the collaborator permission | ||
| // from selection if the experiment allows | ||
| func promptCollaboratorsAddPermissionPrompts( | ||
|
Contributor
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. Changed the behaviour here: before when adding a new collaborator we required the permission type to be set, but I think we can default to 'owner' unless otherwise specified
Member
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. Sounds good! Since we're now defaulting to the owner, we should update the description of the
Contributor
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. Thanks! |
||
| ctx context.Context, | ||
| clients *shared.ClientFactory, | ||
| ) ( | ||
| permission types.AppCollaboratorPermission, | ||
| err error, | ||
| ) { | ||
| switch clients.Config.WithExperimentOn(experiment.ReadOnlyAppCollaborators) { | ||
| case false: | ||
| return types.OWNER, nil | ||
| default: | ||
| permissionLabels := []string{ | ||
| "owner", | ||
| "reader", | ||
| } | ||
| response, err := clients.IO.SelectPrompt( | ||
| ctx, | ||
| "Decide the collaborator permission", | ||
| permissionLabels, | ||
| iostreams.SelectPromptConfig{ | ||
| Required: true, | ||
| }, | ||
| ) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return types.StringToAppCollaboratorPermission(response.Option) | ||
| } | ||
| } | ||
|
|
||
| // promptCollaboratorsAddPermissionFlags gathers the collaborator permission | ||
| // from flags if the experiment allows | ||
| // promptCollaboratorsAddPermissionFlags fetches collaborator permission from the flag | ||
| func promptCollaboratorsAddPermissionFlags( | ||
| ctx context.Context, | ||
| clients *shared.ClientFactory, | ||
|
|
@@ -223,19 +189,7 @@ func promptCollaboratorsAddPermissionFlags( | |
| permission types.AppCollaboratorPermission, | ||
| err error, | ||
| ) { | ||
| switch clients.Config.WithExperimentOn(experiment.ReadOnlyAppCollaborators) { | ||
| case true: | ||
| return types.StringToAppCollaboratorPermission(addFlags.permissionType) | ||
| default: | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "construction", | ||
| Text: fmt.Sprintf("This command is under construction. Use at your own risk %s", style.Emoji("skull")), | ||
| Secondary: []string{ | ||
| fmt.Sprintf("Bypass this message with the %s flag", style.Highlight("--experiment read-only-collaborators")), | ||
| }, | ||
| })) | ||
| return "", slackerror.New(slackerror.ErrMissingExperiment) | ||
| } | ||
| return types.StringToAppCollaboratorPermission(addFlags.permissionType) | ||
| } | ||
|
|
||
| // printCollaboratorsAddSuccess outputs a message when addition is done | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,12 @@ | |
| package collaborators | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "context" | ||
| "net/mail" | ||
|
|
||
| "github.com/opentracing/opentracing-go" | ||
| "github.com/slackapi/slack-cli/internal/cmdutil" | ||
| "github.com/slackapi/slack-cli/internal/experiment" | ||
| "github.com/slackapi/slack-cli/internal/iostreams" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/shared/types" | ||
|
|
@@ -51,23 +51,11 @@ func NewUpdateCommand(clients *shared.ClientFactory) *cobra.Command { | |
| return cmdutil.IsValidProjectDirectory(clients) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if !clients.Config.WithExperimentOn(experiment.ReadOnlyAppCollaborators) { | ||
| cmd.Println() | ||
| cmd.Println(style.Sectionf(style.TextSection{ | ||
| Emoji: "construction", | ||
| Text: fmt.Sprintf("This command is under construction. Use at your own risk %s", style.Emoji("skull")), | ||
| Secondary: []string{ | ||
| fmt.Sprintf("Bypass this message with the %s flag", style.Highlight("--experiment read-only-collaborators")), | ||
| }, | ||
| })) | ||
| return nil | ||
| } | ||
|
|
||
| return runUpdateCommand(cmd, clients, args) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVarP(&updateFlags.permissionType, "permission-type", "P", "", "collaborator permission type: reader, owner") | ||
| cmd.Flags().StringVarP(&updateFlags.permissionType, "permission-type", "P", "", "collaborator permission type: [reader|owner]") | ||
|
vegeris marked this conversation as resolved.
Outdated
|
||
|
|
||
| return cmd | ||
| } | ||
|
|
@@ -92,8 +80,10 @@ func runUpdateCommand(cmd *cobra.Command, clients *shared.ClientFactory, args [] | |
| return err | ||
| } | ||
| } else { | ||
| cmd.Println(fmt.Sprintf("\n%s Specify a permission type for your collaborator with the %s flag\n", style.Emoji("warning"), style.Highlight("--permission-type"))) | ||
| return nil | ||
| slackUser.PermissionType, err = promptCollaboratorPermissionSelection(ctx, clients) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
Contributor
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. When updating an existing collaborator however, maybe it would make sense to prompt for the permission type rather than error out
Member
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 we choose to prompt, than we should handle non-TTY (no interactivity) as well. In that case, I think we would error when there is no flag value provided. suggestion: Personally, I suggest we keep the error when the flag is not provided because it's been tested and works. If we switch to a prompt, I'd rather see it as a separate PR because it changes the functionality rather than simply unhides the experiment (purpose of this PR).
Contributor
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. Sounds good; I'll flip this back to erroring out if the flag isn't provided. I'm fine with keeping that behaviour if the CLI team doesn't see adding the prompt as an enhancement to the user experience |
||
| } | ||
|
|
||
| // Get the app auth selection from the flag or prompt | ||
|
|
@@ -117,3 +107,29 @@ func runUpdateCommand(cmd *cobra.Command, clients *shared.ClientFactory, args [] | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| // promptCollaboratorPermissionSelection fetches collaborator permission from the prompt | ||
| func promptCollaboratorPermissionSelection( | ||
| ctx context.Context, | ||
| clients *shared.ClientFactory, | ||
| ) ( | ||
| permission types.AppCollaboratorPermission, | ||
| err error, | ||
| ) { | ||
| permissionLabels := []string{ | ||
| "owner", | ||
| "reader", | ||
| } | ||
| response, err := clients.IO.SelectPrompt( | ||
| ctx, | ||
| "Select a permission type", | ||
| permissionLabels, | ||
| iostreams.SelectPromptConfig{ | ||
| Required: true, | ||
| }, | ||
| ) | ||
|
Member
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. suggestion: I think this needs to be more robust. The
Contributor
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. Removed the prompt for now but will make note of this if we want to bring it back |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return types.StringToAppCollaboratorPermission(response.Option) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.