MM-23015: Enable or disable group mentions (#14010)
* MM-23015: Enable or disable group mentions + show them in suggestion list Co-authored-by: Catalin Tomai <catalin.tomai@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0bfb063c78
Коммит
b90f4f46e2
@@ -909,6 +909,77 @@ func (s *SqlGroupStore) groupsBySyncableBaseQuery(st model.GroupSyncableType, t
|
||||
OrderBy("ug.DisplayName")
|
||||
}
|
||||
|
||||
if opts.FilterAllowReference && t == selectGroups {
|
||||
query = query.Where("ug.AllowReference = true")
|
||||
}
|
||||
|
||||
if len(opts.Q) > 0 {
|
||||
pattern := fmt.Sprintf("%%%s%%", sanitizeSearchTerm(opts.Q, "\\"))
|
||||
operatorKeyword := "ILIKE"
|
||||
if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
operatorKeyword = "LIKE"
|
||||
}
|
||||
query = query.Where(fmt.Sprintf("(ug.Name %[1]s ? OR ug.DisplayName %[1]s ?)", operatorKeyword), pattern, pattern)
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncableType, teamID string, opts model.GroupSearchOpts) sq.SelectBuilder {
|
||||
query := s.getQueryBuilder().
|
||||
Select("gc.ChannelId, ug.*, gc.SchemeAdmin AS SyncableSchemeAdmin").
|
||||
From("UserGroups ug").
|
||||
LeftJoin(fmt.Sprintf(`(
|
||||
SELECT
|
||||
GroupChannels.GroupId, GroupChannels.ChannelId, GroupChannels.DeleteAt, GroupChannels.SchemeAdmin
|
||||
FROM
|
||||
GroupChannels
|
||||
LEFT JOIN
|
||||
Channels ON (Channels.Id = GroupChannels.ChannelId)
|
||||
WHERE
|
||||
GroupChannels.DeleteAt = 0
|
||||
AND Channels.DeleteAt = 0
|
||||
AND Channels.TeamId = ?) AS gc
|
||||
ON gc.GroupId = ug.Id`), teamID).
|
||||
Where("ug.DeleteAt = 0 AND gc.DeleteAt = 0").
|
||||
OrderBy("ug.DisplayName")
|
||||
|
||||
if opts.IncludeMemberCount {
|
||||
query = s.getQueryBuilder().
|
||||
Select("gc.ChannelId, ug.*, coalesce(Members.MemberCount, 0) AS MemberCount, gc.SchemeAdmin AS SyncableSchemeAdmin").
|
||||
From("UserGroups ug").
|
||||
LeftJoin(fmt.Sprintf(`(
|
||||
SELECT
|
||||
GroupChannels.ChannelId, GroupChannels.DeleteAt, GroupChannels.GroupId, GroupChannels.SchemeAdmin
|
||||
FROM
|
||||
GroupChannels
|
||||
LEFT JOIN
|
||||
Channels ON (Channels.Id = GroupChannels.ChannelId)
|
||||
WHERE
|
||||
GroupChannels.DeleteAt = 0
|
||||
AND Channels.DeleteAt = 0
|
||||
AND Channels.TeamId = ?) AS gc
|
||||
ON gc.GroupId = ug.Id`), teamID).
|
||||
LeftJoin(`(
|
||||
SELECT
|
||||
GroupMembers.GroupId, COUNT(*) AS MemberCount
|
||||
FROM
|
||||
GroupMembers
|
||||
LEFT JOIN
|
||||
Users ON Users.Id = GroupMembers.UserId
|
||||
WHERE
|
||||
GroupMembers.DeleteAt = 0
|
||||
AND Users.DeleteAt = 0
|
||||
GROUP BY GroupId) AS Members
|
||||
ON Members.GroupId = ug.Id`).
|
||||
Where("ug.DeleteAt = 0 AND gc.DeleteAt = 0").
|
||||
OrderBy("ug.DisplayName")
|
||||
}
|
||||
|
||||
if opts.FilterAllowReference {
|
||||
query = query.Where("ug.AllowReference = true")
|
||||
}
|
||||
|
||||
if len(opts.Q) > 0 {
|
||||
pattern := fmt.Sprintf("%%%s%%", sanitizeSearchTerm(opts.Q, "\\"))
|
||||
operatorKeyword := "ILIKE"
|
||||
@@ -960,6 +1031,42 @@ func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpt
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) {
|
||||
query := s.getGroupsAssociatedToChannelsByTeam(model.GroupSyncableTypeTeam, teamId, opts)
|
||||
|
||||
if opts.PageOpts != nil {
|
||||
offset := uint64(opts.PageOpts.Page * opts.PageOpts.PerPage)
|
||||
query = query.OrderBy("ug.DisplayName").Limit(uint64(opts.PageOpts.PerPage)).Offset(offset)
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GetGroupsAssociatedToChannelsByTeam", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var tgroups []*model.GroupsAssociatedToChannelWithSchemeAdmin
|
||||
|
||||
_, err = s.GetReplica().Select(&tgroups, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GetGroupsAssociatedToChannelsByTeam", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
groups := map[string][]*model.GroupWithSchemeAdmin{}
|
||||
for _, tgroup := range tgroups {
|
||||
var group = model.GroupWithSchemeAdmin{}
|
||||
group.Group = tgroup.Group
|
||||
group.SchemeAdmin = tgroup.SchemeAdmin
|
||||
|
||||
if val, ok := groups[tgroup.ChannelId]; ok {
|
||||
groups[tgroup.ChannelId] = append(val, &group)
|
||||
} else {
|
||||
groups[tgroup.ChannelId] = []*model.GroupWithSchemeAdmin{&group}
|
||||
}
|
||||
}
|
||||
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) {
|
||||
var groups []*model.Group
|
||||
|
||||
@@ -978,6 +1085,10 @@ func (s *SqlGroupStore) GetGroups(page, perPage int, opts model.GroupSearchOpts)
|
||||
Offset(uint64(page * perPage)).
|
||||
OrderBy("g.DisplayName")
|
||||
|
||||
if opts.FilterAllowReference {
|
||||
groupsQuery = groupsQuery.Where("g.AllowReference = true")
|
||||
}
|
||||
|
||||
if len(opts.Q) > 0 {
|
||||
pattern := fmt.Sprintf("%%%s%%", sanitizeSearchTerm(opts.Q, "\\"))
|
||||
operatorKeyword := "ILIKE"
|
||||
|
||||
@@ -176,7 +176,7 @@ func upgradeDatabase(sqlStore SqlStore, currentModelVersionString string) error
|
||||
upgradeDatabaseToVersion521(sqlStore)
|
||||
upgradeDatabaseToVersion522(sqlStore)
|
||||
upgradeDatabaseToVersion523(sqlStore)
|
||||
|
||||
upgradeDatabaseToVersion524(sqlStore)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -793,3 +793,13 @@ func upgradeDatabaseToVersion523(sqlStore SqlStore) {
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_23_0)
|
||||
// }
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion524(sqlStore SqlStore) {
|
||||
// TODO: uncomment when the time arrive to upgrade the DB for 5.24
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_23_0, VERSION_5_24_0) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("UserGroups", "AllowReference", "boolean", "boolean", "0")
|
||||
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_24_0)
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -661,6 +661,7 @@ type GroupStore interface {
|
||||
CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError)
|
||||
|
||||
GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError)
|
||||
GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError)
|
||||
CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError)
|
||||
|
||||
GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError)
|
||||
|
||||
@@ -55,6 +55,7 @@ func TestGroupStore(t *testing.T, ss store.Store) {
|
||||
t.Run("ChannelMembersToRemove_SingleChannel", func(t *testing.T) { testChannelMembersToRemoveSingleChannel(t, ss) })
|
||||
|
||||
t.Run("GetGroupsByChannel", func(t *testing.T) { testGetGroupsByChannel(t, ss) })
|
||||
t.Run("GetGroupsAssociatedToChannelsByTeam", func(t *testing.T) { testGetGroupsAssociatedToChannelsByTeam(t, ss) })
|
||||
t.Run("GetGroupsByTeam", func(t *testing.T) { testGetGroupsByTeam(t, ss) })
|
||||
|
||||
t.Run("GetGroups", func(t *testing.T) { testGetGroups(t, ss) })
|
||||
@@ -2055,27 +2056,30 @@ func testGetGroupsByChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create Groups 1, 2 and a deleted group
|
||||
group1, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
group2, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: false,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
deletedGroup, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
DeleteAt: 1,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
DeleteAt: 1,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -2102,10 +2106,11 @@ func testGetGroupsByChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create Group3
|
||||
group3, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -2242,6 +2247,14 @@ func testGetGroupsByChannel(t *testing.T, ss store.Store) {
|
||||
{Group: group2WithMemberCount, SchemeAdmin: model.NewBool(false)},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Include allow reference",
|
||||
ChannelId: channel1.Id,
|
||||
Opts: model.GroupSearchOpts{FilterAllowReference: true},
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Result: []*model.GroupWithSchemeAdmin{group1WSA},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
@@ -2264,6 +2277,249 @@ func testGetGroupsByChannel(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
func testGetGroupsAssociatedToChannelsByTeam(t *testing.T, ss store.Store) {
|
||||
// Create Team1
|
||||
team1 := &model.Team{
|
||||
DisplayName: "Team1",
|
||||
Description: model.NewId(),
|
||||
CompanyName: model.NewId(),
|
||||
AllowOpenInvite: false,
|
||||
InviteId: model.NewId(),
|
||||
Name: "zz" + model.NewId(),
|
||||
Email: "success+" + model.NewId() + "@simulator.amazonses.com",
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
team1, errt := ss.Team().Save(team1)
|
||||
require.Nil(t, errt)
|
||||
|
||||
// Create Channel1
|
||||
channel1 := &model.Channel{
|
||||
TeamId: team1.Id,
|
||||
DisplayName: "Channel1",
|
||||
Name: model.NewId(),
|
||||
Type: model.CHANNEL_OPEN,
|
||||
}
|
||||
channel1, err := ss.Channel().Save(channel1, 9999)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Create Groups 1, 2 and a deleted group
|
||||
group1, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: false,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
group2, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
deletedGroup, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
DeleteAt: 1,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// And associate them with Channel1
|
||||
for _, g := range []*model.Group{group1, group2, deletedGroup} {
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: channel1.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
GroupId: g.Id,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
// Create Channel2
|
||||
channel2 := &model.Channel{
|
||||
TeamId: team1.Id,
|
||||
DisplayName: "Channel2",
|
||||
Name: model.NewId(),
|
||||
Type: model.CHANNEL_OPEN,
|
||||
}
|
||||
channel2, err = ss.Channel().Save(channel2, 9999)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Create Group3
|
||||
group3, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// And associate it to Channel2
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: channel2.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
GroupId: group3.Id,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
// add members
|
||||
u1 := &model.User{
|
||||
Email: MakeEmail(),
|
||||
Username: model.NewId(),
|
||||
}
|
||||
user1, err := ss.User().Save(u1)
|
||||
require.Nil(t, err)
|
||||
|
||||
u2 := &model.User{
|
||||
Email: MakeEmail(),
|
||||
Username: model.NewId(),
|
||||
}
|
||||
user2, err := ss.User().Save(u2)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Group().UpsertMember(group1.Id, user1.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Group().UpsertMember(group1.Id, user2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
user2.DeleteAt = 1
|
||||
_, err = ss.User().Update(user2, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
group1WithMemberCount := *group1
|
||||
group1WithMemberCount.MemberCount = model.NewInt(1)
|
||||
|
||||
group2WithMemberCount := *group2
|
||||
group2WithMemberCount.MemberCount = model.NewInt(0)
|
||||
|
||||
group3WithMemberCount := *group3
|
||||
group3WithMemberCount.MemberCount = model.NewInt(0)
|
||||
|
||||
group1WSA := &model.GroupWithSchemeAdmin{Group: *group1, SchemeAdmin: model.NewBool(false)}
|
||||
group2WSA := &model.GroupWithSchemeAdmin{Group: *group2, SchemeAdmin: model.NewBool(false)}
|
||||
group3WSA := &model.GroupWithSchemeAdmin{Group: *group3, SchemeAdmin: model.NewBool(false)}
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
TeamId string
|
||||
Page int
|
||||
PerPage int
|
||||
Result map[string][]*model.GroupWithSchemeAdmin
|
||||
Opts model.GroupSearchOpts
|
||||
}{
|
||||
{
|
||||
Name: "Get the groups for Channel1 and Channel2",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{},
|
||||
Page: 0,
|
||||
PerPage: 60,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{channel1.Id: {group1WSA, group2WSA}, channel2.Id: {group3WSA}},
|
||||
},
|
||||
{
|
||||
Name: "Get first Group for Channel1 with page 0 with 1 element",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{},
|
||||
Page: 0,
|
||||
PerPage: 1,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{channel1.Id: {group1WSA}},
|
||||
},
|
||||
{
|
||||
Name: "Get second Group for Channel1 with page 1 with 1 element",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{},
|
||||
Page: 1,
|
||||
PerPage: 1,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{channel1.Id: {group2WSA}},
|
||||
},
|
||||
{
|
||||
Name: "Get empty Groups for a fake id",
|
||||
TeamId: model.NewId(),
|
||||
Opts: model.GroupSearchOpts{},
|
||||
Page: 0,
|
||||
PerPage: 60,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{},
|
||||
},
|
||||
{
|
||||
Name: "Get group matching name",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{Q: string([]rune(group1.Name)[2:10])}, // very low chance of a name collision
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{channel1.Id: {group1WSA}},
|
||||
},
|
||||
{
|
||||
Name: "Get group matching display name",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{Q: "rouP-1"},
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{channel1.Id: {group1WSA}},
|
||||
},
|
||||
{
|
||||
Name: "Get group matching multiple display names",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{Q: "roUp-"},
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{channel1.Id: {group1WSA, group2WSA}, channel2.Id: {group3WSA}},
|
||||
},
|
||||
{
|
||||
Name: "Include member counts",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{IncludeMemberCount: true},
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{
|
||||
channel1.Id: {
|
||||
{Group: group1WithMemberCount, SchemeAdmin: model.NewBool(false)},
|
||||
{Group: group2WithMemberCount, SchemeAdmin: model.NewBool(false)},
|
||||
},
|
||||
channel2.Id: {
|
||||
{Group: group3WithMemberCount, SchemeAdmin: model.NewBool(false)},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Include allow reference",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{FilterAllowReference: true},
|
||||
Page: 0,
|
||||
PerPage: 2,
|
||||
Result: map[string][]*model.GroupWithSchemeAdmin{
|
||||
channel1.Id: {
|
||||
group2WSA,
|
||||
},
|
||||
channel2.Id: {
|
||||
group3WSA,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
if tc.Opts.PageOpts == nil {
|
||||
tc.Opts.PageOpts = &model.PageOpts{}
|
||||
}
|
||||
tc.Opts.PageOpts.Page = tc.Page
|
||||
tc.Opts.PageOpts.PerPage = tc.PerPage
|
||||
groups, err := ss.Group().GetGroupsAssociatedToChannelsByTeam(tc.TeamId, tc.Opts)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, tc.Result, groups)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testGetGroupsByTeam(t *testing.T, ss store.Store) {
|
||||
// Create Team1
|
||||
team1 := &model.Team{
|
||||
@@ -2281,27 +2537,30 @@ func testGetGroupsByTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create Groups 1, 2 and a deleted group
|
||||
group1, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: false,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
group2, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
deletedGroup, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
DeleteAt: 1,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
DeleteAt: 1,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -2332,10 +2591,11 @@ func testGetGroupsByTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create Group3
|
||||
group3, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -2476,6 +2736,14 @@ func testGetGroupsByTeam(t *testing.T, ss store.Store) {
|
||||
{Group: group2WithMemberCount, SchemeAdmin: model.NewBool(false)},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Include allow reference",
|
||||
TeamId: team1.Id,
|
||||
Opts: model.GroupSearchOpts{FilterAllowReference: true},
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Result: []*model.GroupWithSchemeAdmin{group2WSA},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
@@ -2525,27 +2793,30 @@ func testGetGroups(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create Groups 1 and 2
|
||||
group1, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId(),
|
||||
DisplayName: "group-1",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
group2, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId() + "-group-2",
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId() + "-group-2",
|
||||
DisplayName: "group-2",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: false,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
deletedGroup, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId() + "-group-deleted",
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
DeleteAt: 1,
|
||||
Name: model.NewId() + "-group-deleted",
|
||||
DisplayName: "group-deleted",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: false,
|
||||
DeleteAt: 1,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -2586,10 +2857,11 @@ func testGetGroups(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create Group3
|
||||
group3, err := ss.Group().Create(&model.Group{
|
||||
Name: model.NewId() + "-group-3",
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
Name: model.NewId() + "-group-3",
|
||||
DisplayName: "group-3",
|
||||
RemoteId: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
AllowReference: true,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
@@ -2788,6 +3060,26 @@ func testGetGroups(t *testing.T, ss store.Store) {
|
||||
return true
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Include allow reference",
|
||||
Opts: model.GroupSearchOpts{FilterAllowReference: true},
|
||||
Page: 0,
|
||||
PerPage: 100,
|
||||
Resultf: func(groups []*model.Group) bool {
|
||||
if len(groups) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, g := range groups {
|
||||
if !g.AllowReference {
|
||||
return false
|
||||
}
|
||||
if g.DeleteAt != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -604,6 +604,31 @@ func (_m *GroupStore) GetGroupsByChannel(channelId string, opts model.GroupSearc
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetGroupsAssociatedToChannelsByTeam provides a mock function with given fields: teamId, opts
|
||||
func (_m *GroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) {
|
||||
ret := _m.Called(teamId, opts)
|
||||
|
||||
var r0 map[string][]*model.GroupWithSchemeAdmin
|
||||
if rf, ok := ret.Get(0).(func(string, model.GroupSearchOpts) map[string][]*model.GroupWithSchemeAdmin); ok {
|
||||
r0 = rf(teamId, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(map[string][]*model.GroupWithSchemeAdmin)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok {
|
||||
r1 = rf(teamId, opts)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetGroupsByTeam provides a mock function with given fields: teamId, opts
|
||||
func (_m *GroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) {
|
||||
ret := _m.Called(teamId, opts)
|
||||
|
||||
@@ -2990,6 +2990,22 @@ func (s *TimerLayerGroupStore) GetGroupsByChannel(channelId string, opts model.G
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.GroupStore.GetGroupsAssociatedToChannelsByTeam(teamId, opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if resultVar1 == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.GetGroupsAssociatedToChannelsByTeam", success, elapsed)
|
||||
}
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user