MM-23816: Group Mentions: Add ability to rename group names (#14338)
* MM-23816: Group Mentions: Add ability to rename group names
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9dc64173dc
Коммит
41e58d9769
@@ -3180,7 +3180,7 @@ func (s *OpenTracingLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerGroupStore) GetByName(name string) (*model.Group, *model.AppError) {
|
||||
func (s *OpenTracingLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "GroupStore.GetByName")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -3189,7 +3189,7 @@ func (s *OpenTracingLayerGroupStore) GetByName(name string) (*model.Group, *mode
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := s.GroupStore.GetByName(name)
|
||||
resultVar0, resultVar1 := s.GroupStore.GetByName(name, opts)
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -125,9 +125,19 @@ func (s *SqlGroupStore) Get(groupId string) (*model.Group, *model.AppError) {
|
||||
return group, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) GetByName(name string) (*model.Group, *model.AppError) {
|
||||
func (s *SqlGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) {
|
||||
var group *model.Group
|
||||
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil {
|
||||
query := s.getQueryBuilder().Select("*").From("UserGroups").Where(sq.Eq{"Name": name})
|
||||
if opts.FilterAllowReference {
|
||||
query = query.Where("AllowReference = true")
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GetByName", "store.sql_group.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if err := s.GetReplica().SelectOne(&group, queryString, args...); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupGetByName", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound)
|
||||
}
|
||||
@@ -216,6 +226,9 @@ func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, *model.AppErro
|
||||
|
||||
rowsChanged, err := s.GetMaster().Update(group)
|
||||
if err != nil {
|
||||
if IsUniqueConstraintError(err, []string{"Name", "groups_name_key"}) {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.sql_group.unique_constraint", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdate", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if rowsChanged != 1 {
|
||||
@@ -993,8 +1006,8 @@ func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncab
|
||||
query := s.getQueryBuilder().
|
||||
Select("gc.ChannelId, ug.*, gc.SchemeAdmin AS SyncableSchemeAdmin").
|
||||
From("UserGroups ug").
|
||||
LeftJoin(fmt.Sprintf(`(
|
||||
SELECT
|
||||
LeftJoin(`
|
||||
(SELECT
|
||||
GroupChannels.GroupId, GroupChannels.ChannelId, GroupChannels.DeleteAt, GroupChannels.SchemeAdmin
|
||||
FROM
|
||||
GroupChannels
|
||||
@@ -1003,8 +1016,7 @@ func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncab
|
||||
WHERE
|
||||
GroupChannels.DeleteAt = 0
|
||||
AND Channels.DeleteAt = 0
|
||||
AND Channels.TeamId = ?) AS gc
|
||||
ON gc.GroupId = ug.Id`), teamID).
|
||||
AND Channels.TeamId = ?) AS gc ON gc.GroupId = ug.Id`, teamID).
|
||||
Where("ug.DeleteAt = 0 AND gc.DeleteAt = 0").
|
||||
OrderBy("ug.DisplayName")
|
||||
|
||||
@@ -1012,8 +1024,8 @@ func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncab
|
||||
query = s.getQueryBuilder().
|
||||
Select("gc.ChannelId, ug.*, coalesce(Members.MemberCount, 0) AS MemberCount, gc.SchemeAdmin AS SyncableSchemeAdmin").
|
||||
From("UserGroups ug").
|
||||
LeftJoin(fmt.Sprintf(`(
|
||||
SELECT
|
||||
LeftJoin(`
|
||||
(SELECT
|
||||
GroupChannels.ChannelId, GroupChannels.DeleteAt, GroupChannels.GroupId, GroupChannels.SchemeAdmin
|
||||
FROM
|
||||
GroupChannels
|
||||
@@ -1022,8 +1034,7 @@ func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncab
|
||||
WHERE
|
||||
GroupChannels.DeleteAt = 0
|
||||
AND Channels.DeleteAt = 0
|
||||
AND Channels.TeamId = ?) AS gc
|
||||
ON gc.GroupId = ug.Id`), teamID).
|
||||
AND Channels.TeamId = ?) AS gc ON gc.GroupId = ug.Id`, teamID).
|
||||
LeftJoin(`(
|
||||
SELECT
|
||||
GroupMembers.GroupId, COUNT(*) AS MemberCount
|
||||
|
||||
@@ -624,7 +624,7 @@ type UserTermsOfServiceStore interface {
|
||||
type GroupStore interface {
|
||||
Create(group *model.Group) (*model.Group, *model.AppError)
|
||||
Get(groupID string) (*model.Group, *model.AppError)
|
||||
GetByName(name string) (*model.Group, *model.AppError)
|
||||
GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError)
|
||||
GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError)
|
||||
GetByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError)
|
||||
GetAllBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError)
|
||||
|
||||
@@ -177,6 +177,16 @@ func testGroupStoreCreate(t *testing.T, ss store.Store) {
|
||||
RemoteId: model.NewId(),
|
||||
}
|
||||
require.Equal(t, g6.IsValidForCreate().Id, "model.group.source.app_error")
|
||||
|
||||
//must use valid characters
|
||||
g7 := &model.Group{
|
||||
Name: "%^#@$$",
|
||||
DisplayName: model.NewId(),
|
||||
Description: model.NewId(),
|
||||
Source: model.GroupSourceLdap,
|
||||
RemoteId: model.NewId(),
|
||||
}
|
||||
require.Equal(t, g7.IsValidForCreate().Id, "model.group.name.invalid_chars.app_error")
|
||||
}
|
||||
|
||||
func testGroupStoreGet(t *testing.T, ss store.Store) {
|
||||
@@ -219,12 +229,16 @@ func testGroupStoreGetByName(t *testing.T, ss store.Store) {
|
||||
Source: model.GroupSourceLdap,
|
||||
RemoteId: model.NewId(),
|
||||
}
|
||||
g1Opts := model.GroupSearchOpts{
|
||||
FilterAllowReference: false,
|
||||
}
|
||||
|
||||
d1, err := ss.Group().Create(g1)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, d1.Id, 26)
|
||||
|
||||
// Get the group
|
||||
d2, err := ss.Group().GetByName(d1.Name)
|
||||
d2, err := ss.Group().GetByName(d1.Name, g1Opts)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, d1.Id, d2.Id)
|
||||
require.Equal(t, d1.Name, d2.Name)
|
||||
@@ -236,7 +250,7 @@ func testGroupStoreGetByName(t *testing.T, ss store.Store) {
|
||||
require.Equal(t, d1.DeleteAt, d2.DeleteAt)
|
||||
|
||||
// Get an invalid group
|
||||
_, err = ss.Group().GetByName(model.NewId())
|
||||
_, err = ss.Group().GetByName(model.NewId(), g1Opts)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, err.Id, "store.sql_group.no_rows")
|
||||
}
|
||||
@@ -490,7 +504,7 @@ func testGroupStoreUpdate(t *testing.T, ss store.Store) {
|
||||
Description: model.NewId(),
|
||||
RemoteId: model.NewId(),
|
||||
})
|
||||
require.Equal(t, err.Id, "store.update_error")
|
||||
require.Equal(t, err.Id, "store.sql_group.unique_constraint")
|
||||
|
||||
// Cannot update CreateAt
|
||||
someVal := model.GetMillis()
|
||||
|
||||
@@ -454,13 +454,13 @@ func (_m *GroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppErr
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByName provides a mock function with given fields: name
|
||||
func (_m *GroupStore) GetByName(name string) (*model.Group, *model.AppError) {
|
||||
ret := _m.Called(name)
|
||||
// GetByName provides a mock function with given fields: name, opts
|
||||
func (_m *GroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) {
|
||||
ret := _m.Called(name, opts)
|
||||
|
||||
var r0 *model.Group
|
||||
if rf, ok := ret.Get(0).(func(string) *model.Group); ok {
|
||||
r0 = rf(name)
|
||||
if rf, ok := ret.Get(0).(func(string, model.GroupSearchOpts) *model.Group); ok {
|
||||
r0 = rf(name, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Group)
|
||||
@@ -468,8 +468,8 @@ func (_m *GroupStore) GetByName(name string) (*model.Group, *model.AppError) {
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(name)
|
||||
if rf, ok := ret.Get(1).(func(string, model.GroupSearchOpts) *model.AppError); ok {
|
||||
r1 = rf(name, opts)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
|
||||
@@ -2910,10 +2910,10 @@ func (s *TimerLayerGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *mod
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerGroupStore) GetByName(name string) (*model.Group, *model.AppError) {
|
||||
func (s *TimerLayerGroupStore) GetByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.GroupStore.GetByName(name)
|
||||
resultVar0, resultVar1 := s.GroupStore.GetByName(name, opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user