From 6dcfb480c032f8b9d11725226c4cdc0866aea01d Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 23 Aug 2022 18:00:32 +0200 Subject: [PATCH] add home space deletion on user delete Signed-off-by: Christian Richter --- services/graph/pkg/service/v0/users.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/services/graph/pkg/service/v0/users.go b/services/graph/pkg/service/v0/users.go index d96007597ab..2202d5466f9 100644 --- a/services/graph/pkg/service/v0/users.go +++ b/services/graph/pkg/service/v0/users.go @@ -238,6 +238,29 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) { return } + currentUser := ctxpkg.ContextMustGetUser(r.Context()) + + opaque := utils.AppendPlainToOpaque(nil, "unrestricted", "T") + f := listStorageSpacesUserFilter(userID) + lspr, err := g.gatewayClient.ListStorageSpaces(r.Context(), &storageprovider.ListStorageSpacesRequest{ + Opaque: opaque, + Filters: []*storageprovider.ListStorageSpacesRequest_Filter{f}, + }) + for _, sp := range lspr.GetStorageSpaces() { + if sp.SpaceType == "personal" { + _, err := g.gatewayClient.DeleteStorageSpace(r.Context(), &storageprovider.DeleteStorageSpaceRequest{ + Opaque: opaque, + Id: &storageprovider.StorageSpaceId{ + OpaqueId: sp.Id.OpaqueId, + }, + }) + if err != nil { + errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "could not delete homespace") + } + continue + } + } + err = g.identityBackend.DeleteUser(r.Context(), userID) if err != nil { @@ -249,7 +272,6 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) { } } - currentUser := ctxpkg.ContextMustGetUser(r.Context()) g.publishEvent(events.UserDeleted{Executant: currentUser.Id, UserID: userID}) render.Status(r, http.StatusNoContent)