diff --git a/src/router/routerVMs.go b/src/router/routerVMs.go index dc634e3948f6b2177bf7a27a8d1b7dd00d1c0580..bd94f5cd8d03274ddcef34aca2b700b4fc3152d2 100644 --- a/src/router/routerVMs.go +++ b/src/router/routerVMs.go @@ -358,12 +358,9 @@ func (r *RouterVMs)DeleteVMAccessForUser(c echo.Context) error { return echo.NewHTTPError(http.StatusUnauthorized, msgInsufficientCaps) } - // Checks the user for which to modify the VM Access actually exists. + // Does not check that the user to remove the VM access for actually exists. + // Indeed, it might have been deleted. email := c.Param("email") - _, err = r.users.GetUserByEmail(email) - if err != nil { - return echo.NewHTTPError(http.StatusNotFound, err.Error()) - } // Retrieves the vmID of the VM to modify. vmID, err := uuid.Parse(c.Param("id")) diff --git a/src/vms/vms.go b/src/vms/vms.go index 475d6785707daa5f349eaad410880b1617967eee..7a1dc0124604552d7b3de8472bf291c2cf25e1fa 100644 --- a/src/vms/vms.go +++ b/src/vms/vms.go @@ -379,8 +379,12 @@ func (vms *VMs)DeleteVMAccess(vmID uuid.UUID, loggedUserEmail, userEmail string) return errors.New("Insufficient capability") } - // Removes the user from the Access map - delete(vm.Access, userEmail) + // Only removes the user from the Access map if it actually had an access. + if _, exists := vm.Access[userEmail]; exists { + delete(vm.Access, userEmail) + } else { + return errors.New("User "+userEmail+" has no VM access") + } if err = vms.updateVM(&vm); err != nil { return err