PLT-4157 CLI to make a user active or inactive (#4025)

This commit is contained in:
enahum
2016-09-15 12:33:16 -03:00
committed by Harrison Healey
parent 2659d19d05
commit 9d40538106
2 changed files with 66 additions and 1 deletions

View File

@@ -417,3 +417,27 @@ func TestCliCreateChannel(t *testing.T) {
t.Fatal()
}
}
func TestCliMakeUserActiveAndInactive(t *testing.T) {
if disableCliTests {
return
}
th := Setup().InitBasic()
// first inactivate the user
cmd := exec.Command("bash", "-c", `go run ../mattermost.go -activate_user -inactive -email="`+th.BasicUser.Email+`"`)
output, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(output))
t.Fatal()
}
// activate the inactive user
cmd2 := exec.Command("bash", "-c", `go run ../mattermost.go -activate_user -email="`+th.BasicUser.Email+`"`)
output2, err2 := cmd2.CombinedOutput()
if err2 != nil {
t.Log(string(output2))
t.Fatal()
}
}

View File

@@ -62,6 +62,7 @@ var flagCmdPermanentDeleteAllUsers bool
var flagCmdResetDatabase bool
var flagCmdRunLdapSync bool
var flagCmdMigrateAccounts bool
var flagCmdActivateUser bool
var flagUsername string
var flagCmdUploadLicense bool
var flagConfigFile string
@@ -79,6 +80,7 @@ var flagMatchField string
var flagChannelType string
var flagChannelHeader string
var flagChannelPurpose string
var flagUserSetInactive bool
func doLoadConfig(filename string) (err string) {
defer func() {
@@ -372,6 +374,8 @@ func parseCmds() {
flag.BoolVar(&flagCmdRunLdapSync, "ldap_sync", false, "")
flag.BoolVar(&flagCmdMigrateAccounts, "migrate_accounts", false, "")
flag.BoolVar(&flagCmdUploadLicense, "upload_license", false, "")
flag.BoolVar(&flagCmdActivateUser, "activate_user", false, "")
flag.BoolVar(&flagUserSetInactive, "inactive", false, "")
flag.Parse()
@@ -397,7 +401,8 @@ func parseCmds() {
flagCmdResetDatabase ||
flagCmdRunLdapSync ||
flagCmdMigrateAccounts ||
flagCmdUploadLicense)
flagCmdUploadLicense ||
flagCmdActivateUser)
}
func runCmds() {
@@ -423,6 +428,7 @@ func runCmds() {
cmdUploadLicense()
cmdRunLdapSync()
cmdRunMigrateAccounts()
cmdActivateUser()
}
type TeamForUpgrade struct {
@@ -1336,6 +1342,34 @@ func cmdUploadLicense() {
}
}
func cmdActivateUser() {
if flagCmdActivateUser {
if len(flagEmail) == 0 {
fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
flag.Usage()
os.Exit(1)
}
var user *model.User
if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil {
l4g.Error("%v", result.Err)
flushLogAndExit(1)
} else {
user = result.Data.(*model.User)
}
if user.IsLDAPUser() {
l4g.Error("%v", utils.T("api.user.update_active.no_deactivate_ldap.app_error"))
}
if _, err := api.UpdateActive(user, !flagUserSetInactive); err != nil {
l4g.Error("%v", err)
}
os.Exit(0)
}
}
func flushLogAndExit(code int) {
l4g.Close()
time.Sleep(time.Second)
@@ -1391,6 +1425,13 @@ FLAGS:
admin who has access to all teams
and configuration settings.
COMMANDS:
-activate_user Set a user as active or inactive. It requies
the -email flag.
Examples:
platform -activate_user -email="user@example.com"
platform -activate_user -inactive -email="user@example.com"
-create_team Creates a team. It requires the -team_name
and -email flag to create a team.
Example: