* WIP

* adding initial creategroup endpoint

* fetching by group source

* fixing startup error

* updating create endpoint to take an array of user_ids, this will allow us to create the group with one request

* adding delete group endpoint and appropriate test

* adding source param for getGroups

* adding add members and delete members endpoints

* locking down crud endpoints to only be allowed for custom groups

* user search stuff

* allowing remoteid be null by changing field to pointer

* code cleanup and store level tests

* adding new tests and removing unused endpoint

* resolving conflicts

* Adds authz check for group.

* Adds authz checks to groups APIs.

* Updated create group authz tests.

* Updates delete group tests.

* Tests create group.

* Adds some tests and validations.

* adding new parameter so I can get users not in a group

* Fixed all lint warnings.

* Fix type.

* fixing search users not in group

* Fixes some lint errors.

* Moves entry in JSON array.

* Fixed SQL query.

* Fixes permission migration test.

* Fixes migration test.

* Fixes some group store tests.

* Fix test.

* Fix test.

* Revert lint change.

* Migrated CreateWithUserIds to sqlx.

* Adds tests for GetMember; migrates implementation to sqlx.

* Tests GetNonMemberUsersPage and hanles wrong group id.

* Fixes test.

* Switches GetMaster to GetMasterX.

* Switches GetReplica to GetReplicaX.

* Fixes logic.

* Fixes shadow declaration.

* Adds include_member_count to get group API endpoint.

* Adds filter_has_member param to getGroups.

* Fixes.

* Removes array of group sources.

* fixing error

* Testing reverting CreateWithUserIds back to gorp.

* Added websocket event for CreateGroupWithUserIds.

* Changed a few response status codes. Switched to correct permission.

* Added member count to ws payload for group when updating or creating.

* Adds feature flag checks for custom groups.

* Added middleware function to require license. Added config to disable custom groups.

* Change for function signature change of executePossiblyEmptyQuery.

* Lint fixes.

* Adds telemetry none comment.

* Adds translations.

* Migrated to sqlx.

* Temp. removal of translation.

* Fixed typo.

* Added an intermediary model to query with a field that is now ignored by sqlx on read queries.

* Re-used existing store struct.

* Inludes member count.

* Fix for merge error.'

* Require license for group endpoints.

* Updates translations.

* Fix shadow declaration.

* Renames permissions. Switches to new method to retrieve remoteid.

* Added WS events for upsert and delete member(s).

* Added new store error type ErrUniqueConstraint.

* Added EnableCustonGroups to the client config.

* Sanitized some user records.

* Added parameter to include_total_count for listing groups.

* Added translations.

* adding deleteAt field to getByUsers query

* Revert sanitize.

* Added uniqueness constraint error to UpdateGroup.

* Removed the FutureFeatures flag so that the feature is not enabled on old Enterprise licenses.

* Renamed function.

* Updates authz check for user search related to groups.

* Removed debug statement.

* Removed unused app method.

* Added telemetry for enable_custom_groups.

* Returns early from nil license.

* Updates test.

* Returned early to avoid nesting in (*SqlGroupStore).checkUserExist. Switched to reading from replica in (*SqlGroupStore).GetMember. Handled JSON marshal error in (*Client4).UpsertGroupMembers

* Switched to SanitizeProfile.

* Switched to model.NewInt.

* Switched from status NotImplemented to Forbidden for missing license.

* Removed deactivated users from 'exists' set.

* Revert gotool update.

* Ignored lint error that I think is invalid.

* Added the approprate access tag for disabling custom groups.

* Revert change to response status.

* Fixed refactor mistake.

* Limited the group member WS events to individual users.

* Removed WS event of deleted groups.

* Updated license check for searchUsers endpoint.

* Switched from license feature to license sku.

* Update app/group.go

Co-authored-by: Claudio Costa <cstcld91@gmail.com>

* Update app/group.go

Co-authored-by: Claudio Costa <cstcld91@gmail.com>

* Remove linter ignore comment.

* Added function to create sku-specific license.

* Fixed typo. Removed comment.

* Fixed for wrong type.

* Added missing param to client. Removed unnecessary props setting. Added test for retrieving groups by source.

* Updated some tests now that we're validating group membership not created for deactivated user.

* Fix for groups endpoint returning all group types by default.

* Changes constant names. Adds migration for all users to manage custom group members.

* Removes requirement for manage_system permission to filter user search by group.

* Added migration mock.

* Removes default permissions from custom_group_user role.

* Fixes migration.

* Fixes emoji migration test.

* fixing issue with member counts

* fixing search issue for deleted members

Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MBP.ht.home>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.fritz.box>
Co-authored-by: Claudio Costa <cstcld91@gmail.com>
Этот коммит содержится в:
mkraft
2022-02-17 12:34:39 -05:00
коммит произвёл GitHub
родитель 7f1d074d85
Коммит 7fa6b321ae
58 изменённых файлов: 3834 добавлений и 314 удалений

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

@@ -3718,7 +3718,7 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlStore) {
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(group)
require.NoError(t, err)
@@ -5044,7 +5044,7 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err := ss.Group().Create(g1)
require.NoError(t, err)
@@ -5116,7 +5116,7 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(g2)
require.NoError(t, err)
@@ -5155,7 +5155,7 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(g3)
@@ -6146,7 +6146,7 @@ func testChannelStoreSearchAllChannels(t *testing.T, ss store.Store) {
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(group)
require.NoError(t, err)

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@@ -236,6 +236,29 @@ func (_m *GroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*
return r0, r1
}
// CreateWithUserIds provides a mock function with given fields: group
func (_m *GroupStore) CreateWithUserIds(group *model.GroupWithUserIds) (*model.Group, error) {
ret := _m.Called(group)
var r0 *model.Group
if rf, ok := ret.Get(0).(func(*model.GroupWithUserIds) *model.Group); ok {
r0 = rf(group)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Group)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(*model.GroupWithUserIds) error); ok {
r1 = rf(group)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: groupID
func (_m *GroupStore) Delete(groupID string) (*model.Group, error) {
ret := _m.Called(groupID)
@@ -305,6 +328,29 @@ func (_m *GroupStore) DeleteMember(groupID string, userID string) (*model.GroupM
return r0, r1
}
// DeleteMembers provides a mock function with given fields: groupID, userIDs
func (_m *GroupStore) DeleteMembers(groupID string, userIDs []string) ([]*model.GroupMember, error) {
ret := _m.Called(groupID, userIDs)
var r0 []*model.GroupMember
if rf, ok := ret.Get(0).(func(string, []string) []*model.GroupMember); ok {
r0 = rf(groupID, userIDs)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.GroupMember)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, []string) error); ok {
r1 = rf(groupID, userIDs)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// DistinctGroupMemberCount provides a mock function with given fields:
func (_m *GroupStore) DistinctGroupMemberCount() (int64, error) {
ret := _m.Called()
@@ -602,6 +648,29 @@ func (_m *GroupStore) GetGroupsByTeam(teamID string, opts model.GroupSearchOpts)
return r0, r1
}
// GetMember provides a mock function with given fields: groupID, userID
func (_m *GroupStore) GetMember(groupID string, userID string) (*model.GroupMember, error) {
ret := _m.Called(groupID, userID)
var r0 *model.GroupMember
if rf, ok := ret.Get(0).(func(string, string) *model.GroupMember); ok {
r0 = rf(groupID, userID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.GroupMember)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(groupID, userID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetMemberCount provides a mock function with given fields: groupID
func (_m *GroupStore) GetMemberCount(groupID string) (int64, error) {
ret := _m.Called(groupID)
@@ -715,6 +784,29 @@ func (_m *GroupStore) GetMemberUsersPage(groupID string, page int, perPage int)
return r0, r1
}
// GetNonMemberUsersPage provides a mock function with given fields: groupID, page, perPage
func (_m *GroupStore) GetNonMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, error) {
ret := _m.Called(groupID, page, perPage)
var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
r0 = rf(groupID, page, perPage)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.User)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
r1 = rf(groupID, page, perPage)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GroupChannelCount provides a mock function with given fields:
func (_m *GroupStore) GroupChannelCount() (int64, error) {
ret := _m.Called()
@@ -994,3 +1086,26 @@ func (_m *GroupStore) UpsertMember(groupID string, userID string) (*model.GroupM
return r0, r1
}
// UpsertMembers provides a mock function with given fields: groupID, userIDs
func (_m *GroupStore) UpsertMembers(groupID string, userIDs []string) ([]*model.GroupMember, error) {
ret := _m.Called(groupID, userIDs)
var r0 []*model.GroupMember
if rf, ok := ret.Get(0).(func(string, []string) []*model.GroupMember); ok {
r0 = rf(groupID, userIDs)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.GroupMember)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, []string) error); ok {
r1 = rf(groupID, userIDs)
} else {
r1 = ret.Error(1)
}
return r0, r1
}

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

@@ -1274,6 +1274,29 @@ func (_m *UserStore) SearchNotInChannel(teamID string, channelID string, term st
return r0, r1
}
// SearchNotInGroup provides a mock function with given fields: groupID, term, options
func (_m *UserStore) SearchNotInGroup(groupID string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
ret := _m.Called(groupID, term, options)
var r0 []*model.User
if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) []*model.User); ok {
r0 = rf(groupID, term, options)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.User)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, string, *model.UserSearchOptions) error); ok {
r1 = rf(groupID, term, options)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// SearchNotInTeam provides a mock function with given fields: notInTeamID, term, options
func (_m *UserStore) SearchNotInTeam(notInTeamID string, term string, options *model.UserSearchOptions) ([]*model.User, error) {
ret := _m.Called(notInTeamID, term, options)

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

@@ -625,12 +625,6 @@ func testTeamStoreGetByInviteId(t *testing.T, ss store.Store) {
save1, err := ss.Team().Save(&o1)
require.NoError(t, err)
o2 := model.Team{}
o2.DisplayName = "DisplayName"
o2.Name = NewTestId()
o2.Email = MakeEmail()
o2.Type = model.TeamOpen
r1, err := ss.Team().GetByInviteId(save1.InviteId)
require.NoError(t, err)
require.Equal(t, *r1, o1, "invalid returned team")

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

@@ -80,6 +80,7 @@ func TestUserStore(t *testing.T, ss store.Store, s SqlStore) {
t.Run("SearchNotInTeam", func(t *testing.T) { testUserStoreSearchNotInTeam(t, ss) })
t.Run("SearchWithoutTeam", func(t *testing.T) { testUserStoreSearchWithoutTeam(t, ss) })
t.Run("SearchInGroup", func(t *testing.T) { testUserStoreSearchInGroup(t, ss) })
t.Run("SearchNotInGroup", func(t *testing.T) { testUserStoreSearchNotInGroup(t, ss) })
t.Run("GetProfilesNotInTeam", func(t *testing.T) { testUserStoreGetProfilesNotInTeam(t, ss) })
t.Run("ClearAllCustomRoleAssignments", func(t *testing.T) { testUserStoreClearAllCustomRoleAssignments(t, ss) })
t.Run("GetAllAfter", func(t *testing.T) { testUserStoreGetAllAfter(t, ss) })
@@ -1467,7 +1468,7 @@ func testUserStoreGetProfilesNotInChannel(t *testing.T, ss store.Store) {
Name: model.NewString("n_" + model.NewId()),
DisplayName: "dn_" + model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: "ri_" + model.NewId(),
RemoteId: model.NewString("ri_" + model.NewId()),
})
require.NoError(t, err)
@@ -3489,7 +3490,6 @@ func testUserStoreSearchInGroup(t *testing.T, ss store.Store) {
u3 := &model.User{
Username: "jimbo3" + model.NewId(),
Email: MakeEmail(),
DeleteAt: 1,
}
_, err = ss.User().Save(u3)
require.NoError(t, err)
@@ -3507,7 +3507,7 @@ func testUserStoreSearchInGroup(t *testing.T, ss store.Store) {
DisplayName: model.NewId(),
Description: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(g1)
require.NoError(t, err)
@@ -3517,7 +3517,7 @@ func testUserStoreSearchInGroup(t *testing.T, ss store.Store) {
DisplayName: model.NewId(),
Description: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewId(),
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(g2)
require.NoError(t, err)
@@ -3531,6 +3531,10 @@ func testUserStoreSearchInGroup(t *testing.T, ss store.Store) {
_, err = ss.Group().UpsertMember(g1.Id, u3.Id)
require.NoError(t, err)
u3.DeleteAt = 1
_, err = ss.User().Update(u3, true)
require.NoError(t, err)
testCases := []struct {
Description string
GroupId string
@@ -3606,6 +3610,138 @@ func testUserStoreSearchInGroup(t *testing.T, ss store.Store) {
}
}
func testUserStoreSearchNotInGroup(t *testing.T, ss store.Store) {
u1 := &model.User{
Username: "jimbo1" + model.NewId(),
FirstName: "Tim",
LastName: "Bill",
Nickname: "Rob",
Email: "harold" + model.NewId() + "@simulator.amazonses.com",
}
_, err := ss.User().Save(u1)
require.NoError(t, err)
defer func() { require.NoError(t, ss.User().PermanentDelete(u1.Id)) }()
u2 := &model.User{
Username: "jim-bobby" + model.NewId(),
Email: MakeEmail(),
}
_, err = ss.User().Save(u2)
require.NoError(t, err)
defer func() { require.NoError(t, ss.User().PermanentDelete(u2.Id)) }()
u3 := &model.User{
Username: "jimbo3" + model.NewId(),
Email: MakeEmail(),
}
_, err = ss.User().Save(u3)
require.NoError(t, err)
defer func() { require.NoError(t, ss.User().PermanentDelete(u3.Id)) }()
// The users returned from the database will have AuthData as an empty string.
nilAuthData := model.NewString("")
u1.AuthData = nilAuthData
u2.AuthData = nilAuthData
u3.AuthData = nilAuthData
g1 := &model.Group{
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Description: model.NewId(),
Source: model.GroupSourceCustom,
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(g1)
require.NoError(t, err)
g2 := &model.Group{
Name: model.NewString(model.NewId()),
DisplayName: model.NewId(),
Description: model.NewId(),
Source: model.GroupSourceCustom,
RemoteId: model.NewString(model.NewId()),
}
_, err = ss.Group().Create(g2)
require.NoError(t, err)
_, err = ss.Group().UpsertMember(g1.Id, u1.Id)
require.NoError(t, err)
_, err = ss.Group().UpsertMember(g2.Id, u2.Id)
require.NoError(t, err)
_, err = ss.Group().UpsertMember(g1.Id, u3.Id)
require.NoError(t, err)
u3.DeleteAt = 1
_, err = ss.User().Update(u3, true)
require.NoError(t, err)
testCases := []struct {
Description string
GroupId string
Term string
Options *model.UserSearchOptions
Expected []*model.User
}{
{
"search jimb, not in group 1",
g1.Id,
"jimb",
&model.UserSearchOptions{
AllowFullNames: true,
Limit: model.UserSearchDefaultLimit,
},
[]*model.User{},
},
{
"search jim, not in group 1",
g1.Id,
"jim",
&model.UserSearchOptions{
AllowFullNames: true,
Limit: model.UserSearchDefaultLimit,
},
[]*model.User{u2},
},
{
"search jimb, not in group 3, allow inactive",
g2.Id,
"jimb",
&model.UserSearchOptions{
AllowFullNames: true,
AllowInactive: true,
Limit: model.UserSearchDefaultLimit,
},
[]*model.User{u1, u3},
},
{
"search jim, not in group 2",
g2.Id,
"jimb",
&model.UserSearchOptions{
AllowFullNames: true,
AllowInactive: true,
Limit: model.UserSearchDefaultLimit,
},
[]*model.User{u1, u3},
},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
users, err := ss.User().SearchNotInGroup(
testCase.GroupId,
testCase.Term,
testCase.Options,
)
require.NoError(t, err)
assertUsers(t, testCase.Expected, users)
})
}
}
func testCount(t *testing.T, ss store.Store) {
// Regular
teamId := model.NewId()
@@ -4362,7 +4498,7 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
Name: model.NewString("n_" + model.NewId()),
DisplayName: "dn_" + model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: "ri_" + model.NewId(),
RemoteId: model.NewString("ri_" + model.NewId()),
})
require.NoError(t, err)
@@ -4679,7 +4815,7 @@ func testUserStoreGetTeamGroupUsers(t *testing.T, ss store.Store) {
Name: model.NewString("n_" + id),
DisplayName: "dn_" + id,
Source: model.GroupSourceLdap,
RemoteId: "ri_" + id,
RemoteId: model.NewString("ri_" + id),
})
require.NoError(t, err)
require.NotNil(t, group)
@@ -4800,7 +4936,7 @@ func testUserStoreGetChannelGroupUsers(t *testing.T, ss store.Store) {
Name: model.NewString("n_" + id),
DisplayName: "dn_" + id,
Source: model.GroupSourceLdap,
RemoteId: "ri_" + id,
RemoteId: model.NewString("ri_" + id),
})
require.NoError(t, err)
require.NotNil(t, group)