Migrates Channel.ClearAllCustomRoleAssignments to sync by default (#11274)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
5c32f92413
Коммит
a02467698c
@@ -38,8 +38,8 @@ func (a *App) ResetPermissionsSystem() *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset all Custom Role assignments to ChannelMembers.
|
// Reset all Custom Role assignments to ChannelMembers.
|
||||||
if result := <-a.Srv.Store.Channel().ClearAllCustomRoleAssignments(); result.Err != nil {
|
if err := a.Srv.Store.Channel().ClearAllCustomRoleAssignments(); err != nil {
|
||||||
return result.Err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Purge all schemes from the database.
|
// Purge all schemes from the database.
|
||||||
|
|||||||
@@ -2411,65 +2411,61 @@ func (s SqlChannelStore) resetAllChannelSchemesT(transaction *gorp.Transaction)
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) ClearAllCustomRoleAssignments() store.StoreChannel {
|
func (s SqlChannelStore) ClearAllCustomRoleAssignments() *model.AppError {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
builtInRoles := model.MakeDefaultRoles()
|
||||||
builtInRoles := model.MakeDefaultRoles()
|
lastUserId := strings.Repeat("0", 26)
|
||||||
lastUserId := strings.Repeat("0", 26)
|
lastChannelId := strings.Repeat("0", 26)
|
||||||
lastChannelId := strings.Repeat("0", 26)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var transaction *gorp.Transaction
|
var transaction *gorp.Transaction
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if transaction, err = s.GetMaster().Begin(); err != nil {
|
if transaction, err = s.GetMaster().Begin(); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var channelMembers []*channelMember
|
var channelMembers []*channelMember
|
||||||
if _, err := transaction.Select(&channelMembers, "SELECT * from ChannelMembers WHERE (ChannelId, UserId) > (:ChannelId, :UserId) ORDER BY ChannelId, UserId LIMIT 1000", map[string]interface{}{"ChannelId": lastChannelId, "UserId": lastUserId}); err != nil {
|
if _, err := transaction.Select(&channelMembers, "SELECT * from ChannelMembers WHERE (ChannelId, UserId) > (:ChannelId, :UserId) ORDER BY ChannelId, UserId LIMIT 1000", map[string]interface{}{"ChannelId": lastChannelId, "UserId": lastUserId}); err != nil {
|
||||||
finalizeTransaction(transaction)
|
finalizeTransaction(transaction)
|
||||||
result.Err = model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.select.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if len(channelMembers) == 0 {
|
if len(channelMembers) == 0 {
|
||||||
finalizeTransaction(transaction)
|
finalizeTransaction(transaction)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range channelMembers {
|
for _, member := range channelMembers {
|
||||||
lastUserId = member.UserId
|
lastUserId = member.UserId
|
||||||
lastChannelId = member.ChannelId
|
lastChannelId = member.ChannelId
|
||||||
|
|
||||||
var newRoles []string
|
var newRoles []string
|
||||||
|
|
||||||
for _, role := range strings.Fields(member.Roles) {
|
for _, role := range strings.Fields(member.Roles) {
|
||||||
for name := range builtInRoles {
|
for name := range builtInRoles {
|
||||||
if name == role {
|
if name == role {
|
||||||
newRoles = append(newRoles, role)
|
newRoles = append(newRoles, role)
|
||||||
break
|
break
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newRolesString := strings.Join(newRoles, " ")
|
|
||||||
if newRolesString != member.Roles {
|
|
||||||
if _, err := transaction.Exec("UPDATE ChannelMembers SET Roles = :Roles WHERE UserId = :UserId AND ChannelId = :ChannelId", map[string]interface{}{"Roles": newRolesString, "ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
|
|
||||||
finalizeTransaction(transaction)
|
|
||||||
result.Err = model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := transaction.Commit(); err != nil {
|
newRolesString := strings.Join(newRoles, " ")
|
||||||
finalizeTransaction(transaction)
|
if newRolesString != member.Roles {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
if _, err := transaction.Exec("UPDATE ChannelMembers SET Roles = :Roles WHERE UserId = :UserId AND ChannelId = :ChannelId", map[string]interface{}{"Roles": newRolesString, "ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
|
||||||
return
|
finalizeTransaction(transaction)
|
||||||
|
return model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.update.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
if err := transaction.Commit(); err != nil {
|
||||||
|
finalizeTransaction(transaction)
|
||||||
|
return model.NewAppError("SqlChannelStore.ClearAllCustomRoleAssignments", "store.sql_channel.clear_all_custom_role_assignments.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) store.StoreChannel {
|
func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ type ChannelStore interface {
|
|||||||
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
||||||
MigrateChannelMembers(fromChannelId string, fromUserId string) StoreChannel
|
MigrateChannelMembers(fromChannelId string, fromUserId string) StoreChannel
|
||||||
ResetAllChannelSchemes() StoreChannel
|
ResetAllChannelSchemes() StoreChannel
|
||||||
ClearAllCustomRoleAssignments() StoreChannel
|
ClearAllCustomRoleAssignments() *model.AppError
|
||||||
MigratePublicChannels() error
|
MigratePublicChannels() error
|
||||||
GetAllChannelsForExportAfter(limit int, afterId string) StoreChannel
|
GetAllChannelsForExportAfter(limit int, afterId string) StoreChannel
|
||||||
GetAllDirectChannelsForExportAfter(limit int, afterId string) StoreChannel
|
GetAllDirectChannelsForExportAfter(limit int, afterId string) StoreChannel
|
||||||
|
|||||||
@@ -3096,7 +3096,7 @@ func testChannelStoreClearAllCustomRoleAssignments(t *testing.T, ss store.Store)
|
|||||||
store.Must(ss.Channel().SaveMember(m3))
|
store.Must(ss.Channel().SaveMember(m3))
|
||||||
store.Must(ss.Channel().SaveMember(m4))
|
store.Must(ss.Channel().SaveMember(m4))
|
||||||
|
|
||||||
require.Nil(t, (<-ss.Channel().ClearAllCustomRoleAssignments()).Err)
|
require.Nil(t, ss.Channel().ClearAllCustomRoleAssignments())
|
||||||
|
|
||||||
member, err := ss.Channel().GetMember(m1.ChannelId, m1.UserId)
|
member, err := ss.Channel().GetMember(m1.ChannelId, m1.UserId)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|||||||
@@ -94,15 +94,15 @@ func (_m *ChannelStore) AutocompleteInTeamForSearch(teamId string, userId string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClearAllCustomRoleAssignments provides a mock function with given fields:
|
// ClearAllCustomRoleAssignments provides a mock function with given fields:
|
||||||
func (_m *ChannelStore) ClearAllCustomRoleAssignments() store.StoreChannel {
|
func (_m *ChannelStore) ClearAllCustomRoleAssignments() *model.AppError {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.AppError
|
||||||
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func() *model.AppError); ok {
|
||||||
r0 = rf()
|
r0 = rf()
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user