删除附件.
()
| 950 | |
| 951 | // 删除附件. |
| 952 | func (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 | // 删除文档. |
| 991 | func (this *DocumentController) Delete() { |
nothing calls this directly
no test coverage detected