Ejemplo n.º 1
0
func cmdLeaveChannel() {
	if flagCmdLeaveChannel {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
			os.Exit(1)
		}

		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			os.Exit(1)
		}

		if len(flagChannelName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -channel_name")
			os.Exit(1)
		}

		if flagChannelName == model.DEFAULT_CHANNEL {
			fmt.Fprintln(os.Stderr, "flag has invalid argument: -channel_name (cannot leave town-square)")
			os.Exit(1)
		}

		if !utils.IsLicensed {
			fmt.Fprintln(os.Stderr, utils.T("cli.license.critical"))
			os.Exit(1)
		}

		var team *model.Team
		if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			team = result.Data.(*model.Team)
		}

		var user *model.User
		if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			user = result.Data.(*model.User)
		}

		var channel *model.Channel
		if result := <-app.Srv.Store.Channel().GetByName(team.Id, flagChannelName); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			channel = result.Data.(*model.Channel)
		}

		err := api.RemoveUserFromChannel(user.Id, user.Id, channel)
		if err != nil {
			l4g.Error("%v", err)
			flushLogAndExit(1)
		}

		os.Exit(0)
	}
}
Ejemplo n.º 2
0
func removeUserFromChannel(channel *model.Channel, user *model.User, userArg string) {
	if user == nil {
		CommandPrintErrorln("Can't find user '" + userArg + "'")
		return
	}
	if err := api.RemoveUserFromChannel(user.Id, "", channel); err != nil {
		CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
	}
}