MM-14753: Verifies that user can join teams and channels in spite of group constraints. (#10529)

* MM-147753: Verifies that users are allowed to be members of a team or a channel, based on group constraints, prior to allowing the API to add them.

* MM-14753: Allow methods to return meaningful results for deleted teams or channels.

* MM-14753: Renames methods to differentiate from permissions and other team and channel restrictions.

* MM-14753: Only check if users are team/channel members if team/channel is group constrained.

* MM-14753: Updates test function names.

* MM-14753: Changes a few method signatures.

* MM-14753: Small refactor and adds missing returns.

* MM-14753: Changes method names from Get* to Filter* name prefixes.

* MM-14753: Renames error variables.

* MM-14753: Updates method names for consistency with join table names.

* MM-14753: Adds case for non AppError return.

* Update i18n/en.json
Этот коммит содержится в:
Martin Kraft
2019-04-09 07:09:57 -04:00
коммит произвёл GitHub
родитель 43fa7e0548
Коммит 7bde0378cd
11 изменённых файлов: 629 добавлений и 2 удалений

Просмотреть файл

@@ -1442,6 +1442,30 @@ func TestAddTeamMember(t *testing.T) {
if tm != nil {
t.Fatal("should have not returned team member")
}
// Set a team to group-constrained
team.GroupConstrained = model.NewBool(true)
_, err := th.App.UpdateTeam(team)
require.Nil(t, err)
// User is not in associated groups so shouldn't be allowed
_, resp = th.SystemAdminClient.AddTeamMember(team.Id, otherUser.Id)
CheckErrorMessage(t, resp, "api.team.add_members.user_denied")
// Associate group to team
_, err = th.App.CreateGroupSyncable(&model.GroupSyncable{
GroupId: th.Group.Id,
SyncableId: team.Id,
Type: model.GroupSyncableTypeTeam,
})
require.Nil(t, err)
// Add user to group
_, err = th.App.CreateOrRestoreGroupMember(th.Group.Id, otherUser.Id)
require.Nil(t, err)
_, resp = th.SystemAdminClient.AddTeamMember(team.Id, otherUser.Id)
CheckNoError(t, resp)
}
func TestAddTeamMemberMyself(t *testing.T) {
@@ -1578,7 +1602,7 @@ func TestAddTeamMembers(t *testing.T) {
CheckBadRequestStatus(t, resp)
_, resp = Client.AddTeamMembers(GenerateTestId(), userList)
CheckForbiddenStatus(t, resp)
CheckNotFoundStatus(t, resp)
testUserList := append(userList, GenerateTestId())
_, resp = Client.AddTeamMembers(team.Id, testUserList)
@@ -1633,6 +1657,30 @@ func TestAddTeamMembers(t *testing.T) {
// Should work as a regular user.
_, resp = Client.AddTeamMembers(team.Id, userList)
CheckNoError(t, resp)
// Set a team to group-constrained
team.GroupConstrained = model.NewBool(true)
_, err := th.App.UpdateTeam(team)
require.Nil(t, err)
// User is not in associated groups so shouldn't be allowed
_, resp = Client.AddTeamMembers(team.Id, userList)
CheckErrorMessage(t, resp, "api.team.add_members.user_denied")
// Associate group to team
_, err = th.App.CreateGroupSyncable(&model.GroupSyncable{
GroupId: th.Group.Id,
SyncableId: team.Id,
Type: model.GroupSyncableTypeTeam,
})
require.Nil(t, err)
// Add user to group
_, err = th.App.CreateOrRestoreGroupMember(th.Group.Id, userList[0])
require.Nil(t, err)
_, resp = Client.AddTeamMembers(team.Id, userList)
CheckNoError(t, resp)
}
func TestRemoveTeamMember(t *testing.T) {