From f01d56fe5fef946eb523db8d31d8d49ff1c4e7ff Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 27 Jan 2022 17:32:41 +0100 Subject: [PATCH] temporary hack to completely delete users When deleting a user using the OCS api we want to delete the users home space. Now to completely delete a space you need to send two requests. First to 'disable' a space and a second one to really purge it. This commit introduces this second purge request. Furthermore the OCS api now also deletes all spaces owned by the user not only the home space. This is needed since some tests create project spaces and then lookup the space by name. When doing multiple runs though the tests will find several spaces with the same name and will sometimes choose the wrong one which leads to test failures. The whole test tear down should be changed to correctly clean up the test setup. --- ocs/pkg/service/v0/users.go | 51 ++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/ocs/pkg/service/v0/users.go b/ocs/pkg/service/v0/users.go index 84cf9df2b..8010b10a2 100644 --- a/ocs/pkg/service/v0/users.go +++ b/ocs/pkg/service/v0/users.go @@ -14,6 +14,7 @@ import ( revauser "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/auth/scope" revactx "github.com/cs3org/reva/pkg/ctx" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" @@ -410,12 +411,6 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) { }, }, }, - { - Type: provider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE, - Term: &provider.ListStorageSpacesRequest_Filter_SpaceType{ - SpaceType: "personal", - }, - }, }, }) if err != nil { @@ -445,6 +440,50 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) { continue } } + lsRes, err = gwc.ListStorageSpaces(ctx, &provider.ListStorageSpacesRequest{ + Filters: []*provider.ListStorageSpacesRequest_Filter{ + { + Type: provider.ListStorageSpacesRequest_Filter_TYPE_OWNER, + Term: &provider.ListStorageSpacesRequest_Filter_Owner{ + Owner: &revauser.UserId{ + Idp: o.config.IdentityManagement.Address, + OpaqueId: account.Id, + }, + }, + }, + }, + }) + if err != nil { + o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, errors.Wrap(err, "could not list owned personal spaces").Error())) + return + } + + if lsRes.Status.Code != rpcv1beta1.Code_CODE_OK { + o.logger.Error(). + Interface("status", lsRes.Status). + Msg("DeleteUser: could not list personal spaces") + return + } + for _, space := range lsRes.StorageSpaces { + dsRes, err := gwc.DeleteStorageSpace(ctx, &provider.DeleteStorageSpaceRequest{ + Opaque: &typesv1beta1.Opaque{ + Map: map[string]*typesv1beta1.OpaqueEntry{ + "purge": {}, + }, + }, + Id: space.Id, + }) + if err != nil { + o.logger.Error().Err(err).Msg("DeleteUser: could not make delete space request") + continue + } + if dsRes.Status.Code != rpcv1beta1.Code_CODE_OK && dsRes.Status.Code != rpcv1beta1.Code_CODE_NOT_FOUND { + o.logger.Error(). + Interface("status", dsRes.Status). + Msg("DeleteUser: could not delete space") + continue + } + } } req := accounts.DeleteAccountRequest{