EE: PLT-3747 Add create_channel to command line (#3760)

* PLT-3747 Add create_channel command line

* Added tests

* Set as EE feature
Этот коммит содержится в:
enahum
2016-08-12 06:50:11 -05:00
коммит произвёл Joram Wilander
родитель c0a905c037
Коммит 53c068952c
2 изменённых файлов: 131 добавлений и 6 удалений

Просмотреть файл

@@ -389,3 +389,31 @@ func TestCliResetPassword(t *testing.T) {
th.BasicUser.Password = "password2" th.BasicUser.Password = "password2"
th.LoginBasic() th.LoginBasic()
} }
func TestCliCreateChannel(t *testing.T) {
if disableCliTests {
return
}
th := Setup().InitBasic()
id := model.NewId()
name := "name" + id
// should fail because channel does not have license
cmd := exec.Command("bash", "-c", `go run ../mattermost.go -create_channel -email="`+th.BasicUser.Email+`" -team_name="`+th.BasicTeam.Name+`" -channel_type="O" -channel_name="`+name+`"`)
output, err := cmd.CombinedOutput()
if err == nil {
t.Log(string(output))
t.Fatal()
}
// should fail because channel does not have license
name = name + "-private"
cmd2 := exec.Command("bash", "-c", `go run ../mattermost.go -create_channel -email="`+th.BasicUser.Email+`" -team_name="`+th.BasicTeam.Name+`" -channel_type="P" -channel_name="`+name+`"`)
output2, err2 := cmd2.CombinedOutput()
if err2 == nil {
t.Log(string(output2))
t.Fatal()
}
}

Просмотреть файл

@@ -45,6 +45,7 @@ var flagCmdCreateTeam bool
var flagCmdCreateUser bool var flagCmdCreateUser bool
var flagCmdInviteUser bool var flagCmdInviteUser bool
var flagCmdAssignRole bool var flagCmdAssignRole bool
var flagCmdCreateChannel bool
var flagCmdJoinChannel bool var flagCmdJoinChannel bool
var flagCmdLeaveChannel bool var flagCmdLeaveChannel bool
var flagCmdListChannels bool var flagCmdListChannels bool
@@ -76,6 +77,9 @@ var flagRunCmds bool
var flagFromAuth string var flagFromAuth string
var flagToAuth string var flagToAuth string
var flagMatchField string var flagMatchField string
var flagChannelType string
var flagChannelHeader string
var flagChannelPurpose string
func doLoadConfig(filename string) (err string) { func doLoadConfig(filename string) (err string) {
defer func() { defer func() {
@@ -302,12 +306,16 @@ func parseCmds() {
flag.StringVar(&flagToAuth, "to_auth", "", "") flag.StringVar(&flagToAuth, "to_auth", "", "")
flag.StringVar(&flagMatchField, "match_field", "email", "") flag.StringVar(&flagMatchField, "match_field", "email", "")
flag.StringVar(&flagRole, "role", "", "") flag.StringVar(&flagRole, "role", "", "")
flag.StringVar(&flagChannelType, "channel_type", "O", "")
flag.StringVar(&flagChannelHeader, "channel_header", "", "")
flag.StringVar(&flagChannelPurpose, "channel_purpose", "", "")
flag.BoolVar(&flagCmdUpdateDb30, "upgrade_db_30", false, "") flag.BoolVar(&flagCmdUpdateDb30, "upgrade_db_30", false, "")
flag.BoolVar(&flagCmdCreateTeam, "create_team", false, "") flag.BoolVar(&flagCmdCreateTeam, "create_team", false, "")
flag.BoolVar(&flagCmdCreateUser, "create_user", false, "") flag.BoolVar(&flagCmdCreateUser, "create_user", false, "")
flag.BoolVar(&flagCmdInviteUser, "invite_user", false, "") flag.BoolVar(&flagCmdInviteUser, "invite_user", false, "")
flag.BoolVar(&flagCmdAssignRole, "assign_role", false, "") flag.BoolVar(&flagCmdAssignRole, "assign_role", false, "")
flag.BoolVar(&flagCmdCreateChannel, "create_channel", false, "")
flag.BoolVar(&flagCmdJoinChannel, "join_channel", false, "") flag.BoolVar(&flagCmdJoinChannel, "join_channel", false, "")
flag.BoolVar(&flagCmdLeaveChannel, "leave_channel", false, "") flag.BoolVar(&flagCmdLeaveChannel, "leave_channel", false, "")
flag.BoolVar(&flagCmdListChannels, "list_channels", false, "") flag.BoolVar(&flagCmdListChannels, "list_channels", false, "")
@@ -334,6 +342,7 @@ func parseCmds() {
flagCmdInviteUser || flagCmdInviteUser ||
flagCmdLeaveTeam || flagCmdLeaveTeam ||
flagCmdAssignRole || flagCmdAssignRole ||
flagCmdCreateChannel ||
flagCmdJoinChannel || flagCmdJoinChannel ||
flagCmdLeaveChannel || flagCmdLeaveChannel ||
flagCmdListChannels || flagCmdListChannels ||
@@ -361,6 +370,7 @@ func runCmds() {
cmdInviteUser() cmdInviteUser()
cmdLeaveTeam() cmdLeaveTeam()
cmdAssignRole() cmdAssignRole()
cmdCreateChannel()
cmdJoinChannel() cmdJoinChannel()
cmdLeaveChannel() cmdLeaveChannel()
cmdListChannels() cmdListChannels()
@@ -943,6 +953,75 @@ func cmdAssignRole() {
} }
} }
func cmdCreateChannel() {
if flagCmdCreateChannel {
if len(flagTeamName) == 0 {
fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
flag.Usage()
os.Exit(1)
}
if len(flagChannelName) == 0 {
fmt.Fprintln(os.Stderr, "flag needs an argument: -channel_name")
flag.Usage()
os.Exit(1)
}
if len(flagEmail) == 0 {
fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
flag.Usage()
os.Exit(1)
}
if flagChannelType != "O" && flagChannelType != "P" {
fmt.Fprintln(os.Stderr, "flag channel_type must have on of the following values: O or P")
flag.Usage()
os.Exit(1)
}
if !utils.IsLicensed {
fmt.Fprintln(os.Stderr, utils.T("cli.license.critical"))
flag.Usage()
os.Exit(1)
}
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
l4g.Error("%v %v", utils.T(result.Err.Message), result.Err.DetailedError)
flushLogAndExit(1)
} else {
team = result.Data.(*model.Team)
}
var user *model.User
if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil {
l4g.Error("%v %v", utils.T(result.Err.Message), result.Err.DetailedError)
flushLogAndExit(1)
} else {
user = result.Data.(*model.User)
}
c := getMockContext()
c.Session.UserId = user.Id
channel := &model.Channel{}
channel.DisplayName = flagChannelName
channel.CreatorId = user.Id
channel.Name = flagChannelName
channel.TeamId = team.Id
channel.Type = flagChannelType
channel.Header = flagChannelHeader
channel.Purpose = flagChannelPurpose
if _, err := api.CreateChannel(c, channel, true); err != nil {
l4g.Error("%v %v", utils.T(err.Message), err.DetailedError)
flushLogAndExit(1)
}
os.Exit(0)
}
}
func cmdJoinChannel() { func cmdJoinChannel() {
if flagCmdJoinChannel { if flagCmdJoinChannel {
if len(flagTeamName) == 0 { if len(flagTeamName) == 0 {
@@ -1587,6 +1666,17 @@ FLAGS:
-team_name="name" The team name used in other commands -team_name="name" The team name used in other commands
-channel_name="name" The channel name used in other commands
-channel_header="string" The channel header used in other commands
-channel_purpose="string" The channel purpose used in other commands
-channel_type="type" The channel type used in other commands
valid values are
"O" - public channel
"P" - private group
-role="system_admin" The role used in other commands -role="system_admin" The role used in other commands
valid values are valid values are
"" - The empty role is basic user "" - The empty role is basic user
@@ -1628,6 +1718,13 @@ COMMANDS:
Example: Example:
platform -assign_role -email="user@example.com" -role="system_admin" platform -assign_role -email="user@example.com" -role="system_admin"
-create_channel Create a new channel in the specified team. It requires the -email,
-team_name, -channel_name, -channel_type flags. Optional you can set
the -channel_header and -channel_purpose.
Example:
platform -create_channel -email="user@example.com" -team_name="name" -channel_name="channel_name" -channel_type="O"
-join_channel Joins a user to the channel. It requires the -email, channel_name and -join_channel Joins a user to the channel. It requires the -email, channel_name and
-team_name flags. You may need to logout of your current session -team_name flags. You may need to logout of your current session
for the new channel to be applied. Requires an enterprise license. for the new channel to be applied. Requires an enterprise license.