Skip to content

Commit

Permalink
add home space deletion on user delete
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Aug 24, 2022
1 parent 1565fe6 commit 6dcfb48
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion services/graph/pkg/service/v0/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 6dcfb48

Please sign in to comment.