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

Method DeleteHistory

controllers/DocumentController.go:1542–1594  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1540}
1541
1542func (this *DocumentController) DeleteHistory() {
1543
1544 this.TplName = "document/history.html"
1545
1546 identify := this.GetString("identify")
1547 docId, _ := this.GetInt("doc_id", 0)
1548 historyId, _ := this.GetInt("history_id", 0)
1549
1550 if historyId <= 0 {
1551 this.JsonResult(6001, "参数错误")
1552 }
1553 bookId := 0
1554 //如果是超级管理员则忽略权限判断
1555 if this.Member.IsAdministrator() {
1556 book, err := models.NewBook().FindByFieldFirst("identify", identify)
1557 if err != nil {
1558 beego.Error("FindByIdentify => ", err)
1559 this.JsonResult(6002, "书籍不存在或权限不足")
1560 }
1561 bookId = book.BookId
1562 } else {
1563 bookResult, err := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId)
1564
1565 if err != nil || bookResult.RoleId == conf.BookObserver {
1566 beego.Error("FindByIdentify => ", err)
1567 this.JsonResult(6002, "书籍不存在或权限不足")
1568 }
1569 bookId = bookResult.BookId
1570 }
1571
1572 if docId <= 0 {
1573 this.JsonResult(6001, "参数错误")
1574 }
1575
1576 doc, err := models.NewDocument().Find(docId)
1577 if err != nil {
1578 beego.Error("Delete => ", err)
1579 this.JsonResult(6001, "获取历史失败")
1580 }
1581
1582 //如果文档所属书籍错误
1583 if doc.BookId != bookId {
1584 this.JsonResult(6001, "参数错误")
1585 }
1586
1587 //err = models.NewDocumentHistory().Delete(history_id, doc_id)
1588 err = models.NewDocumentHistory().DeleteByHistoryId(historyId)
1589 if err != nil {
1590 beego.Error(err)
1591 this.JsonResult(6002, "删除失败")
1592 }
1593 this.JsonResult(0, "ok")
1594}
1595
1596func (this *DocumentController) RestoreHistory() {
1597

Callers

nothing calls this directly

Calls 10

NewBookFunction · 0.92
NewBookResultFunction · 0.92
NewDocumentFunction · 0.92
NewDocumentHistoryFunction · 0.92
JsonResultMethod · 0.80
IsAdministratorMethod · 0.80
DeleteByHistoryIdMethod · 0.80
FindByFieldFirstMethod · 0.45
FindByIdentifyMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected