Skip to content

Commit

Permalink
added --skip-send-invite flag to "create user" cmd (#333)
Browse files Browse the repository at this point in the history
* added --skip-send-invite flag to "create user" cmd

* fix arg range for create user cmd

* fix bool flag, double negative fixin

* add skip-welcome-email and skip-invite options to bulk import user cmd

* Update .changes/unreleased/Feature-20240930-150305.yaml

---------

Co-authored-by: Kyle <[email protected]>
  • Loading branch information
davidbloss and rocktavious authored Sep 30, 2024
1 parent fa0ef03 commit 4090eb5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20240930-130549.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: added --skip-send-invite flag to "create user" cmd
time: 2024-09-30T13:05:49.15243-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20240930-150305.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: add --skip-welcome-email and --skip-invite options to bulk import user cmd
time: 2024-09-30T15:03:05.541886-05:00
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ tasks:
echo "Using latest version of opslevel-go - {{.LATEST_OPSLEVEL_GO_VERSION}}";
else
echo "WARNING: current version of opslevel-go is behind '{{.LATEST_OPSLEVEL_GO_VERSION}}'"
echo "Run 'task lintfix' to get latest version"
echo "Run 'task fix' to get latest version"
exit 1
fi
Expand Down
30 changes: 22 additions & 8 deletions src/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ var createUserCmd = &cobra.Command{
Long: "Create a User and optionally define the role (options `User`|`Admin`).",
Example: `
opslevel create user "[email protected]" "John Doe"
opslevel create user "[email protected]" "Jane Doe" Admin --skip-send-invite
opslevel create user "[email protected]" "Jane Doe" Admin --skip-welcome-email
opslevel create user "[email protected]" "Jane Doe" Admin --skip-send-invite --skip-welcome-email
`,
Args: cobra.MinimumNArgs(2),
Args: cobra.RangeArgs(2, 3),
Run: func(cmd *cobra.Command, args []string) {
email := args[0]
name := args[1]
Expand All @@ -44,14 +46,17 @@ opslevel create user "[email protected]" "Jane Doe" Admin --skip-welcome-email
}
}

skipSendInvite, err := cmd.Flags().GetBool("skip-send-invite")
cobra.CheckErr(err)
skipEmail, err := cmd.Flags().GetBool("skip-welcome-email")
cobra.CheckErr(err)

resource, err := getClientGQL().InviteUser(email, opslevel.UserInput{
userInput := opslevel.UserInput{
Name: opslevel.RefOf(name),
Role: opslevel.RefOf(role),
SkipWelcomeEmail: opslevel.RefOf(skipEmail),
})
}
resource, err := getClientGQL().InviteUser(email, userInput, !skipSendInvite)
cobra.CheckErr(err)
fmt.Println(resource.Id)
},
Expand Down Expand Up @@ -160,7 +165,7 @@ var importUsersCmd = &cobra.Command{
Long: `Imports a list of users from a CSV file with the column headers:
Name,Email,Role,Team`,
Example: `
cat << EOF | opslevel import user -f -
cat << EOF | opslevel import user --skip-send-invite --skip-welcome-email -f -
Name,Email,Role,Team
Kyle Rockman,[email protected],Admin,platform
Edgar Ochoa,[email protected],Admin,platform
Expand All @@ -170,6 +175,11 @@ EOF
Run: func(cmd *cobra.Command, args []string) {
reader, err := readImportFilepathAsCSV()
cobra.CheckErr(err)
skipSendInvite, err := cmd.Flags().GetBool("skip-send-invite")
cobra.CheckErr(err)
skipWelcomeEmail, err := cmd.Flags().GetBool("skip-welcome-email")
cobra.CheckErr(err)

for reader.Rows() {
name := reader.Text("Name")
email := reader.Text("Email")
Expand All @@ -183,10 +193,11 @@ EOF
userRole = opslevel.UserRole(role)
}
input := opslevel.UserInput{
Name: opslevel.RefOf(name),
Role: opslevel.RefOf(userRole),
Name: opslevel.RefOf(name),
Role: opslevel.RefOf(userRole),
SkipWelcomeEmail: opslevel.RefOf(skipWelcomeEmail),
}
user, err := getClientGQL().InviteUser(email, input)
user, err := getClientGQL().InviteUser(email, input, !skipSendInvite)
if err != nil {
log.Error().Err(err).Msgf("error inviting user '%s' with email '%s'", name, email)
continue
Expand Down Expand Up @@ -216,7 +227,10 @@ EOF
}

func init() {
createUserCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set the welcome e-mail will be skipped from being sent")
createUserCmd.Flags().Bool("skip-send-invite", false, "If this flag is set the welcome e-mail will be not be sent")
createUserCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set send an invite email even if notifications are disabled for the account")
importUsersCmd.Flags().Bool("skip-send-invite", false, "If this flag is set the welcome e-mail will be not be sent")
importUsersCmd.Flags().Bool("skip-welcome-email", false, "If this flag is set send an invite email even if notifications are disabled for the account")
listUserCmd.Flags().Bool("ignore-deactivated", false, "If this flag is set only return active users")

exampleCmd.AddCommand(exampleUserCmd)
Expand Down

0 comments on commit 4090eb5

Please sign in to comment.