mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
This commit is contained in:
committed by
Jesús Espino
parent
45b47ca901
commit
d1a594e504
@@ -825,49 +825,42 @@ func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId s
|
||||
}
|
||||
|
||||
// PermanentDeleteByTeam removes all channels for the given team from the database.
|
||||
func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
*result = s.permanentDeleteByTeamtT(transaction, teamId)
|
||||
if result.Err != nil {
|
||||
return
|
||||
}
|
||||
if err := s.permanentDeleteByTeamtT(transaction, teamId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Additionally propagate the deletions to the PublicChannels table.
|
||||
if _, err := transaction.Exec(`
|
||||
// Additionally propagate the deletions to the PublicChannels table.
|
||||
if _, err := transaction.Exec(`
|
||||
DELETE FROM
|
||||
PublicChannels
|
||||
WHERE
|
||||
TeamId = :TeamId
|
||||
`, map[string]interface{}{
|
||||
"TeamId": teamId,
|
||||
}); err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.PermanentDeleteByTeamt", "store.sql_channel.permanent_delete_by_team.delete_public_channels.app_error", nil, "team_id="+teamId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, teamId string) store.StoreResult {
|
||||
result := store.StoreResult{}
|
||||
|
||||
if _, err := transaction.Exec("DELETE FROM Channels WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return result
|
||||
"TeamId": teamId,
|
||||
}); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeamt", "store.sql_channel.permanent_delete_by_team.delete_public_channels.app_error", nil, "team_id="+teamId+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return result
|
||||
if err := transaction.Commit(); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, teamId string) *model.AppError {
|
||||
if _, err := transaction.Exec("DELETE FROM Channels WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PermanentDelete removes the given channel from the database.
|
||||
|
||||
@@ -140,7 +140,7 @@ type ChannelStore interface {
|
||||
Delete(channelId string, time int64) *model.AppError
|
||||
Restore(channelId string, time int64) *model.AppError
|
||||
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) *model.AppError
|
||||
PermanentDeleteByTeam(teamId string) StoreChannel
|
||||
PermanentDeleteByTeam(teamId string) *model.AppError
|
||||
PermanentDelete(channelId string) StoreChannel
|
||||
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
|
||||
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError)
|
||||
|
||||
@@ -645,8 +645,8 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) {
|
||||
require.Equal(t, &model.ChannelList{}, list)
|
||||
}
|
||||
|
||||
if r := <-ss.Channel().PermanentDeleteByTeam(o1.TeamId); r.Err != nil {
|
||||
t.Fatal(r.Err)
|
||||
if err = ss.Channel().PermanentDeleteByTeam(o1.TeamId); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1158,15 +1158,15 @@ func (_m *ChannelStore) PermanentDelete(channelId string) store.StoreChannel {
|
||||
}
|
||||
|
||||
// PermanentDeleteByTeam provides a mock function with given fields: teamId
|
||||
func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) store.StoreChannel {
|
||||
func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
r0 = rf(teamId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user