✨ Cleanup shares when deleting user
This commit is contained in:
parent
8f49cccfeb
commit
b8181be096
21
cmd_user.go
21
cmd_user.go
|
@ -26,6 +26,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
@ -127,5 +128,23 @@ type CmdUserDelete struct {
|
|||
}
|
||||
|
||||
func (cmd CmdUserDelete) Run(app *app) error {
|
||||
return app.userStore.RemoveUser(cmd.Username)
|
||||
if err := app.userStore.RemoveUser(cmd.Username); err != nil {
|
||||
return fmt.Errorf("cannot remove user: %w", err)
|
||||
}
|
||||
|
||||
sharesByUser, err := app.shareStore.FindSharesByUser(cmd.Username)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get shares of user: %w", err)
|
||||
}
|
||||
allSuccessful := true
|
||||
for _, userShare := range sharesByUser {
|
||||
if err := app.shareStore.RemoveShare(userShare.UUID); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "User %q cannot be removed from Share %q: %v\n", cmd.Username, userShare.UUID.String(), err)
|
||||
allSuccessful = false
|
||||
}
|
||||
}
|
||||
if !allSuccessful {
|
||||
return fmt.Errorf("could not remove user from all shares")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue