2021-02-20 14:03:54 +00:00
|
|
|
|
package shroom
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/history"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/user"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// DeleteHypha deletes hypha and makes a history record about that.
|
|
|
|
|
func DeleteHypha(u *user.User, h *hyphae.Hypha) (hop *history.HistoryOp, errtitle string) {
|
|
|
|
|
hop = history.Operation(history.TypeDeleteHypha)
|
|
|
|
|
|
|
|
|
|
if err, errtitle := CanDelete(u, h); errtitle != "" {
|
2021-02-26 16:43:45 +00:00
|
|
|
|
hop.WithErrAbort(err)
|
2021-02-20 14:03:54 +00:00
|
|
|
|
return hop, errtitle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hop.
|
|
|
|
|
WithFilesRemoved(h.TextPath, h.BinaryPath).
|
|
|
|
|
WithMsg(fmt.Sprintf("Delete ‘%s’", h.Name)).
|
|
|
|
|
WithUser(u).
|
|
|
|
|
Apply()
|
|
|
|
|
if !hop.HasErrors() {
|
|
|
|
|
h.Delete()
|
|
|
|
|
}
|
|
|
|
|
return hop, ""
|
|
|
|
|
}
|