From 1885d2ec2ab6870b735f08752f5354e9f624d87f Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Tue, 8 Aug 2017 16:20:07 -0400 Subject: Minor updates to team --- api4/team.go | 4 ++-- api4/team_test.go | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'api4') diff --git a/api4/team.go b/api4/team.go index 98a672d93..b71b285e6 100644 --- a/api4/team.go +++ b/api4/team.go @@ -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 } diff --git a/api4/team_test.go b/api4/team_test.go index 421428afa..ba7b23ef3 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -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) { -- cgit v1.2.3-1-g7c22