summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2017-08-08 16:20:07 -0400
committerJoramWilander <jwawilander@gmail.com>2017-08-08 16:20:07 -0400
commit1885d2ec2ab6870b735f08752f5354e9f624d87f (patch)
tree5ec059b473ca28ca0c6343d7c82ff4fbff43a616 /api
parent70fe9e9e971943b108492b1814a23bd42eae8ae2 (diff)
downloadchat-1885d2ec2ab6870b735f08752f5354e9f624d87f.tar.gz
chat-1885d2ec2ab6870b735f08752f5354e9f624d87f.tar.bz2
chat-1885d2ec2ab6870b735f08752f5354e9f624d87f.zip
Minor updates to team
Diffstat (limited to 'api')
-rw-r--r--api/team.go2
-rw-r--r--api/team_test.go24
2 files changed, 19 insertions, 7 deletions
diff --git a/api/team.go b/api/team.go
index c7fa61df6..a2ac50116 100644
--- a/api/team.go
+++ b/api/team.go
@@ -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
diff --git a/api/team_test.go b/api/team_test.go
index e09bf42ef..14c9311a3 100644
--- a/api/team_test.go
+++ b/api/team_test.go
@@ -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 {