Commit afa7f70f authored by Derrick Anderson's avatar Derrick Anderson

Merge branch 'XYZ-111' of https://github.com/jespino/platform into jespino-XYZ-111

parents 63d45a0a bda87367
......@@ -302,10 +302,16 @@ func (a *App) joinUserToTeam(team *model.Team, user *model.User) (*model.TeamMem
return rtm, true, nil
}
if tmr := <-a.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
return nil, false, tmr.Err
if membersCount := <-a.Srv.Store.Team().GetActiveMemberCount(tm.TeamId); membersCount.Err != nil {
return nil, false, membersCount.Err
} else if membersCount.Data.(int64) >= int64(*a.Config().TeamSettings.MaxUsersPerTeam) {
return nil, false, model.NewAppError("joinUserToTeam", "app.team.join_user_to_team.max_accounts.app_error", nil, "teamId="+tm.TeamId, http.StatusBadRequest)
} else {
return tmr.Data.(*model.TeamMember), false, nil
if tmr := <-a.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
return nil, false, tmr.Err
} else {
return tmr.Data.(*model.TeamMember), false, nil
}
}
} else {
// Membership appears to be missing. Lets try to add.
......
......@@ -460,3 +460,92 @@ func TestAddUserToTeamByHashMismatchedInviteId(t *testing.T) {
assert.Nil(t, team)
assert.Equal(t, "api.user.create_user.signup_link_mismatched_invite_id.app_error", err.Id)
}
func TestJoinUserToTeam(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
id := model.NewId()
team := &model.Team{
DisplayName: "dn_" + id,
Name: "name" + id,
Email: "success+" + id + "@simulator.amazonses.com",
Type: model.TEAM_OPEN,
}
if _, err := th.App.CreateTeam(team); err != nil {
t.Log(err)
t.Fatal("Should create a new team")
}
maxUsersPerTeam := th.App.Config().TeamSettings.MaxUsersPerTeam
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = maxUsersPerTeam })
th.App.SetDefaultRolesBasedOnConfig()
th.App.PermanentDeleteTeam(team)
}()
one := 1
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = &one })
t.Run("new join", func(t *testing.T) {
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser, _ := th.App.CreateUser(&user)
defer th.App.PermanentDeleteUser(&user)
if _, alreadyAdded, err := th.App.joinUserToTeam(team, ruser); alreadyAdded || err != nil {
t.Fatal("Should return already added equal to false and no error")
}
})
t.Run("join when you are a member", func(t *testing.T) {
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser, _ := th.App.CreateUser(&user)
defer th.App.PermanentDeleteUser(&user)
th.App.joinUserToTeam(team, ruser)
if _, alreadyAdded, err := th.App.joinUserToTeam(team, ruser); !alreadyAdded || err != nil {
t.Fatal("Should return already added and no error")
}
})
t.Run("re-join after leaving", func(t *testing.T) {
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser, _ := th.App.CreateUser(&user)
defer th.App.PermanentDeleteUser(&user)
th.App.joinUserToTeam(team, ruser)
th.App.LeaveTeam(team, ruser, ruser.Id)
if _, alreadyAdded, err := th.App.joinUserToTeam(team, ruser); alreadyAdded || err != nil {
t.Fatal("Should return already added equal to false and no error")
}
})
t.Run("new join with limit problem", func(t *testing.T) {
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser1, _ := th.App.CreateUser(&user1)
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser2, _ := th.App.CreateUser(&user2)
defer th.App.PermanentDeleteUser(&user1)
defer th.App.PermanentDeleteUser(&user2)
th.App.joinUserToTeam(team, ruser1)
if _, _, err := th.App.joinUserToTeam(team, ruser2); err == nil {
t.Fatal("Should fail")
}
})
t.Run("re-join alfter leaving with limit problem", func(t *testing.T) {
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser1, _ := th.App.CreateUser(&user1)
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser2, _ := th.App.CreateUser(&user2)
defer th.App.PermanentDeleteUser(&user1)
defer th.App.PermanentDeleteUser(&user2)
th.App.joinUserToTeam(team, ruser1)
th.App.LeaveTeam(team, ruser1, ruser1.Id)
th.App.joinUserToTeam(team, ruser2)
if _, _, err := th.App.joinUserToTeam(team, ruser1); err == nil {
t.Fatal("Should fail")
}
})
}
......@@ -3126,6 +3126,10 @@
"id": "api.websocket_handler.invalid_param.app_error",
"translation": "Invalid {{.Name}} parameter"
},
{
"id": "app.team.join_user_to_team.max_accounts.app_error",
"translation": "This team has reached the maximum number of allowed accounts. Contact your systems administrator to set a higher limit."
},
{
"id": "app.channel.create_channel.no_team_id.app_error",
"translation": "Must specify the team ID to create a channel"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment