From b13a228b0451098ea32933a36fe64566e366583d Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Wed, 18 Apr 2018 10:18:07 +0100 Subject: MM-10121: CLI command to reset permissions system to default state. (#8637) * MM-10121: CLI command to reset permissions system to default state. * Review comment. --- store/sqlstore/role_supplier.go | 10 ++++++++++ store/sqlstore/system_store.go | 11 +++++++++++ 2 files changed, 21 insertions(+) (limited to 'store/sqlstore') diff --git a/store/sqlstore/role_supplier.go b/store/sqlstore/role_supplier.go index 828f4484e..ddbdaca52 100644 --- a/store/sqlstore/role_supplier.go +++ b/store/sqlstore/role_supplier.go @@ -174,3 +174,13 @@ func (s *SqlSupplier) RoleGetByNames(ctx context.Context, names []string, hints return result } + +func (s *SqlSupplier) RolePermanentDeleteAll(ctx context.Context, hints ...store.LayeredStoreHint) *store.LayeredStoreSupplierResult { + result := store.NewSupplierResult() + + if _, err := s.GetMaster().Exec("DELETE FROM Roles"); err != nil { + result.Err = model.NewAppError("SqlRoleStore.PermanentDeleteAll", "store.sql_role.permanent_delete_all.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return result +} diff --git a/store/sqlstore/system_store.go b/store/sqlstore/system_store.go index 496ff2ced..4065bb955 100644 --- a/store/sqlstore/system_store.go +++ b/store/sqlstore/system_store.go @@ -85,3 +85,14 @@ func (s SqlSystemStore) GetByName(name string) store.StoreChannel { result.Data = &system }) } + +func (s SqlSystemStore) PermanentDeleteByName(name string) store.StoreChannel { + return store.Do(func(result *store.StoreResult) { + var system model.System + if _, err := s.GetReplica().Exec("DELETE FROM Systems WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil { + result.Err = model.NewAppError("SqlSystemStore.PermanentDeleteByName", "store.sql_system.permanent_delete_by_name.app_error", nil, "", http.StatusInternalServerError) + } + + result.Data = &system + }) +} -- cgit v1.2.3-1-g7c22