Skip to content

Commit

Permalink
add skip-welcome-email and skip-invite options to bulk import user cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Sep 30, 2024
1 parent f7e775b commit a661947
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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
16 changes: 12 additions & 4 deletions src/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,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 @@ -175,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 @@ -188,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, false)
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 @@ -223,6 +229,8 @@ EOF
func init() {
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 a661947

Please sign in to comment.