本文整理汇总了Golang中github.com/mattermost/platform/utils.SetDefaultRolesBasedOnConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang SetDefaultRolesBasedOnConfig函数的具体用法?Golang SetDefaultRolesBasedOnConfig怎么用?Golang SetDefaultRolesBasedOnConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetDefaultRolesBasedOnConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestListOutgoingHooks
func TestListOutgoingHooks(t *testing.T) {
th := Setup().InitSystemAdmin()
Client := th.SystemAdminClient
team := th.SystemAdminTeam
channel1 := th.CreateChannel(Client, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
utils.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
hook1 := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
hook1 = Client.Must(Client.CreateOutgoingWebhook(hook1)).Data.(*model.OutgoingWebhook)
hook2 := &model.OutgoingWebhook{TriggerWords: []string{"trigger"}, CallbackURLs: []string{"http://nowhere.com"}}
hook2 = Client.Must(Client.CreateOutgoingWebhook(hook2)).Data.(*model.OutgoingWebhook)
if result, err := Client.ListOutgoingWebhooks(); err != nil {
t.Fatal(err)
} else {
hooks := result.Data.([]*model.OutgoingWebhook)
if len(hooks) != 2 {
t.Fatal("incorrect number of hooks")
}
}
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
if _, err := Client.ListOutgoingWebhooks(); err == nil {
t.Fatal("should have failed - not system/team admin")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.ListOutgoingWebhooks(); err != nil {
t.Fatal(err)
}
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
if _, err := Client.ListOutgoingWebhooks(); err == nil {
t.Fatal("should have errored - webhooks turned off")
}
}
示例2: TestOAuthDeleteApp
func TestOAuthDeleteApp(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient
AdminClient := th.SystemAdminClient
if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.DeleteOAuthApp("fakeId"); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
app := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
app = Client.Must(Client.RegisterApp(app)).Data.(*model.OAuthApp)
if _, err := Client.DeleteOAuthApp(app.Id); err != nil {
t.Fatal(err)
}
app = &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
app = Client.Must(Client.RegisterApp(app)).Data.(*model.OAuthApp)
if _, err := AdminClient.DeleteOAuthApp(app.Id); err != nil {
t.Fatal(err)
}
}
示例3: setupClientTests
func setupClientTests() {
*utils.Cfg.TeamSettings.EnableOpenServer = true
*utils.Cfg.ServiceSettings.EnableCommands = false
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
*utils.Cfg.ServiceSettings.EnableCustomEmoji = true
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
utils.SetDefaultRolesBasedOnConfig()
}
示例4: TestGetOAuthAppsByUser
func TestGetOAuthAppsByUser(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient
AdminClient := th.SystemAdminClient
if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
if _, err := Client.GetOAuthAppsByUser(); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
}
utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
if _, err := Client.GetOAuthAppsByUser(); err != nil {
t.Fatal("Should have passed.")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
if result, err := Client.GetOAuthAppsByUser(); err != nil {
t.Fatal(err)
} else {
apps := result.Data.([]*model.OAuthApp)
if len(apps) != 0 {
t.Fatal("incorrect number of apps should have been 0")
}
}
app := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
app = Client.Must(Client.RegisterApp(app)).Data.(*model.OAuthApp)
if result, err := Client.GetOAuthAppsByUser(); err != nil {
t.Fatal(err)
} else {
apps := result.Data.([]*model.OAuthApp)
if len(apps) != 1 {
t.Fatal("incorrect number of apps should have been 1")
}
}
app = &model.OAuthApp{Name: "TestApp4" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
app = AdminClient.Must(Client.RegisterApp(app)).Data.(*model.OAuthApp)
if result, err := AdminClient.GetOAuthAppsByUser(); err != nil {
t.Fatal(err)
} else {
apps := result.Data.([]*model.OAuthApp)
if len(apps) < 4 {
t.Fatal("incorrect number of apps should have been 4 or more")
}
}
}
示例5: TestInviteMembers
func TestInviteMembers(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
th.BasicClient.Logout()
Client := th.BasicClient
SystemAdminClient := th.SystemAdminClient
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
user := &model.User{Email: model.NewId() + "[email protected]", Nickname: "Corey Hulen", Password: "passwd1"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
LinkUserToTeam(user, team)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
Client.Login(user.Email, "passwd1")
Client.SetTeamId(team.Id)
invite := make(map[string]string)
invite["email"] = "success+" + model.NewId() + "@simulator.amazonses.com"
invite["first_name"] = "Test"
invite["last_name"] = "Guy"
invites := &model.Invites{Invites: []map[string]string{invite}}
invites.Invites = append(invites.Invites, invite)
if _, err := Client.InviteMembers(invites); err != nil {
t.Fatal(err)
}
invites2 := &model.Invites{Invites: []map[string]string{}}
if _, err := Client.InviteMembers(invites2); err == nil {
t.Fatal("Should have errored out on no invites to send")
}
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic2()
LinkUserToTeam(th.BasicUser2, team)
if _, err := Client.InviteMembers(invites); err != nil {
t.Fatal(err)
}
isLicensed := utils.IsLicensed
license := utils.License
defer func() {
utils.IsLicensed = isLicensed
utils.License = license
}()
utils.IsLicensed = true
utils.License = &model.License{Features: &model.Features{}}
utils.License.Features.SetDefaults()
if _, err := Client.InviteMembers(invites); err == nil {
t.Fatal("should have errored not team admin and licensed")
}
UpdateUserToTeamAdmin(th.BasicUser2, team)
Client.Logout()
th.LoginBasic2()
Client.SetTeamId(team.Id)
if _, err := Client.InviteMembers(invites); err != nil {
t.Fatal(err)
}
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.InviteMembers(invites); err == nil {
t.Fatal("should have errored not system admin and licensed")
}
LinkUserToTeam(th.SystemAdminUser, team)
if _, err := SystemAdminClient.InviteMembers(invites); err != nil {
t.Fatal(err)
}
}
示例6: TestGetAccessToken
func TestGetAccessToken(t *testing.T) {
Setup()
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "[email protected]", Type: model.TEAM_OPEN}
rteam, _ := ApiClient.CreateTeam(&team)
user := model.User{Email: strings.ToLower(model.NewId()) + "[email protected]", Password: "passwd1"}
ruser := ApiClient.Must(ApiClient.CreateUser(&user, "")).Data.(*model.User)
api.JoinUserToTeam(rteam.Data.(*model.Team), ruser)
store.Must(api.Srv.Store.User().VerifyEmail(ruser.Id))
app := &model.OAuthApp{Name: "TestApp" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = false
data := url.Values{"grant_type": []string{"junk"}, "client_id": []string{"12345678901234567890123456"}, "client_secret": []string{"12345678901234567890123456"}, "code": []string{"junk"}, "redirect_uri": []string{app.CallbackUrls[0]}}
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - oauth providing turned off")
}
utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
ApiClient.Must(ApiClient.LoginById(ruser.Id, "passwd1"))
ApiClient.SetTeamId(rteam.Data.(*model.Team).Id)
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
app = ApiClient.Must(ApiClient.RegisterApp(app)).Data.(*model.OAuthApp)
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
redirect := ApiClient.Must(ApiClient.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, app.Id, app.CallbackUrls[0], "all", "123")).Data.(map[string]string)["redirect"]
rurl, _ := url.Parse(redirect)
teamId := rteam.Data.(*model.Team).Id
ApiClient.Logout()
data = url.Values{"grant_type": []string{"junk"}, "client_id": []string{app.Id}, "client_secret": []string{app.ClientSecret}, "code": []string{rurl.Query().Get("code")}, "redirect_uri": []string{app.CallbackUrls[0]}}
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - bad grant type")
}
data.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE)
data.Set("client_id", "")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - missing client id")
}
data.Set("client_id", "junk")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - bad client id")
}
data.Set("client_id", app.Id)
data.Set("client_secret", "")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - missing client secret")
}
data.Set("client_secret", "junk")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - bad client secret")
}
data.Set("client_secret", app.ClientSecret)
data.Set("code", "")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - missing code")
}
data.Set("code", "junk")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - bad code")
}
data.Set("code", rurl.Query().Get("code"))
data.Set("redirect_uri", "junk")
if _, err := ApiClient.GetAccessToken(data); err == nil {
t.Fatal("should have failed - non-matching redirect uri")
}
// reset data for successful request
data.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE)
data.Set("client_id", app.Id)
data.Set("client_secret", app.ClientSecret)
data.Set("code", rurl.Query().Get("code"))
data.Set("redirect_uri", app.CallbackUrls[0])
token := ""
if result, err := ApiClient.GetAccessToken(data); err != nil {
t.Fatal(err)
} else {
rsp := result.Data.(*model.AccessResponse)
if len(rsp.AccessToken) == 0 {
t.Fatal("access token not returned")
} else {
token = rsp.AccessToken
}
if rsp.TokenType != model.ACCESS_TOKEN_TYPE {
t.Fatal("access token type incorrect")
}
//.........这里部分代码省略.........
示例7: TestRegenOutgoingHookToken
func TestRegenOutgoingHookToken(t *testing.T) {
th := Setup().InitSystemAdmin()
Client := th.SystemAdminClient
team := th.SystemAdminTeam
team2 := th.CreateTeam(Client)
channel1 := th.CreateChannel(Client, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
user3 := th.CreateUser(Client)
LinkUserToTeam(user3, team2)
enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
utils.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
if _, err := Client.RegenOutgoingWebhookToken("junk"); err == nil {
t.Fatal("should have failed - bad id")
}
if _, err := Client.RegenOutgoingWebhookToken(""); err == nil {
t.Fatal("should have failed - empty id")
}
if result, err := Client.RegenOutgoingWebhookToken(hook.Id); err != nil {
t.Fatal(err)
} else {
if result.Data.(*model.OutgoingWebhook).Token == hook.Token {
t.Fatal("regen didn't work properly")
}
}
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err == nil {
t.Fatal("should have failed - not system/team admin")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err != nil {
t.Fatal(err)
}
Client.Logout()
Client.Must(Client.LoginById(user3.Id, user3.Password))
Client.SetTeamId(team2.Id)
if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err == nil {
t.Fatal("should have failed - wrong team")
}
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = false
if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err == nil {
t.Fatal("should have errored - webhooks turned off")
}
}
示例8: TestCreateOutgoingHook
func TestCreateOutgoingHook(t *testing.T) {
th := Setup().InitSystemAdmin()
Client := th.SystemAdminClient
user := th.SystemAdminUser
team := th.SystemAdminTeam
team2 := th.CreateTeam(Client)
channel1 := th.CreateChannel(Client, team)
channel2 := th.CreatePrivateChannel(Client, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
user3 := th.CreateUser(Client)
LinkUserToTeam(user3, team2)
enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
utils.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
var rhook *model.OutgoingWebhook
if result, err := Client.CreateOutgoingWebhook(hook); err != nil {
t.Fatal(err)
} else {
rhook = result.Data.(*model.OutgoingWebhook)
}
if hook.ChannelId != rhook.ChannelId {
t.Fatal("channel ids didn't match")
}
if rhook.CreatorId != user.Id {
t.Fatal("user ids didn't match")
}
if rhook.TeamId != team.Id {
t.Fatal("team ids didn't match")
}
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, TriggerWords: []string{"cats", "dogs"}, CallbackURLs: []string{"http://nowhere.com", "http://cats.com"}}
hook1 := &model.OutgoingWebhook{ChannelId: channel1.Id, TriggerWords: []string{"cats"}, CallbackURLs: []string{"http://nowhere.com"}}
if _, err := Client.CreateOutgoingWebhook(hook); err != nil {
t.Fatal("multiple trigger words and urls failed")
}
if _, err := Client.CreateOutgoingWebhook(hook1); err == nil {
t.Fatal("should have failed - duplicate trigger words and urls")
}
hook = &model.OutgoingWebhook{ChannelId: "junk", CallbackURLs: []string{"http://nowhere.com"}}
if _, err := Client.CreateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - bad channel id")
}
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, CreatorId: "123", TeamId: "456", CallbackURLs: []string{"http://nowhere.com"}}
if result, err := Client.CreateOutgoingWebhook(hook); err != nil {
t.Fatal(err)
} else {
if result.Data.(*model.OutgoingWebhook).CreatorId != user.Id {
t.Fatal("bad user id wasn't overwritten")
}
if result.Data.(*model.OutgoingWebhook).TeamId != team.Id {
t.Fatal("bad team id wasn't overwritten")
}
}
hook = &model.OutgoingWebhook{ChannelId: channel2.Id, CallbackURLs: []string{"http://nowhere.com"}}
if _, err := Client.CreateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - private channel")
}
hook = &model.OutgoingWebhook{CallbackURLs: []string{"http://nowhere.com"}}
if _, err := Client.CreateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - blank channel and trigger words")
}
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
if _, err := Client.CreateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - not system/team admin")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.CreateOutgoingWebhook(hook); err != nil {
t.Fatal(err)
}
Client.Logout()
//.........这里部分代码省略.........
示例9: TestDeleteIncomingHook
func TestDeleteIncomingHook(t *testing.T) {
th := Setup().InitSystemAdmin()
Client := th.SystemAdminClient
team := th.SystemAdminTeam
channel1 := th.CreateChannel(Client, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
utils.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook)
if _, err := Client.DeleteIncomingWebhook(hook.Id); err != nil {
t.Fatal(err)
}
if _, err := Client.DeleteIncomingWebhook("junk"); err == nil {
t.Fatal("should have failed - bad id")
}
if _, err := Client.DeleteIncomingWebhook(""); err == nil {
t.Fatal("should have failed - empty id")
}
hooks := Client.Must(Client.ListIncomingWebhooks()).Data.([]*model.IncomingWebhook)
if len(hooks) != 0 {
t.Fatal("delete didn't work properly")
}
hook = &model.IncomingWebhook{ChannelId: channel1.Id}
hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook)
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
t.Fatal("should have failed - not system/team admin")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
t.Fatal("should have failed - not creator or team admin")
}
hook = &model.IncomingWebhook{ChannelId: channel1.Id}
hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook)
if _, err := Client.DeleteIncomingWebhook(hook.Id); err != nil {
t.Fatal(err)
}
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
t.Fatal("should have errored - webhooks turned off")
}
}
示例10: TestCreateIncomingHook
func TestCreateIncomingHook(t *testing.T) {
th := Setup().InitSystemAdmin()
Client := th.SystemAdminClient
user := th.SystemAdminUser
team := th.SystemAdminTeam
channel1 := th.CreateChannel(Client, team)
channel2 := th.CreatePrivateChannel(Client, team)
channel3 := th.CreateChannel(Client, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
defer func() {
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
utils.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
var rhook *model.IncomingWebhook
if result, err := Client.CreateIncomingWebhook(hook); err != nil {
t.Fatal(err)
} else {
rhook = result.Data.(*model.IncomingWebhook)
}
if hook.ChannelId != rhook.ChannelId {
t.Fatal("channel ids didn't match")
}
if rhook.UserId != user.Id {
t.Fatal("user ids didn't match")
}
if rhook.TeamId != team.Id {
t.Fatal("team ids didn't match")
}
hook = &model.IncomingWebhook{ChannelId: "junk"}
if _, err := Client.CreateIncomingWebhook(hook); err == nil {
t.Fatal("should have failed - bad channel id")
}
hook = &model.IncomingWebhook{ChannelId: channel2.Id, UserId: "123", TeamId: "456"}
if result, err := Client.CreateIncomingWebhook(hook); err != nil {
t.Fatal(err)
} else {
if result.Data.(*model.IncomingWebhook).UserId != user.Id {
t.Fatal("bad user id wasn't overwritten")
}
if result.Data.(*model.IncomingWebhook).TeamId != team.Id {
t.Fatal("bad team id wasn't overwritten")
}
}
Client.Must(Client.LeaveChannel(channel3.Id))
hook = &model.IncomingWebhook{ChannelId: channel3.Id, UserId: user.Id, TeamId: team.Id}
if _, err := Client.CreateIncomingWebhook(hook); err != nil {
t.Fatal(err)
}
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
hook = &model.IncomingWebhook{ChannelId: channel1.Id}
if _, err := Client.CreateIncomingWebhook(hook); err == nil {
t.Fatal("should have failed - not system/team admin")
}
Client.Logout()
UpdateUserToTeamAdmin(user2, team)
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
if _, err := Client.CreateIncomingWebhook(hook); err != nil {
t.Fatal(err)
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.CreateIncomingWebhook(hook); err != nil {
t.Fatal(err)
}
hook = &model.IncomingWebhook{ChannelId: channel2.Id}
if _, err := Client.CreateIncomingWebhook(hook); err == nil {
t.Fatal("should have failed - channel is private and not a member")
}
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = false
//.........这里部分代码省略.........
示例11: TestDeleteChannel
func TestDeleteChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.SystemAdminClient
team := th.SystemAdminTeam
userSystemAdmin := th.SystemAdminUser
userTeamAdmin := th.CreateUser(Client)
LinkUserToTeam(userTeamAdmin, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
Client.Login(user2.Email, user2.Password)
channelMadeByCA := &model.Channel{DisplayName: "C Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channelMadeByCA = Client.Must(Client.CreateChannel(channelMadeByCA)).Data.(*model.Channel)
Client.AddChannelMember(channelMadeByCA.Id, userTeamAdmin.Id)
Client.Login(userTeamAdmin.Email, "pwd")
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
if _, err := Client.DeleteChannel(channel1.Id); err != nil {
t.Fatal(err)
}
if _, err := Client.DeleteChannel(channelMadeByCA.Id); err != nil {
t.Fatal("Team admin failed to delete Channel Admin's channel")
}
post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
if _, err := Client.CreatePost(post1); err == nil {
t.Fatal("should have failed to post to deleted channel")
}
userStd := th.CreateUser(Client)
LinkUserToTeam(userStd, team)
Client.Login(userStd.Email, userStd.Password)
if _, err := Client.JoinChannel(channel1.Id); err == nil {
t.Fatal("should have failed to join deleted channel")
}
Client.Must(Client.JoinChannel(channel2.Id))
if _, err := Client.DeleteChannel(channel2.Id); err != nil {
t.Fatal(err)
}
rget := Client.Must(Client.GetChannels(""))
cdata := rget.Data.(*model.ChannelList)
for _, c := range cdata.Channels {
if c.Name == model.DEFAULT_CHANNEL {
if _, err := Client.DeleteChannel(c.Id); err == nil {
t.Fatal("should have errored on deleting default channel")
}
break
}
}
UpdateUserToTeamAdmin(userStd, team)
Client.Logout()
Client.Login(userStd.Email, userStd.Password)
Client.SetTeamId(team.Id)
channel2 = th.CreateChannel(Client, team)
if _, err := Client.DeleteChannel(channel2.Id); err != nil {
t.Fatal(err)
}
channel3 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel3 = Client.Must(Client.CreateChannel(channel3)).Data.(*model.Channel)
Client.Login(userSystemAdmin.Email, userSystemAdmin.Password)
Client.Must(Client.JoinChannel(channel3.Id))
if _, err := Client.DeleteChannel(channel3.Id); err != nil {
t.Fatal(err)
}
if _, err := Client.DeleteChannel(channel3.Id); err == nil {
t.Fatal("should have failed - channel already deleted")
}
isLicensed := utils.IsLicensed
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
//.........这里部分代码省略.........
示例12: TestUpdateChannelPurpose
func TestUpdateChannelPurpose(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient
SystemAdminClient := th.SystemAdminClient
team := th.BasicTeam
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
data := make(map[string]string)
data["channel_id"] = channel1.Id
data["channel_purpose"] = "new purpose"
var upChannel1 *model.Channel
if result, err := Client.UpdateChannelPurpose(data); err != nil {
t.Fatal(err)
} else {
upChannel1 = result.Data.(*model.Channel)
}
if upChannel1.Purpose != data["channel_purpose"] {
t.Fatal("Failed to update purpose")
}
data["channel_id"] = "junk"
if _, err := Client.UpdateChannelPurpose(data); err == nil {
t.Fatal("should have errored on junk channel id")
}
data["channel_id"] = "12345678901234567890123456"
if _, err := Client.UpdateChannelPurpose(data); err == nil {
t.Fatal("should have errored on non-existent channel id")
}
data["channel_id"] = channel1.Id
data["channel_purpose"] = strings.Repeat("a", 150)
if _, err := Client.UpdateChannelPurpose(data); err == nil {
t.Fatal("should have errored on bad channel purpose")
}
th.LoginBasic2()
data["channel_id"] = channel1.Id
data["channel_purpose"] = "new purpose"
if _, err := Client.UpdateChannelPurpose(data); err == nil {
t.Fatal("should have errored non-channel member trying to update purpose")
}
isLicensed := utils.IsLicensed
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
channel2 := th.CreateChannel(Client, team)
channel3 := th.CreatePrivateChannel(Client, team)
data2 := make(map[string]string)
data2["channel_id"] = channel2.Id
data2["channel_purpose"] = "new purpose"
data3 := make(map[string]string)
data3["channel_id"] = channel3.Id
data3["channel_purpose"] = "new purpose"
Client.Login(th.BasicUser.Email, th.BasicUser.Password)
if _, err := Client.UpdateChannelPurpose(data2); err != nil {
t.Fatal(err)
}
if _, err := Client.UpdateChannelPurpose(data3); err != nil {
t.Fatal(err)
}
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
t.Fatal("should have errored not team admin")
}
if _, err := Client.UpdateChannelPurpose(data3); err == nil {
t.Fatal("should have errored not team admin")
}
UpdateUserToTeamAdmin(th.BasicUser, team)
Client.Logout()
th.LoginBasic()
Client.SetTeamId(team.Id)
if _, err := Client.UpdateChannelPurpose(data2); err != nil {
//.........这里部分代码省略.........
示例13: TestUpdateChannel
func TestUpdateChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.SystemAdminClient
team := th.SystemAdminTeam
sysAdminUser := th.SystemAdminUser
user := th.CreateUser(Client)
LinkUserToTeam(user, team)
user2 := th.CreateUser(Client)
LinkUserToTeam(user2, team)
Client.Login(user.Email, user.Password)
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
Client.AddChannelMember(channel1.Id, user.Id)
header := "a" + model.NewId() + "a"
purpose := "a" + model.NewId() + "a"
upChannel1 := &model.Channel{Id: channel1.Id, Header: header, Purpose: purpose}
upChannel1 = Client.Must(Client.UpdateChannel(upChannel1)).Data.(*model.Channel)
if upChannel1.Header != header {
t.Fatal("Channel admin failed to update header")
}
if upChannel1.Purpose != purpose {
t.Fatal("Channel admin failed to update purpose")
}
if upChannel1.DisplayName != channel1.DisplayName {
t.Fatal("Channel admin failed to skip displayName")
}
rget := Client.Must(Client.GetChannels(""))
data := rget.Data.(*model.ChannelList)
for _, c := range data.Channels {
if c.Name == model.DEFAULT_CHANNEL {
c.Header = "new header"
c.Name = "pseudo-square"
if _, err := Client.UpdateChannel(c); err == nil {
t.Fatal("should have errored on updating default channel name")
}
break
}
}
Client.Login(user2.Email, user2.Password)
if _, err := Client.UpdateChannel(upChannel1); err == nil {
t.Fatal("Standard User should have failed to update")
}
Client.Must(Client.JoinChannel(channel1.Id))
UpdateUserToTeamAdmin(user2, team)
Client.Logout()
Client.Login(user2.Email, user2.Password)
Client.SetTeamId(team.Id)
if _, err := Client.UpdateChannel(upChannel1); err != nil {
t.Fatal(err)
}
Client.Login(sysAdminUser.Email, sysAdminUser.Password)
LinkUserToTeam(sysAdminUser, team)
Client.Must(Client.JoinChannel(channel1.Id))
if _, err := Client.UpdateChannel(upChannel1); err != nil {
t.Fatal(err)
}
Client.Must(Client.DeleteChannel(channel1.Id))
if _, err := Client.UpdateChannel(upChannel1); err == nil {
t.Fatal("should have failed - channel deleted")
}
isLicensed := utils.IsLicensed
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true
utils.SetDefaultRolesBasedOnConfig()
channel2 := th.CreateChannel(Client, team)
channel3 := th.CreatePrivateChannel(Client, team)
LinkUserToTeam(th.BasicUser, team)
Client.Must(Client.AddChannelMember(channel2.Id, th.BasicUser.Id))
Client.Must(Client.AddChannelMember(channel3.Id, th.BasicUser.Id))
//.........这里部分代码省略.........
示例14: TestCreateChannel
func TestCreateChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient
SystemAdminClient := th.SystemAdminClient
team := th.BasicTeam
Client.Must(Client.Logout())
team2 := th.CreateTeam(th.BasicClient)
th.LoginBasic()
th.BasicClient.SetTeamId(team.Id)
channel := model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
rchannel, err := Client.CreateChannel(&channel)
if err != nil {
t.Fatal(err)
}
if rchannel.Data.(*model.Channel).Name != channel.Name {
t.Fatal("full name didn't match")
}
rget := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
nameMatch := false
for _, c := range rget.Channels {
if c.Name == channel.Name {
nameMatch = true
}
}
if !nameMatch {
t.Fatal("Did not create channel with correct name")
}
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err == nil {
t.Fatal("Cannot create an existing")
}
savedId := rchannel.Data.(*model.Channel).Id
rchannel.Data.(*model.Channel).Id = ""
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err != nil {
if err.Message != "A channel with that URL already exists" {
t.Fatal(err)
}
}
if _, err := Client.DoApiPost(Client.GetTeamRoute()+"/channels/create", "garbage"); err == nil {
t.Fatal("should have been an error")
}
Client.DeleteChannel(savedId)
if _, err := Client.CreateChannel(rchannel.Data.(*model.Channel)); err != nil {
if err.Message != "A channel with that URL was previously created" {
t.Fatal(err)
}
}
channel = model.Channel{DisplayName: "Channel on Different Team", Name: "aaaa" + model.NewId() + "abbb", Type: model.CHANNEL_OPEN, TeamId: team2.Id}
if _, err := Client.CreateChannel(&channel); err.StatusCode != http.StatusForbidden {
t.Fatal(err)
}
channel = model.Channel{DisplayName: "Channel With No TeamId", Name: "aaaa" + model.NewId() + "abbb", Type: model.CHANNEL_OPEN, TeamId: ""}
if _, err := Client.CreateChannel(&channel); err != nil {
t.Fatal(err)
}
channel = model.Channel{DisplayName: "Test API Name", Name: model.NewId() + "__" + model.NewId(), Type: model.CHANNEL_OPEN, TeamId: team.Id}
if _, err := Client.CreateChannel(&channel); err == nil {
t.Fatal("Should have errored out on invalid '__' character")
}
channel = model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_DIRECT, TeamId: team.Id}
if _, err := Client.CreateChannel(&channel); err == nil {
t.Fatal("Should have errored out on direct channel type")
}
isLicensed := utils.IsLicensed
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.SetDefaultRolesBasedOnConfig()
utils.IsLicensed = true
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel3 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
if _, err := Client.CreateChannel(channel2); err != nil {
t.Fatal(err)
}
if _, err := Client.CreateChannel(channel3); err != nil {
//.........这里部分代码省略.........
示例15: TestUpdateChannelHeader
func TestUpdateChannelHeader(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient
SystemAdminClient := th.SystemAdminClient
team := th.BasicTeam
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
data := make(map[string]string)
data["channel_id"] = channel1.Id
data["channel_header"] = "new header"
var upChannel1 *model.Channel
if result, err := Client.UpdateChannelHeader(data); err != nil {
t.Fatal(err)
} else {
upChannel1 = result.Data.(*model.Channel)
}
r1 := Client.Must(Client.GetPosts(channel1.Id, 0, 1, "")).Data.(*model.PostList)
if len(r1.Order) != 1 {
t.Fatal("Header update system message was not found")
} else if val, ok := r1.Posts[r1.Order[0]].Props["old_header"]; !ok || val != "" {
t.Fatal("Props should contain old_header with old header value")
} else if val, ok := r1.Posts[r1.Order[0]].Props["new_header"]; !ok || val != "new header" {
t.Fatal("Props should contain new_header with new header value")
}
if upChannel1.Header != data["channel_header"] {
t.Fatal("Failed to update header")
}
data["channel_id"] = "junk"
if _, err := Client.UpdateChannelHeader(data); err == nil {
t.Fatal("should have errored on junk channel id")
}
data["channel_id"] = "12345678901234567890123456"
if _, err := Client.UpdateChannelHeader(data); err == nil {
t.Fatal("should have errored on non-existent channel id")
}
data["channel_id"] = channel1.Id
data["channel_header"] = strings.Repeat("a", 1050)
if _, err := Client.UpdateChannelHeader(data); err == nil {
t.Fatal("should have errored on bad channel header")
}
rchannel := Client.Must(Client.CreateDirectChannel(th.BasicUser2.Id)).Data.(*model.Channel)
data["channel_id"] = rchannel.Id
data["channel_header"] = "new header"
var upChanneld *model.Channel
if result, err := Client.UpdateChannelHeader(data); err != nil {
t.Fatal(err)
} else {
upChanneld = result.Data.(*model.Channel)
}
if upChanneld.Header != data["channel_header"] {
t.Fatal("Failed to update header")
}
th.LoginBasic2()
data["channel_id"] = channel1.Id
data["channel_header"] = "new header"
if _, err := Client.UpdateChannelHeader(data); err == nil {
t.Fatal("should have errored non-channel member trying to update header")
}
isLicensed := utils.IsLicensed
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
channel2 := th.CreateChannel(Client, team)
channel3 := th.CreatePrivateChannel(Client, team)
data2 := make(map[string]string)
data2["channel_id"] = channel2.Id
data2["channel_header"] = "new header"
data3 := make(map[string]string)
data3["channel_id"] = channel3.Id
data3["channel_header"] = "new header"
Client.Login(th.BasicUser.Email, th.BasicUser.Password)
if _, err := Client.UpdateChannelHeader(data2); err != nil {
//.........这里部分代码省略.........