summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorSimon Soriano <simon0191@gmail.com>2017-04-05 10:42:21 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-04-05 11:42:21 -0400
commit51608b583a8a4254574d95618df9046954ebdef5 (patch)
treedc06a53e88bb336e1254a83030d764359da659ec /cmd
parent5264d22d9ca4367088852c33800cdf505b89ae9e (diff)
downloadchat-51608b583a8a4254574d95618df9046954ebdef5.tar.gz
chat-51608b583a8a4254574d95618df9046954ebdef5.tar.bz2
chat-51608b583a8a4254574d95618df9046954ebdef5.zip
Add CLI command to search for users based on username, email, or user ID (#5918)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/platform/user.go49
1 files changed, 44 insertions, 5 deletions
diff --git a/cmd/platform/user.go b/cmd/platform/user.go
index 41f0b4f66..9d1122fb3 100644
--- a/cmd/platform/user.go
+++ b/cmd/platform/user.go
@@ -40,7 +40,7 @@ var userCreateCmd = &cobra.Command{
Use: "create",
Short: "Create a user",
Long: "Create a user",
- Example: ` user create --email user@example.com --username userexample --password Password1
+ Example: ` user create --email user@example.com --username userexample --password Password1
user create --firstname Joe --system_admin --email joe@example.com --username joe --password Password1`,
RunE: userCreateCmdF,
}
@@ -67,7 +67,7 @@ var resetUserPasswordCmd = &cobra.Command{
var resetUserMfaCmd = &cobra.Command{
Use: "resetmfa [users]",
Short: "Turn off MFA",
- Long: `Turn off multi-factor authentication for a user.
+ Long: `Turn off multi-factor authentication for a user.
If MFA enforcement is enabled, the user will be forced to re-enable MFA as soon as they login.`,
Example: " user resetmfa user@example.com",
RunE: resetUserMfaCmdF,
@@ -94,13 +94,13 @@ var migrateAuthCmd = &cobra.Command{
Short: "Mass migrate user accounts authentication type",
Long: `Migrates accounts from one authentication provider to another. For example, you can upgrade your authentication provider from email to ldap.
-from_auth:
+from_auth:
The authentication service to migrate users accounts from.
- Supported options: email, gitlab, saml.
+ Supported options: email, gitlab, saml.
to_auth:
The authentication service to migrate users to.
- Supported options: ldap.
+ Supported options: ldap.
match_field:
The field that is guaranteed to be the same in both authentication services. For example, if the users emails are consistent set to email.
@@ -119,6 +119,14 @@ var verifyUserCmd = &cobra.Command{
RunE: verifyUserCmdF,
}
+var searchUserCmd = &cobra.Command{
+ Use: "search [users]",
+ Short: "Search for users",
+ Long: "Search for users based on username, email, or user ID.",
+ Example: " user search user1@mail.com user2@mail.com",
+ RunE: searchUserCmdF,
+}
+
func init() {
userCreateCmd.Flags().String("username", "", "Username")
userCreateCmd.Flags().String("email", "", "Email")
@@ -144,6 +152,7 @@ func init() {
deleteAllUsersCmd,
migrateAuthCmd,
verifyUserCmd,
+ searchUserCmd,
)
}
@@ -431,3 +440,33 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {
return nil
}
+
+func searchUserCmdF(cmd *cobra.Command, args []string) error {
+ initDBCommandContextCobra(cmd)
+ if len(args) < 1 {
+ return errors.New("Enter at least one query.")
+ }
+
+ users := getUsersFromUserArgs(args)
+
+ for i, user := range users {
+ if i > 0 {
+ CommandPrettyPrintln("------------------------------")
+ }
+ if user == nil {
+ CommandPrintErrorln("Unable to find user '" + args[i] + "'")
+ continue
+ }
+
+ CommandPrettyPrintln("id: " + user.Id)
+ CommandPrettyPrintln("username: " + user.Username)
+ CommandPrettyPrintln("nickname: " + user.Nickname)
+ CommandPrettyPrintln("position: " + user.Position)
+ CommandPrettyPrintln("first_name: " + user.FirstName)
+ CommandPrettyPrintln("last_name: " + user.LastName)
+ CommandPrettyPrintln("email: " + user.Email)
+ CommandPrettyPrintln("auth_service: " + user.AuthService)
+ }
+
+ return nil
+}