mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrate Store groups to sync by default (GroupSyncable methods) (#11003)
This commit is contained in:
30
app/group.go
30
app/group.go
@@ -94,43 +94,23 @@ func (a *App) DeleteGroupMember(groupID string, userID string) (*model.GroupMemb
|
||||
}
|
||||
|
||||
func (a *App) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
result := <-a.Srv.Store.Group().CreateGroupSyncable(groupSyncable)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.GroupSyncable), nil
|
||||
return a.Srv.Store.Group().CreateGroupSyncable(groupSyncable)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
result := <-a.Srv.Store.Group().GetGroupSyncable(groupID, syncableID, syncableType)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.GroupSyncable), nil
|
||||
return a.Srv.Store.Group().GetGroupSyncable(groupID, syncableID, syncableType)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
|
||||
result := <-a.Srv.Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.([]*model.GroupSyncable), nil
|
||||
return a.Srv.Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType)
|
||||
}
|
||||
|
||||
func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
result := <-a.Srv.Store.Group().UpdateGroupSyncable(groupSyncable)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.GroupSyncable), nil
|
||||
return a.Srv.Store.Group().UpdateGroupSyncable(groupSyncable)
|
||||
}
|
||||
|
||||
func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
result := <-a.Srv.Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.GroupSyncable), nil
|
||||
return a.Srv.Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType)
|
||||
}
|
||||
|
||||
func (a *App) TeamMembersToAdd(since int64) ([]*model.UserTeamIDPair, *model.AppError) {
|
||||
|
||||
@@ -406,69 +406,52 @@ func (s *SqlGroupStore) DeleteMember(groupID string, userID string) store.StoreC
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
if err := groupSyncable.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := groupSyncable.IsValid(); err != nil {
|
||||
result.Err = err
|
||||
return
|
||||
// Reset values that shouldn't be updatable by parameter
|
||||
groupSyncable.DeleteAt = 0
|
||||
groupSyncable.CreateAt = model.GetMillis()
|
||||
groupSyncable.UpdateAt = groupSyncable.CreateAt
|
||||
|
||||
var insertErr error
|
||||
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
if _, err := s.Team().Get(groupSyncable.SyncableId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Reset values that shouldn't be updatable by parameter
|
||||
groupSyncable.DeleteAt = 0
|
||||
groupSyncable.CreateAt = model.GetMillis()
|
||||
groupSyncable.UpdateAt = groupSyncable.CreateAt
|
||||
|
||||
var err error
|
||||
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
if _, err := s.Team().Get(groupSyncable.SyncableId); err != nil {
|
||||
result.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
err = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
_, errCh := s.Channel().Get(groupSyncable.SyncableId, false)
|
||||
if errCh != nil {
|
||||
result.Err = errCh
|
||||
return
|
||||
}
|
||||
|
||||
err = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
||||
default:
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
if _, err := s.Channel().Get(groupSyncable.SyncableId, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "store.insert_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
insertErr = s.GetMaster().Insert(groupSyncableToGroupChannel(groupSyncable))
|
||||
default:
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = groupSyncable
|
||||
return
|
||||
})
|
||||
if insertErr != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupCreateGroupSyncable", "store.insert_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+insertErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return groupSyncable, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
|
||||
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound)
|
||||
} else {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
func (s *SqlGroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound)
|
||||
}
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupGetGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = groupSyncable
|
||||
|
||||
return
|
||||
})
|
||||
return groupSyncable, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) getGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, error) {
|
||||
@@ -517,20 +500,18 @@ func (s *SqlGroupStore) getGroupSyncable(groupID string, syncableID string, sync
|
||||
return &groupSyncable, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
|
||||
args := map[string]interface{}{"GroupId": groupID}
|
||||
|
||||
args := map[string]interface{}{"GroupId": groupID}
|
||||
appErrF := func(msg string) *model.AppError {
|
||||
return model.NewAppError("SqlGroupStore.GroupGetAllGroupSyncablesByGroup", "store.select_error", nil, msg, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
appErrF := func(msg string) *model.AppError {
|
||||
return model.NewAppError("SqlGroupStore.GroupGetAllGroupSyncablesByGroup", "store.select_error", nil, msg, http.StatusInternalServerError)
|
||||
}
|
||||
groupSyncables := []*model.GroupSyncable{}
|
||||
|
||||
groupSyncables := []*model.GroupSyncable{}
|
||||
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
sqlQuery := `
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
sqlQuery := `
|
||||
SELECT
|
||||
GroupTeams.*,
|
||||
Teams.DisplayName AS TeamDisplayName,
|
||||
@@ -541,28 +522,27 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy
|
||||
WHERE
|
||||
GroupId = :GroupId AND GroupTeams.DeleteAt = 0`
|
||||
|
||||
results := []*groupTeamJoin{}
|
||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||
if err != nil {
|
||||
result.Err = appErrF(err.Error())
|
||||
return
|
||||
results := []*groupTeamJoin{}
|
||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||
if err != nil {
|
||||
return nil, appErrF(err.Error())
|
||||
}
|
||||
for _, result := range results {
|
||||
groupSyncable := &model.GroupSyncable{
|
||||
SyncableId: result.TeamId,
|
||||
GroupId: result.GroupId,
|
||||
AutoAdd: result.AutoAdd,
|
||||
CreateAt: result.CreateAt,
|
||||
DeleteAt: result.DeleteAt,
|
||||
UpdateAt: result.UpdateAt,
|
||||
Type: syncableType,
|
||||
TeamDisplayName: result.TeamDisplayName,
|
||||
TeamType: result.TeamType,
|
||||
}
|
||||
for _, result := range results {
|
||||
groupSyncable := &model.GroupSyncable{
|
||||
SyncableId: result.TeamId,
|
||||
GroupId: result.GroupId,
|
||||
AutoAdd: result.AutoAdd,
|
||||
CreateAt: result.CreateAt,
|
||||
DeleteAt: result.DeleteAt,
|
||||
UpdateAt: result.UpdateAt,
|
||||
Type: syncableType,
|
||||
TeamDisplayName: result.TeamDisplayName,
|
||||
TeamType: result.TeamType,
|
||||
}
|
||||
groupSyncables = append(groupSyncables, groupSyncable)
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
sqlQuery := `
|
||||
groupSyncables = append(groupSyncables, groupSyncable)
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
sqlQuery := `
|
||||
SELECT
|
||||
GroupChannels.*,
|
||||
Channels.DisplayName AS ChannelDisplayName,
|
||||
@@ -577,124 +557,102 @@ func (s *SqlGroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableTy
|
||||
WHERE
|
||||
GroupId = :GroupId AND GroupChannels.DeleteAt = 0`
|
||||
|
||||
results := []*groupChannelJoin{}
|
||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||
if err != nil {
|
||||
result.Err = appErrF(err.Error())
|
||||
return
|
||||
}
|
||||
for _, result := range results {
|
||||
groupSyncable := &model.GroupSyncable{
|
||||
SyncableId: result.ChannelId,
|
||||
GroupId: result.GroupId,
|
||||
AutoAdd: result.AutoAdd,
|
||||
CreateAt: result.CreateAt,
|
||||
DeleteAt: result.DeleteAt,
|
||||
UpdateAt: result.UpdateAt,
|
||||
Type: syncableType,
|
||||
ChannelDisplayName: result.ChannelDisplayName,
|
||||
ChannelType: result.ChannelType,
|
||||
TeamDisplayName: result.TeamDisplayName,
|
||||
TeamType: result.TeamType,
|
||||
TeamID: result.TeamID,
|
||||
}
|
||||
groupSyncables = append(groupSyncables, groupSyncable)
|
||||
}
|
||||
results := []*groupChannelJoin{}
|
||||
_, err := s.GetMaster().Select(&results, sqlQuery, args)
|
||||
if err != nil {
|
||||
return nil, appErrF(err.Error())
|
||||
}
|
||||
for _, result := range results {
|
||||
groupSyncable := &model.GroupSyncable{
|
||||
SyncableId: result.ChannelId,
|
||||
GroupId: result.GroupId,
|
||||
AutoAdd: result.AutoAdd,
|
||||
CreateAt: result.CreateAt,
|
||||
DeleteAt: result.DeleteAt,
|
||||
UpdateAt: result.UpdateAt,
|
||||
Type: syncableType,
|
||||
ChannelDisplayName: result.ChannelDisplayName,
|
||||
ChannelType: result.ChannelType,
|
||||
TeamDisplayName: result.TeamDisplayName,
|
||||
TeamType: result.TeamType,
|
||||
TeamID: result.TeamID,
|
||||
}
|
||||
groupSyncables = append(groupSyncables, groupSyncable)
|
||||
}
|
||||
}
|
||||
|
||||
result.Data = groupSyncables
|
||||
return
|
||||
})
|
||||
return groupSyncables, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
|
||||
retrievedGroupSyncable, err := s.getGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.select_error", nil, "GroupId="+groupSyncable.GroupId+", SyncableId="+groupSyncable.SyncableId+", SyncableType="+groupSyncable.Type.String()+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
func (s *SqlGroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
retrievedGroupSyncable, err := s.getGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.sql_group.no_rows", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.select_error", nil, "GroupId="+groupSyncable.GroupId+", SyncableId="+groupSyncable.SyncableId+", SyncableType="+groupSyncable.Type.String()+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := groupSyncable.IsValid(); err != nil {
|
||||
result.Err = err
|
||||
return
|
||||
}
|
||||
if err := groupSyncable.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If updating DeleteAt it can only be to 0
|
||||
if groupSyncable.DeleteAt != retrievedGroupSyncable.DeleteAt && groupSyncable.DeleteAt != 0 {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// If updating DeleteAt it can only be to 0
|
||||
if groupSyncable.DeleteAt != retrievedGroupSyncable.DeleteAt && groupSyncable.DeleteAt != 0 {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group.delete_at.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// Reset these properties, don't update them based on input
|
||||
groupSyncable.CreateAt = retrievedGroupSyncable.CreateAt
|
||||
groupSyncable.UpdateAt = model.GetMillis()
|
||||
// Reset these properties, don't update them based on input
|
||||
groupSyncable.CreateAt = retrievedGroupSyncable.CreateAt
|
||||
groupSyncable.UpdateAt = model.GetMillis()
|
||||
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||
default:
|
||||
model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||
default:
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupUpdateGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = groupSyncable
|
||||
return
|
||||
})
|
||||
return groupSyncable, nil
|
||||
}
|
||||
|
||||
func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
|
||||
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.no_rows", nil, "Id="+groupID+", "+err.Error(), http.StatusNotFound)
|
||||
} else {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
func (s *SqlGroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
groupSyncable, err := s.getGroupSyncable(groupID, syncableID, syncableType)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.no_rows", nil, "Id="+groupID+", "+err.Error(), http.StatusNotFound)
|
||||
}
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if groupSyncable.DeleteAt != 0 {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.group_syncable_already_deleted", nil, "group_id="+groupID+"syncable_id="+syncableID, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if groupSyncable.DeleteAt != 0 {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.sql_group.group_syncable_already_deleted", nil, "group_id="+groupID+"syncable_id="+syncableID, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
time := model.GetMillis()
|
||||
groupSyncable.DeleteAt = time
|
||||
groupSyncable.UpdateAt = time
|
||||
time := model.GetMillis()
|
||||
groupSyncable.DeleteAt = time
|
||||
groupSyncable.UpdateAt = time
|
||||
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||
default:
|
||||
model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
switch groupSyncable.Type {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupTeam(groupSyncable))
|
||||
case model.GroupSyncableTypeChannel:
|
||||
_, err = s.GetMaster().Update(groupSyncableToGroupChannel(groupSyncable))
|
||||
default:
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "model.group_syncable.type.app_error", nil, "group_id="+groupSyncable.GroupId+", syncable_id="+groupSyncable.SyncableId+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlGroupStore.GroupDeleteGroupSyncable", "store.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = groupSyncable
|
||||
return
|
||||
})
|
||||
return groupSyncable, nil
|
||||
}
|
||||
|
||||
// TeamMembersToAdd returns a slice of UserTeamIDPair that need newly created memberships
|
||||
|
||||
@@ -582,11 +582,11 @@ type GroupStore interface {
|
||||
CreateOrRestoreMember(groupID string, userID string) StoreChannel
|
||||
DeleteMember(groupID string, userID string) StoreChannel
|
||||
|
||||
CreateGroupSyncable(groupSyncable *model.GroupSyncable) StoreChannel
|
||||
GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) StoreChannel
|
||||
GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) StoreChannel
|
||||
UpdateGroupSyncable(groupSyncable *model.GroupSyncable) StoreChannel
|
||||
DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) StoreChannel
|
||||
CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
||||
GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError)
|
||||
UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
||||
|
||||
TeamMembersToAdd(since int64) ([]*model.UserTeamIDPair, *model.AppError)
|
||||
ChannelMembersToAdd(since int64) ([]*model.UserChannelIDPair, *model.AppError)
|
||||
|
||||
@@ -1116,7 +1116,8 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlSupplier)
|
||||
RemoteId: model.NewId(),
|
||||
}
|
||||
store.Must(ss.Group().Create(group))
|
||||
store.Must(ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, c1.Id, true)))
|
||||
_, err = ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, c1.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
c2 := model.Channel{}
|
||||
c2.TeamId = t1.Id
|
||||
@@ -2457,7 +2458,8 @@ func testChannelStoreSearchAllChannels(t *testing.T, ss store.Store) {
|
||||
RemoteId: model.NewId(),
|
||||
}
|
||||
store.Must(ss.Group().Create(group))
|
||||
store.Must(ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, o7.Id, true)))
|
||||
_, err = ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, o7.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
o8 := model.Channel{
|
||||
TeamId: t1.Id,
|
||||
|
||||
@@ -624,8 +624,8 @@ func testGroupDeleteMember(t *testing.T, ss store.Store) {
|
||||
|
||||
func testCreateGroupSyncable(t *testing.T, ss store.Store) {
|
||||
// Invalid GroupID
|
||||
res2 := <-ss.Group().CreateGroupSyncable(model.NewGroupTeam("x", model.NewId(), false))
|
||||
require.Equal(t, res2.Err.Id, "model.group_syncable.group_id.app_error")
|
||||
_, err := ss.Group().CreateGroupSyncable(model.NewGroupTeam("x", model.NewId(), false))
|
||||
require.Equal(t, err.Id, "model.group_syncable.group_id.app_error")
|
||||
|
||||
// Create Group
|
||||
g1 := &model.Group{
|
||||
@@ -654,9 +654,8 @@ func testCreateGroupSyncable(t *testing.T, ss store.Store) {
|
||||
|
||||
// New GroupSyncable, happy path
|
||||
gt1 := model.NewGroupTeam(group.Id, team.Id, false)
|
||||
res6 := <-ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, res6.Err)
|
||||
d1 := res6.Data.(*model.GroupSyncable)
|
||||
d1, err := ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, gt1.SyncableId, d1.SyncableId)
|
||||
require.Equal(t, gt1.GroupId, d1.GroupId)
|
||||
require.Equal(t, gt1.AutoAdd, d1.AutoAdd)
|
||||
@@ -693,14 +692,12 @@ func testGetGroupSyncable(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create GroupSyncable
|
||||
gt1 := model.NewGroupTeam(group.Id, team.Id, false)
|
||||
res3 := <-ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, res3.Err)
|
||||
groupTeam := res3.Data.(*model.GroupSyncable)
|
||||
groupTeam, err := ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Get GroupSyncable
|
||||
res4 := <-ss.Group().GetGroupSyncable(groupTeam.GroupId, groupTeam.SyncableId, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, res4.Err)
|
||||
dgt := res4.Data.(*model.GroupSyncable)
|
||||
dgt, err := ss.Group().GetGroupSyncable(groupTeam.GroupId, groupTeam.SyncableId, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, gt1.GroupId, dgt.GroupId)
|
||||
require.Equal(t, gt1.SyncableId, dgt.SyncableId)
|
||||
require.Equal(t, gt1.AutoAdd, dgt.AutoAdd)
|
||||
@@ -743,15 +740,14 @@ func testGetAllGroupSyncablesByGroup(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// create groupteam
|
||||
res3 := <-ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, team.Id, false))
|
||||
require.Nil(t, res3.Err)
|
||||
groupTeam := res3.Data.(*model.GroupSyncable)
|
||||
groupTeam, err := ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, team.Id, false))
|
||||
require.Nil(t, err)
|
||||
groupTeams = append(groupTeams, groupTeam)
|
||||
}
|
||||
|
||||
// Returns all the group teams
|
||||
res4 := <-ss.Group().GetAllGroupSyncablesByGroupId(group.Id, model.GroupSyncableTypeTeam)
|
||||
d1 := res4.Data.([]*model.GroupSyncable)
|
||||
d1, err := ss.Group().GetAllGroupSyncablesByGroupId(group.Id, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, err)
|
||||
require.Condition(t, func() bool { return len(d1) >= numGroupSyncables })
|
||||
for _, expectedGroupTeam := range groupTeams {
|
||||
present := false
|
||||
@@ -793,46 +789,42 @@ func testUpdateGroupSyncable(t *testing.T, ss store.Store) {
|
||||
|
||||
// New GroupSyncable, happy path
|
||||
gt1 := model.NewGroupTeam(group.Id, team.Id, false)
|
||||
res6 := <-ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, res6.Err)
|
||||
d1 := res6.Data.(*model.GroupSyncable)
|
||||
d1, err := ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Update existing group team
|
||||
gt1.AutoAdd = true
|
||||
res7 := <-ss.Group().UpdateGroupSyncable(gt1)
|
||||
require.Nil(t, res7.Err)
|
||||
d2 := res7.Data.(*model.GroupSyncable)
|
||||
d2, err := ss.Group().UpdateGroupSyncable(gt1)
|
||||
require.Nil(t, err)
|
||||
require.True(t, d2.AutoAdd)
|
||||
|
||||
// Non-existent Group
|
||||
gt2 := model.NewGroupTeam(model.NewId(), team.Id, false)
|
||||
res9 := <-ss.Group().UpdateGroupSyncable(gt2)
|
||||
require.Equal(t, res9.Err.Id, "store.sql_group.no_rows")
|
||||
_, err = ss.Group().UpdateGroupSyncable(gt2)
|
||||
require.Equal(t, err.Id, "store.sql_group.no_rows")
|
||||
|
||||
// Non-existent Team
|
||||
gt3 := model.NewGroupTeam(group.Id, model.NewId(), false)
|
||||
res10 := <-ss.Group().UpdateGroupSyncable(gt3)
|
||||
require.Equal(t, res10.Err.Id, "store.sql_group.no_rows")
|
||||
_, err = ss.Group().UpdateGroupSyncable(gt3)
|
||||
require.Equal(t, err.Id, "store.sql_group.no_rows")
|
||||
|
||||
// Cannot update CreateAt or DeleteAt
|
||||
origCreateAt := d1.CreateAt
|
||||
d1.CreateAt = model.GetMillis()
|
||||
d1.AutoAdd = true
|
||||
res11 := <-ss.Group().UpdateGroupSyncable(d1)
|
||||
require.Nil(t, res11.Err)
|
||||
d3 := res11.Data.(*model.GroupSyncable)
|
||||
d3, err := ss.Group().UpdateGroupSyncable(d1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, origCreateAt, d3.CreateAt)
|
||||
|
||||
// Cannot update DeleteAt to arbitrary value
|
||||
d1.DeleteAt = 1
|
||||
res12 := <-ss.Group().UpdateGroupSyncable(d1)
|
||||
require.Equal(t, "model.group.delete_at.app_error", res12.Err.Id)
|
||||
_, err = ss.Group().UpdateGroupSyncable(d1)
|
||||
require.Equal(t, "model.group.delete_at.app_error", err.Id)
|
||||
|
||||
// Can update DeleteAt to 0
|
||||
d1.DeleteAt = 0
|
||||
res13 := <-ss.Group().UpdateGroupSyncable(d1)
|
||||
require.Nil(t, res13.Err)
|
||||
d4 := res13.Data.(*model.GroupSyncable)
|
||||
d4, err := ss.Group().UpdateGroupSyncable(d1)
|
||||
require.Nil(t, err)
|
||||
require.Zero(t, d4.DeleteAt)
|
||||
}
|
||||
|
||||
@@ -864,22 +856,20 @@ func testDeleteGroupSyncable(t *testing.T, ss store.Store) {
|
||||
|
||||
// Create GroupSyncable
|
||||
gt1 := model.NewGroupTeam(group.Id, team.Id, false)
|
||||
res7 := <-ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, res7.Err)
|
||||
groupTeam := res7.Data.(*model.GroupSyncable)
|
||||
groupTeam, err := ss.Group().CreateGroupSyncable(gt1)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Non-existent Group
|
||||
res5 := <-ss.Group().DeleteGroupSyncable(model.NewId(), groupTeam.SyncableId, model.GroupSyncableTypeTeam)
|
||||
require.Equal(t, res5.Err.Id, "store.sql_group.no_rows")
|
||||
_, err = ss.Group().DeleteGroupSyncable(model.NewId(), groupTeam.SyncableId, model.GroupSyncableTypeTeam)
|
||||
require.Equal(t, err.Id, "store.sql_group.no_rows")
|
||||
|
||||
// Non-existent Team
|
||||
res6 := <-ss.Group().DeleteGroupSyncable(groupTeam.GroupId, string(model.NewId()), model.GroupSyncableTypeTeam)
|
||||
require.Equal(t, res6.Err.Id, "store.sql_group.no_rows")
|
||||
_, err = ss.Group().DeleteGroupSyncable(groupTeam.GroupId, string(model.NewId()), model.GroupSyncableTypeTeam)
|
||||
require.Equal(t, err.Id, "store.sql_group.no_rows")
|
||||
|
||||
// Happy path...
|
||||
res8 := <-ss.Group().DeleteGroupSyncable(groupTeam.GroupId, groupTeam.SyncableId, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, res8.Err)
|
||||
d1 := res8.Data.(*model.GroupSyncable)
|
||||
d1, err := ss.Group().DeleteGroupSyncable(groupTeam.GroupId, groupTeam.SyncableId, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, err)
|
||||
require.NotZero(t, d1.DeleteAt)
|
||||
require.Equal(t, d1.GroupId, groupTeam.GroupId)
|
||||
require.Equal(t, d1.SyncableId, groupTeam.SyncableId)
|
||||
@@ -888,9 +878,9 @@ func testDeleteGroupSyncable(t *testing.T, ss store.Store) {
|
||||
require.Condition(t, func() bool { return d1.UpdateAt > groupTeam.UpdateAt })
|
||||
|
||||
// Record already deleted
|
||||
res9 := <-ss.Group().DeleteGroupSyncable(d1.GroupId, d1.SyncableId, d1.Type)
|
||||
require.NotNil(t, res9.Err)
|
||||
require.Equal(t, res9.Err.Id, "store.sql_group.group_syncable_already_deleted")
|
||||
_, err = ss.Group().DeleteGroupSyncable(d1.GroupId, d1.SyncableId, d1.Type)
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, err.Id, "store.sql_group.group_syncable_already_deleted")
|
||||
}
|
||||
|
||||
func testPendingAutoAddTeamMembers(t *testing.T, ss store.Store) {
|
||||
@@ -932,9 +922,8 @@ func testPendingAutoAddTeamMembers(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Create GroupTeam
|
||||
res = <-ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, team.Id, true))
|
||||
require.Nil(t, res.Err)
|
||||
syncable := res.Data.(*model.GroupSyncable)
|
||||
syncable, err := ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, team.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
// Time before syncable was created
|
||||
teamMembers, err := ss.Group().TeamMembersToAdd(syncable.CreateAt - 1)
|
||||
@@ -959,8 +948,8 @@ func testPendingAutoAddTeamMembers(t *testing.T, ss store.Store) {
|
||||
|
||||
pristineSyncable := *syncable
|
||||
|
||||
res = <-ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Time before syncable was updated
|
||||
teamMembers, err = ss.Group().TeamMembersToAdd(syncable.UpdateAt - 1)
|
||||
@@ -976,15 +965,15 @@ func testPendingAutoAddTeamMembers(t *testing.T, ss store.Store) {
|
||||
|
||||
// Only includes if auto-add
|
||||
syncable.AutoAdd = false
|
||||
res = <-ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, err)
|
||||
teamMembers, err = ss.Group().TeamMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, teamMembers, 0)
|
||||
|
||||
// reset state of syncable and verify
|
||||
res = <-ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, err)
|
||||
teamMembers, err = ss.Group().TeamMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, teamMembers, 1)
|
||||
@@ -1020,15 +1009,15 @@ func testPendingAutoAddTeamMembers(t *testing.T, ss store.Store) {
|
||||
require.Len(t, teamMembers, 1)
|
||||
|
||||
// No result if GroupTeam deleted
|
||||
res = <-ss.Group().DeleteGroupSyncable(group.Id, team.Id, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().DeleteGroupSyncable(group.Id, team.Id, model.GroupSyncableTypeTeam)
|
||||
require.Nil(t, err)
|
||||
teamMembers, err = ss.Group().TeamMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, teamMembers, 0)
|
||||
|
||||
// reset GroupTeam and verify
|
||||
res = <-ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, err)
|
||||
teamMembers, err = ss.Group().TeamMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, teamMembers, 1)
|
||||
@@ -1092,9 +1081,8 @@ func testPendingAutoAddChannelMembers(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// Create GroupChannel
|
||||
res = <-ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, channel.Id, true))
|
||||
require.Nil(t, res.Err)
|
||||
syncable := res.Data.(*model.GroupSyncable)
|
||||
syncable, err := ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, channel.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
// Time before syncable was created
|
||||
channelMembers, err := ss.Group().ChannelMembersToAdd(syncable.CreateAt - 1)
|
||||
@@ -1119,8 +1107,8 @@ func testPendingAutoAddChannelMembers(t *testing.T, ss store.Store) {
|
||||
|
||||
pristineSyncable := *syncable
|
||||
|
||||
res = <-ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Time before syncable was updated
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(syncable.UpdateAt - 1)
|
||||
@@ -1136,15 +1124,15 @@ func testPendingAutoAddChannelMembers(t *testing.T, ss store.Store) {
|
||||
|
||||
// Only includes if auto-add
|
||||
syncable.AutoAdd = false
|
||||
res = <-ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(syncable)
|
||||
require.Nil(t, err)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, channelMembers, 0)
|
||||
|
||||
// reset state of syncable and verify
|
||||
res = <-ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, err)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, channelMembers, 1)
|
||||
@@ -1179,15 +1167,15 @@ func testPendingAutoAddChannelMembers(t *testing.T, ss store.Store) {
|
||||
require.Len(t, channelMembers, 1)
|
||||
|
||||
// No result if GroupChannel deleted
|
||||
res = <-ss.Group().DeleteGroupSyncable(group.Id, channel.Id, model.GroupSyncableTypeChannel)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().DeleteGroupSyncable(group.Id, channel.Id, model.GroupSyncableTypeChannel)
|
||||
require.Nil(t, err)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, channelMembers, 0)
|
||||
|
||||
// reset GroupChannel and verify
|
||||
res = <-ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().UpdateGroupSyncable(&pristineSyncable)
|
||||
require.Nil(t, err)
|
||||
channelMembers, err = ss.Group().ChannelMembersToAdd(0)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, channelMembers, 1)
|
||||
@@ -1486,18 +1474,18 @@ func pendingMemberRemovalsDataSetup(t *testing.T, ss store.Store) *removalsData
|
||||
require.Nil(t, err)
|
||||
|
||||
// create groupteams
|
||||
res = <-ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, teamConstrained.Id, true))
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, teamConstrained.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
res = <-ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, teamUnconstrained.Id, true))
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().CreateGroupSyncable(model.NewGroupTeam(group.Id, teamUnconstrained.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
// create groupchannels
|
||||
res = <-ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, channelConstrained.Id, true))
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, channelConstrained.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
res = <-ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, channelUnconstrained.Id, true))
|
||||
require.Nil(t, res.Err)
|
||||
_, err = ss.Group().CreateGroupSyncable(model.NewGroupChannel(group.Id, channelUnconstrained.Id, true))
|
||||
require.Nil(t, err)
|
||||
|
||||
// add users to teams
|
||||
userIDTeamIDs := [][]string{
|
||||
@@ -1580,13 +1568,13 @@ func testGetGroupsByChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
// And associate them with Channel1
|
||||
for _, g := range []*model.Group{group1, group2} {
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: channel1.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
GroupId: g.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
// Create Channel2
|
||||
@@ -1610,13 +1598,13 @@ func testGetGroupsByChannel(t *testing.T, ss store.Store) {
|
||||
group3 := res.Data.(*model.Group)
|
||||
|
||||
// And associate it to Channel2
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: channel2.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
GroupId: group3.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// add members
|
||||
u1 := &model.User{
|
||||
@@ -1777,13 +1765,13 @@ func testGetGroupsByTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
// And associate them with Team1
|
||||
for _, g := range []*model.Group{group1, group2} {
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: team1.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
GroupId: g.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
// Create Team2
|
||||
@@ -1811,13 +1799,13 @@ func testGetGroupsByTeam(t *testing.T, ss store.Store) {
|
||||
group3 := res.Data.(*model.Group)
|
||||
|
||||
// And associate it to Team2
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: team2.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
GroupId: group3.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// add members
|
||||
u1 := &model.User{
|
||||
@@ -1989,13 +1977,13 @@ func testGetGroups(t *testing.T, ss store.Store) {
|
||||
|
||||
// And associate them with Team1
|
||||
for _, g := range []*model.Group{group1, group2} {
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: team1.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
GroupId: g.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
// Create Team2
|
||||
@@ -2033,32 +2021,32 @@ func testGetGroups(t *testing.T, ss store.Store) {
|
||||
group3 := res.Data.(*model.Group)
|
||||
|
||||
// And associate it to Team2
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: team2.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
GroupId: group3.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// And associate Group1 to Channel2
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: channel2.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
GroupId: group1.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// And associate Group2 and Group3 to Channel1
|
||||
for _, g := range []*model.Group{group2, group3} {
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
AutoAdd: true,
|
||||
SyncableId: channel1.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
GroupId: g.Id,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
// add members
|
||||
|
||||
@@ -126,19 +126,28 @@ func (_m *GroupStore) Create(group *model.Group) store.StoreChannel {
|
||||
}
|
||||
|
||||
// CreateGroupSyncable provides a mock function with given fields: groupSyncable
|
||||
func (_m *GroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) store.StoreChannel {
|
||||
func (_m *GroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
ret := _m.Called(groupSyncable)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(*model.GroupSyncable) store.StoreChannel); ok {
|
||||
var r0 *model.GroupSyncable
|
||||
if rf, ok := ret.Get(0).(func(*model.GroupSyncable) *model.GroupSyncable); ok {
|
||||
r0 = rf(groupSyncable)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.GroupSyncable)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.GroupSyncable) *model.AppError); ok {
|
||||
r1 = rf(groupSyncable)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateOrRestoreMember provides a mock function with given fields: groupID, userID
|
||||
@@ -174,19 +183,28 @@ func (_m *GroupStore) Delete(groupID string) store.StoreChannel {
|
||||
}
|
||||
|
||||
// DeleteGroupSyncable provides a mock function with given fields: groupID, syncableID, syncableType
|
||||
func (_m *GroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||
func (_m *GroupStore) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
ret := _m.Called(groupID, syncableID, syncableType)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string, model.GroupSyncableType) store.StoreChannel); ok {
|
||||
var r0 *model.GroupSyncable
|
||||
if rf, ok := ret.Get(0).(func(string, string, model.GroupSyncableType) *model.GroupSyncable); ok {
|
||||
r0 = rf(groupID, syncableID, syncableType)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.GroupSyncable)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) *model.AppError); ok {
|
||||
r1 = rf(groupID, syncableID, syncableType)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// DeleteMember provides a mock function with given fields: groupID, userID
|
||||
@@ -238,19 +256,28 @@ func (_m *GroupStore) GetAllBySource(groupSource model.GroupSource) store.StoreC
|
||||
}
|
||||
|
||||
// GetAllGroupSyncablesByGroupId provides a mock function with given fields: groupID, syncableType
|
||||
func (_m *GroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||
func (_m *GroupStore) GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
|
||||
ret := _m.Called(groupID, syncableType)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, model.GroupSyncableType) store.StoreChannel); ok {
|
||||
var r0 []*model.GroupSyncable
|
||||
if rf, ok := ret.Get(0).(func(string, model.GroupSyncableType) []*model.GroupSyncable); ok {
|
||||
r0 = rf(groupID, syncableType)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.GroupSyncable)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, model.GroupSyncableType) *model.AppError); ok {
|
||||
r1 = rf(groupID, syncableType)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByRemoteID provides a mock function with given fields: remoteID, groupSource
|
||||
@@ -270,19 +297,28 @@ func (_m *GroupStore) GetByRemoteID(remoteID string, groupSource model.GroupSour
|
||||
}
|
||||
|
||||
// GetGroupSyncable provides a mock function with given fields: groupID, syncableID, syncableType
|
||||
func (_m *GroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) store.StoreChannel {
|
||||
func (_m *GroupStore) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
ret := _m.Called(groupID, syncableID, syncableType)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string, model.GroupSyncableType) store.StoreChannel); ok {
|
||||
var r0 *model.GroupSyncable
|
||||
if rf, ok := ret.Get(0).(func(string, string, model.GroupSyncableType) *model.GroupSyncable); ok {
|
||||
r0 = rf(groupID, syncableID, syncableType)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.GroupSyncable)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string, model.GroupSyncableType) *model.AppError); ok {
|
||||
r1 = rf(groupID, syncableID, syncableType)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetGroups provides a mock function with given fields: page, perPage, opts
|
||||
@@ -475,17 +511,26 @@ func (_m *GroupStore) Update(group *model.Group) store.StoreChannel {
|
||||
}
|
||||
|
||||
// UpdateGroupSyncable provides a mock function with given fields: groupSyncable
|
||||
func (_m *GroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) store.StoreChannel {
|
||||
func (_m *GroupStore) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
ret := _m.Called(groupSyncable)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(*model.GroupSyncable) store.StoreChannel); ok {
|
||||
var r0 *model.GroupSyncable
|
||||
if rf, ok := ret.Get(0).(func(*model.GroupSyncable) *model.GroupSyncable); ok {
|
||||
r0 = rf(groupSyncable)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.GroupSyncable)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.GroupSyncable) *model.AppError); ok {
|
||||
r1 = rf(groupSyncable)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
@@ -1126,12 +1126,12 @@ func testUserStoreGetProfilesNotInChannel(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
// associate the group with the channel
|
||||
res := <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: group.Id,
|
||||
SyncableId: c2.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("get team 1, channel 2, offset 0, limit 0, setting group constrained", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesNotInChannel(teamId, c2.Id, true, 0, 100, nil)
|
||||
@@ -3305,12 +3305,12 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
// associate the group with the team
|
||||
res := <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: group.Id,
|
||||
SyncableId: teamId,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("get not in team 1, offset 0, limit 100000 after second update, setting group constrained", func(t *testing.T) {
|
||||
result := <-ss.User().GetProfilesNotInTeam(teamId, true, 0, 100000, nil)
|
||||
@@ -3618,12 +3618,12 @@ func testUserStoreGetTeamGroupUsers(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, res.Err)
|
||||
|
||||
// association one group to team
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: groupA.Id,
|
||||
SyncableId: team.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
var users []*model.User
|
||||
|
||||
@@ -3647,12 +3647,12 @@ func testUserStoreGetTeamGroupUsers(t *testing.T, ss store.Store) {
|
||||
requireNUsers(1)
|
||||
|
||||
// associate other group to team
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: groupB.Id,
|
||||
SyncableId: team.Id,
|
||||
Type: model.GroupSyncableTypeTeam,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// should return users from all groups
|
||||
// 2 users now that both groups have been associated to the team
|
||||
@@ -3741,12 +3741,12 @@ func testUserStoreGetChannelGroupUsers(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, res.Err)
|
||||
|
||||
// association one group to channel
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: groupA.Id,
|
||||
SyncableId: channel.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
var users []*model.User
|
||||
|
||||
@@ -3770,12 +3770,12 @@ func testUserStoreGetChannelGroupUsers(t *testing.T, ss store.Store) {
|
||||
requireNUsers(1)
|
||||
|
||||
// associate other group to team
|
||||
res = <-ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
_, err = ss.Group().CreateGroupSyncable(&model.GroupSyncable{
|
||||
GroupId: groupB.Id,
|
||||
SyncableId: channel.Id,
|
||||
Type: model.GroupSyncableTypeChannel,
|
||||
})
|
||||
require.Nil(t, res.Err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// should return users from all groups
|
||||
// 2 users now that both groups have been associated to the team
|
||||
|
||||
Reference in New Issue
Block a user