Skip to content
Snippets Groups Projects
Commit 989bd770 authored by Florent Gluck's avatar Florent Gluck
Browse files

Updated vms.DeleteVMAccess(..) so that even a user who doesn't exist anymore...

Updated vms.DeleteVMAccess(..) so that even a user who doesn't exist anymore can be removed from a VM's access.
Also, returns an error if trying to remove an user access for a user that's not present in the VM's accesses.
parent f9beec52
Branches
No related tags found
No related merge requests found
......@@ -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"))
......
......@@ -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
// 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment