Exemple #1
0
func inviteUser(email string, team *model.Team, teamArg string) {
	invites := []string{email}
	if team == nil {
		CommandPrintErrorln("Can't find team '" + teamArg + "'")
		return
	}
	api.InviteMembers(team, "Administrator", invites)
	CommandPrettyPrintln("Invites may or may not have been sent.")
}
Exemple #2
0
func cmdInviteUser() {
	if flagCmdInviteUser {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_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 len(flagSiteURL) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -site_url")
			flag.Usage()
			os.Exit(1)
		}

		// basic validation of the URL format
		if _, err := url.ParseRequestURI(flagSiteURL); err != nil {
			fmt.Fprintln(os.Stderr, "-site_url flag is invalid. It should look like http://example.com")
			flag.Usage()
			os.Exit(1)
		}

		var team *model.Team
		if result := <-api.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 := <-api.Srv.Store.User().GetByEmail(team.Email); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			user = result.Data.(*model.User)
		}

		invites := []string{flagEmail}
		c := getMockContext()
		c.SetSiteURL(strings.TrimSuffix(flagSiteURL, "/"))
		api.InviteMembers(c, team, user, invites)

		os.Exit(0)
	}
}
Exemple #3
0
func cmdInviteUser() {
	if flagCmdInviteUser {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_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 len(*utils.Cfg.ServiceSettings.SiteURL) == 0 {
			fmt.Fprintln(os.Stderr, "SiteURL must be specified in config.json")
			os.Exit(1)
		}

		var team *model.Team
		if result := <-api.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 := <-api.Srv.Store.User().GetByEmail(team.Email); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			user = result.Data.(*model.User)
		}

		invites := []string{flagEmail}
		c := getMockContext()
		api.InviteMembers(c, team, user, invites)

		os.Exit(0)
	}
}