mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Minor updates to team
This commit is contained in:
@@ -235,7 +235,7 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if team.Type != model.TEAM_OPEN && c.Session.GetTeamByTeamId(team.Id) == nil {
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && c.Session.GetTeamByTeamId(team.Id) == nil {
|
||||
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
|
||||
@@ -787,12 +787,15 @@ func TestGetTeamByName(t *testing.T) {
|
||||
th := Setup().InitSystemAdmin().InitBasic()
|
||||
Client := th.BasicClient
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_INVITE}
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN, AllowOpenInvite: false}
|
||||
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||
|
||||
team2 := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN}
|
||||
team2 := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN, AllowOpenInvite: true}
|
||||
team2 = Client.Must(Client.CreateTeam(team2)).Data.(*model.Team)
|
||||
|
||||
team3 := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_INVITE, AllowOpenInvite: true}
|
||||
team3 = Client.Must(Client.CreateTeam(team3)).Data.(*model.Team)
|
||||
|
||||
if _, err := Client.GetTeamByName(team.Name); err != nil {
|
||||
t.Fatal("Failed to get team")
|
||||
}
|
||||
@@ -813,7 +816,7 @@ func TestGetTeamByName(t *testing.T) {
|
||||
|
||||
Client.Login(user2.Email, "passwd1")
|
||||
|
||||
// TEAM_INVITE and user is not part of the team
|
||||
// AllowInviteOpen is false and team is open and user is not part of the team
|
||||
if _, err := Client.GetTeamByName(team.Name); err == nil {
|
||||
t.Fatal("Should fail dont have permissions to get the team")
|
||||
}
|
||||
@@ -822,21 +825,30 @@ func TestGetTeamByName(t *testing.T) {
|
||||
t.Fatal("Should not exist this team")
|
||||
}
|
||||
|
||||
// TEAM_OPEN and user is not part of the team
|
||||
// AllowInviteOpen is true and is open and user is not part of the team
|
||||
if _, err := Client.GetTeamByName(team2.Name); err != nil {
|
||||
t.Fatal("Should not fail team is open")
|
||||
}
|
||||
|
||||
// AllowInviteOpen is true and is invite only and user is not part of the team
|
||||
if _, err := Client.GetTeamByName(team3.Name); err == nil {
|
||||
t.Fatal("Should fail team is invite only")
|
||||
}
|
||||
|
||||
Client.Must(Client.Logout())
|
||||
th.BasicClient.Logout()
|
||||
th.LoginSystemAdmin()
|
||||
|
||||
if _, err := th.SystemAdminClient.GetTeamByName(team.Name); err != nil {
|
||||
t.Fatal("Should not failed to get team the user is admin")
|
||||
t.Fatal("Should not fail to get team the user is admin")
|
||||
}
|
||||
|
||||
if _, err := th.SystemAdminClient.GetTeamByName(team2.Name); err != nil {
|
||||
t.Fatal("Should not failed to get team the user is admin and team is open")
|
||||
t.Fatal("Should not fail to get team the user is admin and team is open")
|
||||
}
|
||||
|
||||
if _, err := th.SystemAdminClient.GetTeamByName(team3.Name); err != nil {
|
||||
t.Fatal("Should not fail to get team the user is admin and team is invite")
|
||||
}
|
||||
|
||||
if _, err := Client.GetTeamByName("InvalidTeamName"); err == nil {
|
||||
|
||||
@@ -85,7 +85,7 @@ func getTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if team.Type != model.TEAM_OPEN && !app.SessionHasPermissionToTeam(c.Session, team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && !app.SessionHasPermissionToTeam(c.Session, team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if team.Type != model.TEAM_OPEN && !app.SessionHasPermissionToTeam(c.Session, team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && !app.SessionHasPermissionToTeam(c.Session, team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,13 +106,21 @@ func TestGetTeam(t *testing.T) {
|
||||
|
||||
th.LoginTeamAdmin()
|
||||
|
||||
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
|
||||
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
|
||||
rteam2, _ := Client.CreateTeam(team2)
|
||||
|
||||
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
|
||||
rteam3, _ := Client.CreateTeam(team3)
|
||||
|
||||
th.LoginBasic()
|
||||
// AllowInviteOpen is false and team is open, and user is not on team
|
||||
_, resp = Client.GetTeam(rteam2.Id, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// AllowInviteOpen is true and team is invite, and user is not on team
|
||||
_, resp = Client.GetTeam(rteam3.Id, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.GetTeam(team.Id, "")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
@@ -474,12 +482,20 @@ func TestGetTeamByName(t *testing.T) {
|
||||
|
||||
th.LoginTeamAdmin()
|
||||
|
||||
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
|
||||
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
|
||||
rteam2, _ := Client.CreateTeam(team2)
|
||||
|
||||
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
|
||||
rteam3, _ := Client.CreateTeam(team3)
|
||||
|
||||
th.LoginBasic()
|
||||
// AllowInviteOpen is false and team is open, and user is not on team
|
||||
_, resp = Client.GetTeamByName(rteam2.Name, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// AllowInviteOpen is true and team is invite only, and user is not on team
|
||||
_, resp = Client.GetTeamByName(rteam3.Name, "")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestSearchAllTeams(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user