* allow reference group changes
Этот коммит содержится в:
Ben Cooke
2025-03-31 15:49:55 -04:00
коммит произвёл GitHub
родитель 7e439a7f7e
Коммит ce9632cca3
10 изменённых файлов: 441 добавлений и 123 удалений

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

@@ -5397,11 +5397,11 @@ func (s *RetryLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.
}
func (s *RetryLayerGroupStore) GetByUser(userID string) ([]*model.Group, error) {
func (s *RetryLayerGroupStore) GetByUser(userID string, opts model.GroupSearchOpts) ([]*model.Group, error) {
tries := 0
for {
result, err := s.GroupStore.GetByUser(userID)
result, err := s.GroupStore.GetByUser(userID, opts)
if err == nil {
return result, nil
}

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

@@ -301,7 +301,7 @@ func (s *SqlGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.
return groups, nil
}
func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, error) {
func (s *SqlGroupStore) GetByUser(userID string, opts model.GroupSearchOpts) ([]*model.Group, error) {
groups := []*model.Group{}
builder := s.getQueryBuilder().
@@ -310,11 +310,15 @@ func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, error) {
Join("UserGroups ON UserGroups.Id = GroupMembers.GroupId").
Where(sq.Eq{
"GroupMembers.DeleteAt": 0,
"UserId": userId,
"UserId": userID,
})
if opts.FilterAllowReference {
builder = builder.Where("UserGroups.AllowReference = true")
}
if err := s.GetReplica().SelectBuilder(&groups, builder); err != nil {
return nil, errors.Wrapf(err, "failed to find Groups with userId=%s", userId)
return nil, errors.Wrapf(err, "failed to find Groups with userId=%s", userID)
}
return groups, nil

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

@@ -882,7 +882,7 @@ type GroupStore interface {
GetByIDs(groupIDs []string) ([]*model.Group, error)
GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, error)
GetAllBySource(groupSource model.GroupSource) ([]*model.Group, error)
GetByUser(userID string) ([]*model.Group, error)
GetByUser(userID string, opts model.GroupSearchOpts) ([]*model.Group, error)
Update(group *model.Group) (*model.Group, error)
Delete(groupID string) (*model.Group, error)
Restore(groupID string) (*model.Group, error)

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

@@ -545,11 +545,12 @@ func testGroupStoreGetByUser(t *testing.T, rctx request.CTX, ss store.Store) {
require.NoError(t, err)
g2 := &model.Group{
Name: model.NewPointer(model.NewId()),
DisplayName: model.NewId(),
Description: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewPointer(model.NewId()),
Name: model.NewPointer(model.NewId()),
DisplayName: model.NewId(),
Description: model.NewId(),
Source: model.GroupSourceLdap,
RemoteId: model.NewPointer(model.NewId()),
AllowReference: true,
}
g2, err = ss.Group().Create(g2)
require.NoError(t, err)
@@ -576,7 +577,7 @@ func testGroupStoreGetByUser(t *testing.T, rctx request.CTX, ss store.Store) {
_, err = ss.Group().UpsertMember(g2.Id, u2.Id)
require.NoError(t, err)
groups, err := ss.Group().GetByUser(u1.Id)
groups, err := ss.Group().GetByUser(u1.Id, model.GroupSearchOpts{})
require.NoError(t, err)
assert.Equal(t, 2, len(groups))
found1 := false
@@ -592,14 +593,19 @@ func testGroupStoreGetByUser(t *testing.T, rctx request.CTX, ss store.Store) {
assert.True(t, found1)
assert.True(t, found2)
groups, err = ss.Group().GetByUser(u2.Id)
groups, err = ss.Group().GetByUser(u2.Id, model.GroupSearchOpts{})
require.NoError(t, err)
require.Equal(t, 1, len(groups))
assert.Equal(t, g2.Id, groups[0].Id)
groups, err = ss.Group().GetByUser(model.NewId())
groups, err = ss.Group().GetByUser(model.NewId(), model.GroupSearchOpts{})
require.NoError(t, err)
assert.Equal(t, 0, len(groups))
groups, err = ss.Group().GetByUser(u1.Id, model.GroupSearchOpts{FilterAllowReference: true})
require.NoError(t, err)
assert.Equal(t, 1, len(groups))
assert.Equal(t, g2.Id, groups[0].Id)
}
func testGroupStoreUpdate(t *testing.T, rctx request.CTX, ss store.Store) {

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

@@ -692,9 +692,9 @@ func (_m *GroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSour
return r0, r1
}
// GetByUser provides a mock function with given fields: userID
func (_m *GroupStore) GetByUser(userID string) ([]*model.Group, error) {
ret := _m.Called(userID)
// GetByUser provides a mock function with given fields: userID, opts
func (_m *GroupStore) GetByUser(userID string, opts model.GroupSearchOpts) ([]*model.Group, error) {
ret := _m.Called(userID, opts)
if len(ret) == 0 {
panic("no return value specified for GetByUser")
@@ -702,19 +702,19 @@ func (_m *GroupStore) GetByUser(userID string) ([]*model.Group, error) {
var r0 []*model.Group
var r1 error
if rf, ok := ret.Get(0).(func(string) ([]*model.Group, error)); ok {
return rf(userID)
if rf, ok := ret.Get(0).(func(string, model.GroupSearchOpts) ([]*model.Group, error)); ok {
return rf(userID, opts)
}
if rf, ok := ret.Get(0).(func(string) []*model.Group); ok {
r0 = rf(userID)
if rf, ok := ret.Get(0).(func(string, model.GroupSearchOpts) []*model.Group); ok {
r0 = rf(userID, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Group)
}
}
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(userID)
if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) error); ok {
r1 = rf(userID, opts)
} else {
r1 = ret.Error(1)
}

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

@@ -4355,10 +4355,10 @@ func (s *TimerLayerGroupStore) GetByRemoteID(remoteID string, groupSource model.
return result, err
}
func (s *TimerLayerGroupStore) GetByUser(userID string) ([]*model.Group, error) {
func (s *TimerLayerGroupStore) GetByUser(userID string, opts model.GroupSearchOpts) ([]*model.Group, error) {
start := time.Now()
result, err := s.GroupStore.GetByUser(userID)
result, err := s.GroupStore.GetByUser(userID, opts)
elapsed := float64(time.Since(start)) / float64(time.Second)
if s.Root.Metrics != nil {