Skip to content

Commit

Permalink
temporary hack to completely delete users
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
David Christofas committed Jan 27, 2022
1 parent e65d80f commit f01d56f
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions ocs/pkg/service/v0/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -410,10 +411,44 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) {
},
},
},
},
})
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{
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
}
}
lsRes, err = gwc.ListStorageSpaces(ctx, &provider.ListStorageSpacesRequest{
Filters: []*provider.ListStorageSpacesRequest_Filter{
{
Type: provider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE,
Term: &provider.ListStorageSpacesRequest_Filter_SpaceType{
SpaceType: "personal",
Type: provider.ListStorageSpacesRequest_Filter_TYPE_OWNER,
Term: &provider.ListStorageSpacesRequest_Filter_Owner{
Owner: &revauser.UserId{
Idp: o.config.IdentityManagement.Address,
OpaqueId: account.Id,
},
},
},
},
Expand All @@ -429,9 +464,13 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) {
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 {
Expand Down

0 comments on commit f01d56f

Please sign in to comment.