Skip to content

Commit

Permalink
Fix home space deletion when deleting user by name
Browse files Browse the repository at this point in the history
DELETE requess on /graph/v1.0/users also work when specifing a user by
name. For deleting the home space in that case we need to get the User's
id from the backend first.

Fixes: owncloud#4195
  • Loading branch information
rhafer committed Sep 7, 2022
1 parent e4f9dfa commit f43a233
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions services/graph/pkg/service/v0/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,21 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) {
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "missing user id")
return
}
user, err := g.identityBackend.GetUser(r.Context(), userID, r.URL.Query())
if err != nil {
var errcode errorcode.Error
if errors.As(err, &errcode) {
errcode.Render(w, r)
} else {
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
}
return
}

currentUser := ctxpkg.ContextMustGetUser(r.Context())

opaque := utils.AppendPlainToOpaque(nil, "unrestricted", "T")
f := listStorageSpacesUserFilter(userID)
f := listStorageSpacesUserFilter(user.GetId())
lspr, err := g.gatewayClient.ListStorageSpaces(r.Context(), &storageprovider.ListStorageSpacesRequest{
Opaque: opaque,
Filters: []*storageprovider.ListStorageSpacesRequest_Filter{f},
Expand All @@ -277,7 +287,7 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) {
return
}
for _, sp := range lspr.GetStorageSpaces() {
if !(sp.SpaceType == "personal" && sp.Owner.Id.OpaqueId == userID) {
if !(sp.SpaceType == "personal" && sp.Owner.Id.OpaqueId == user.GetId()) {
continue
}
// TODO: check if request contains a homespace and if, check if requesting user has the privilege to
Expand Down Expand Up @@ -311,7 +321,7 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) {
break
}

err = g.identityBackend.DeleteUser(r.Context(), userID)
err = g.identityBackend.DeleteUser(r.Context(), user.GetId())

if err != nil {
var errcode errorcode.Error
Expand All @@ -323,7 +333,7 @@ func (g Graph) DeleteUser(w http.ResponseWriter, r *http.Request) {
}
}

g.publishEvent(events.UserDeleted{Executant: currentUser.Id, UserID: userID})
g.publishEvent(events.UserDeleted{Executant: currentUser.Id, UserID: user.GetId()})

render.Status(r, http.StatusNoContent)
render.NoContent(w, r)
Expand Down

0 comments on commit f43a233

Please sign in to comment.