MCPcopy Index your code
hub / github.com/TruthHun/BookStack / RemoveAttachment

Method RemoveAttachment

controllers/DocumentController.go:952–988  ·  view source on GitHub ↗

删除附件.

()

Source from the content-addressed store, hash-verified

950
951// 删除附件.
952func (this *DocumentController) RemoveAttachment() {
953 attachId, _ := this.GetInt("attach_id")
954 if attachId <= 0 {
955 this.JsonResult(6001, "参数错误")
956 }
957
958 attach, err := models.NewAttachment().Find(attachId)
959 if err != nil {
960 beego.Error(err)
961 this.JsonResult(6002, "附件不存在")
962 }
963
964 document, err := models.NewDocument().Find(attach.DocumentId)
965 if err != nil {
966 beego.Error(err)
967 this.JsonResult(6003, "文档不存在")
968 }
969
970 if this.Member.Role != conf.MemberSuperRole {
971 rel, err := models.NewRelationship().FindByBookIdAndMemberId(document.BookId, this.Member.MemberId)
972 if err != nil {
973 beego.Error(err)
974 this.JsonResult(6004, "权限不足")
975 }
976 if rel.RoleId == conf.BookObserver {
977 this.JsonResult(6004, "权限不足")
978 }
979 }
980
981 if err = attach.Delete(); err != nil {
982 beego.Error(err)
983 this.JsonResult(6005, "删除失败")
984 }
985
986 os.Remove(strings.TrimLeft(attach.FilePath, "./"))
987 this.JsonResult(0, "ok", attach)
988}
989
990// 删除文档.
991func (this *DocumentController) Delete() {

Callers

nothing calls this directly

Calls 7

NewAttachmentFunction · 0.92
NewDocumentFunction · 0.92
NewRelationshipFunction · 0.92
JsonResultMethod · 0.80
FindMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected