|
@@ -1,6 +1,7 @@
|
|
package controllers
|
|
package controllers
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"html/template"
|
|
"html/template"
|
|
@@ -14,9 +15,9 @@ import (
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
- "github.com/astaxie/beego"
|
|
|
|
- "github.com/astaxie/beego/logs"
|
|
|
|
- "github.com/astaxie/beego/orm"
|
|
|
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
|
+ "github.com/beego/beego/v2/core/logs"
|
|
|
|
+ "github.com/beego/beego/v2/server/web"
|
|
"github.com/boombuler/barcode"
|
|
"github.com/boombuler/barcode"
|
|
"github.com/boombuler/barcode/qr"
|
|
"github.com/boombuler/barcode/qr"
|
|
"github.com/mindoc-org/mindoc/conf"
|
|
"github.com/mindoc-org/mindoc/conf"
|
|
@@ -26,7 +27,7 @@ import (
|
|
"github.com/mindoc-org/mindoc/utils/filetil"
|
|
"github.com/mindoc-org/mindoc/utils/filetil"
|
|
"github.com/mindoc-org/mindoc/utils/gopool"
|
|
"github.com/mindoc-org/mindoc/utils/gopool"
|
|
"github.com/mindoc-org/mindoc/utils/pagination"
|
|
"github.com/mindoc-org/mindoc/utils/pagination"
|
|
- "gopkg.in/russross/blackfriday.v2"
|
|
|
|
|
|
+ "github.com/russross/blackfriday/v2"
|
|
)
|
|
)
|
|
|
|
|
|
// DocumentController struct
|
|
// DocumentController struct
|
|
@@ -85,7 +86,7 @@ func (c *DocumentController) Index() {
|
|
if err == orm.ErrNoRows {
|
|
if err == orm.ErrNoRows {
|
|
c.ShowErrorPage(404, "当前项目没有文档")
|
|
c.ShowErrorPage(404, "当前项目没有文档")
|
|
} else {
|
|
} else {
|
|
- beego.Error("生成项目文档树时出错 -> ", err)
|
|
|
|
|
|
+ logs.Error("生成项目文档树时出错 -> ", err)
|
|
c.ShowErrorPage(500, "生成项目文档树时出错")
|
|
c.ShowErrorPage(500, "生成项目文档树时出错")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -122,7 +123,7 @@ func (c *DocumentController) Read() {
|
|
if docId, err := strconv.Atoi(id); err == nil {
|
|
if docId, err := strconv.Atoi(id); err == nil {
|
|
doc, err = doc.FromCacheById(docId)
|
|
doc, err = doc.FromCacheById(docId)
|
|
if err != nil || doc == nil {
|
|
if err != nil || doc == nil {
|
|
- beego.Error("从缓存中读取文档时失败 ->", err)
|
|
|
|
|
|
+ logs.Error("从缓存中读取文档时失败 ->", err)
|
|
c.ShowErrorPage(404, "文档不存在或已删除")
|
|
c.ShowErrorPage(404, "文档不存在或已删除")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -132,7 +133,7 @@ func (c *DocumentController) Read() {
|
|
if err == orm.ErrNoRows {
|
|
if err == orm.ErrNoRows {
|
|
c.ShowErrorPage(404, "文档不存在或已删除")
|
|
c.ShowErrorPage(404, "文档不存在或已删除")
|
|
} else {
|
|
} else {
|
|
- beego.Error("从缓存查询文档时出错 ->", err)
|
|
|
|
|
|
+ logs.Error("从缓存查询文档时出错 ->", err)
|
|
c.ShowErrorPage(500, "未知异常")
|
|
c.ShowErrorPage(500, "未知异常")
|
|
}
|
|
}
|
|
return
|
|
return
|
|
@@ -183,7 +184,7 @@ func (c *DocumentController) Read() {
|
|
tree, err := models.NewDocument().CreateDocumentTreeForHtml(bookResult.BookId, doc.DocumentId)
|
|
tree, err := models.NewDocument().CreateDocumentTreeForHtml(bookResult.BookId, doc.DocumentId)
|
|
|
|
|
|
if err != nil && err != orm.ErrNoRows {
|
|
if err != nil && err != orm.ErrNoRows {
|
|
- beego.Error("生成项目文档树时出错 ->", err)
|
|
|
|
|
|
+ logs.Error("生成项目文档树时出错 ->", err)
|
|
|
|
|
|
c.ShowErrorPage(500, "生成项目文档树时出错")
|
|
c.ShowErrorPage(500, "生成项目文档树时出错")
|
|
}
|
|
}
|
|
@@ -223,7 +224,7 @@ func (c *DocumentController) Edit() {
|
|
if err == orm.ErrNoRows || err == models.ErrPermissionDenied {
|
|
if err == orm.ErrNoRows || err == models.ErrPermissionDenied {
|
|
c.ShowErrorPage(403, "项目不存在或没有权限")
|
|
c.ShowErrorPage(403, "项目不存在或没有权限")
|
|
} else {
|
|
} else {
|
|
- beego.Error("查询项目时出错 -> ", err)
|
|
|
|
|
|
+ logs.Error("查询项目时出错 -> ", err)
|
|
c.ShowErrorPage(500, "查询项目时出错")
|
|
c.ShowErrorPage(500, "查询项目时出错")
|
|
}
|
|
}
|
|
return
|
|
return
|
|
@@ -253,7 +254,7 @@ func (c *DocumentController) Edit() {
|
|
trees, err := models.NewDocument().FindDocumentTree(bookResult.BookId)
|
|
trees, err := models.NewDocument().FindDocumentTree(bookResult.BookId)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("FindDocumentTree => ", err)
|
|
|
|
|
|
+ logs.Error("FindDocumentTree => ", err)
|
|
} else {
|
|
} else {
|
|
if len(trees) > 0 {
|
|
if len(trees) > 0 {
|
|
if jtree, err := json.Marshal(trees); err == nil {
|
|
if jtree, err := json.Marshal(trees); err == nil {
|
|
@@ -264,7 +265,7 @@ func (c *DocumentController) Edit() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- c.Data["BaiDuMapKey"] = beego.AppConfig.DefaultString("baidumapkey", "")
|
|
|
|
|
|
+ c.Data["BaiDuMapKey"] = web.AppConfig.DefaultString("baidumapkey", "")
|
|
|
|
|
|
if conf.GetUploadFileSize() > 0 {
|
|
if conf.GetUploadFileSize() > 0 {
|
|
c.Data["UploadFileSize"] = conf.GetUploadFileSize()
|
|
c.Data["UploadFileSize"] = conf.GetUploadFileSize()
|
|
@@ -296,7 +297,7 @@ func (c *DocumentController) Create() {
|
|
if c.Member.IsAdministrator() {
|
|
if c.Member.IsAdministrator() {
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -305,7 +306,7 @@ func (c *DocumentController) Create() {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
|
|
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("FindByIdentify => ", err)
|
|
|
|
|
|
+ logs.Error("FindByIdentify => ", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -349,7 +350,7 @@ func (c *DocumentController) Create() {
|
|
}
|
|
}
|
|
|
|
|
|
if err := document.InsertOrUpdate(); err != nil {
|
|
if err := document.InsertOrUpdate(); err != nil {
|
|
- beego.Error("添加或更新文档时出错 -> ", err)
|
|
|
|
|
|
+ logs.Error("添加或更新文档时出错 -> ", err)
|
|
c.JsonResult(6005, "保存失败")
|
|
c.JsonResult(6005, "保存失败")
|
|
} else {
|
|
} else {
|
|
c.JsonResult(0, "ok", document)
|
|
c.JsonResult(0, "ok", document)
|
|
@@ -417,7 +418,7 @@ func (c *DocumentController) Upload() {
|
|
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("DocumentController.Edit => ", err)
|
|
|
|
|
|
+ logs.Error("DocumentController.Edit => ", err)
|
|
if err == orm.ErrNoRows {
|
|
if err == orm.ErrNoRows {
|
|
c.JsonResult(6006, "权限不足")
|
|
c.JsonResult(6006, "权限不足")
|
|
}
|
|
}
|
|
@@ -461,7 +462,7 @@ func (c *DocumentController) Upload() {
|
|
err = c.SaveToFile(name, filePath)
|
|
err = c.SaveToFile(name, filePath)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("保存文件失败 -> ", err)
|
|
|
|
|
|
+ logs.Error("保存文件失败 -> ", err)
|
|
c.JsonResult(6005, "保存文件失败")
|
|
c.JsonResult(6005, "保存文件失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -494,7 +495,7 @@ func (c *DocumentController) Upload() {
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
os.Remove(filePath)
|
|
os.Remove(filePath)
|
|
- beego.Error("文件保存失败 ->", err)
|
|
|
|
|
|
+ logs.Error("文件保存失败 ->", err)
|
|
c.JsonResult(6006, "文件保存失败")
|
|
c.JsonResult(6006, "文件保存失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -502,7 +503,7 @@ func (c *DocumentController) Upload() {
|
|
attachment.HttpPath = conf.URLForNotHost("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
|
|
attachment.HttpPath = conf.URLForNotHost("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
|
|
|
|
|
|
if err := attachment.Update(); err != nil {
|
|
if err := attachment.Update(); err != nil {
|
|
- beego.Error("保存文件失败 ->", err)
|
|
|
|
|
|
+ logs.Error("保存文件失败 ->", err)
|
|
c.JsonResult(6005, "保存文件失败")
|
|
c.JsonResult(6005, "保存文件失败")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -547,7 +548,7 @@ func (c *DocumentController) DownloadAttachment() {
|
|
if err == orm.ErrNoRows {
|
|
if err == orm.ErrNoRows {
|
|
c.ShowErrorPage(404, "项目不存在或已删除")
|
|
c.ShowErrorPage(404, "项目不存在或已删除")
|
|
} else {
|
|
} else {
|
|
- beego.Error("查找项目时出错 ->", err)
|
|
|
|
|
|
+ logs.Error("查找项目时出错 ->", err)
|
|
c.ShowErrorPage(500, "系统错误")
|
|
c.ShowErrorPage(500, "系统错误")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -569,7 +570,7 @@ func (c *DocumentController) DownloadAttachment() {
|
|
attachment, err := models.NewAttachment().Find(attachId)
|
|
attachment, err := models.NewAttachment().Find(attachId)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("查找附件时出错 -> ", err)
|
|
|
|
|
|
+ logs.Error("查找附件时出错 -> ", err)
|
|
if err == orm.ErrNoRows {
|
|
if err == orm.ErrNoRows {
|
|
c.ShowErrorPage(404, "附件不存在或已删除")
|
|
c.ShowErrorPage(404, "附件不存在或已删除")
|
|
} else {
|
|
} else {
|
|
@@ -597,21 +598,21 @@ func (c *DocumentController) RemoveAttachment() {
|
|
attach, err := models.NewAttachment().Find(attachId)
|
|
attach, err := models.NewAttachment().Find(attachId)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6002, "附件不存在")
|
|
c.JsonResult(6002, "附件不存在")
|
|
}
|
|
}
|
|
|
|
|
|
document, err := models.NewDocument().Find(attach.DocumentId)
|
|
document, err := models.NewDocument().Find(attach.DocumentId)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6003, "文档不存在")
|
|
c.JsonResult(6003, "文档不存在")
|
|
}
|
|
}
|
|
|
|
|
|
if c.Member.Role != conf.MemberSuperRole {
|
|
if c.Member.Role != conf.MemberSuperRole {
|
|
rel, err := models.NewRelationship().FindByBookIdAndMemberId(document.BookId, c.Member.MemberId)
|
|
rel, err := models.NewRelationship().FindByBookIdAndMemberId(document.BookId, c.Member.MemberId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6004, "权限不足")
|
|
c.JsonResult(6004, "权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -622,7 +623,7 @@ func (c *DocumentController) RemoveAttachment() {
|
|
|
|
|
|
err = attach.Delete()
|
|
err = attach.Delete()
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6005, "删除失败")
|
|
c.JsonResult(6005, "删除失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -644,7 +645,7 @@ func (c *DocumentController) Delete() {
|
|
if c.Member.IsAdministrator() {
|
|
if c.Member.IsAdministrator() {
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("FindByIdentify => ", err)
|
|
|
|
|
|
+ logs.Error("FindByIdentify => ", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -653,7 +654,7 @@ func (c *DocumentController) Delete() {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
|
|
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("FindByIdentify => ", err)
|
|
|
|
|
|
+ logs.Error("FindByIdentify => ", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -667,7 +668,7 @@ func (c *DocumentController) Delete() {
|
|
doc, err := models.NewDocument().Find(docId)
|
|
doc, err := models.NewDocument().Find(docId)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("Delete => ", err)
|
|
|
|
|
|
+ logs.Error("Delete => ", err)
|
|
c.JsonResult(6003, "删除失败")
|
|
c.JsonResult(6003, "删除失败")
|
|
}
|
|
}
|
|
// 如果文档所属项目错误
|
|
// 如果文档所属项目错误
|
|
@@ -714,7 +715,7 @@ func (c *DocumentController) Content() {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
|
|
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("项目不存在或权限不足 -> ", err)
|
|
|
|
|
|
+ logs.Error("项目不存在或权限不足 -> ", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -744,7 +745,7 @@ func (c *DocumentController) Content() {
|
|
}
|
|
}
|
|
|
|
|
|
if doc.Version != version && !strings.EqualFold(isCover, "yes") {
|
|
if doc.Version != version && !strings.EqualFold(isCover, "yes") {
|
|
- beego.Info("%d|", version, doc.Version)
|
|
|
|
|
|
+ logs.Info("%d|", version, doc.Version)
|
|
c.JsonResult(6005, "文档已被修改确定要覆盖吗?")
|
|
c.JsonResult(6005, "文档已被修改确定要覆盖吗?")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -771,7 +772,7 @@ func (c *DocumentController) Content() {
|
|
doc.ModifyAt = c.Member.MemberId
|
|
doc.ModifyAt = c.Member.MemberId
|
|
|
|
|
|
if err := doc.InsertOrUpdate(); err != nil {
|
|
if err := doc.InsertOrUpdate(); err != nil {
|
|
- beego.Error("InsertOrUpdate => ", err)
|
|
|
|
|
|
+ logs.Error("InsertOrUpdate => ", err)
|
|
c.JsonResult(6006, "保存失败")
|
|
c.JsonResult(6006, "保存失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -781,7 +782,7 @@ func (c *DocumentController) Content() {
|
|
if c.EnableDocumentHistory && cryptil.Md5Crypt(history.Markdown) != cryptil.Md5Crypt(doc.Markdown) {
|
|
if c.EnableDocumentHistory && cryptil.Md5Crypt(history.Markdown) != cryptil.Md5Crypt(doc.Markdown) {
|
|
_, err = history.InsertOrUpdate()
|
|
_, err = history.InsertOrUpdate()
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("DocumentHistory InsertOrUpdate => ", err)
|
|
|
|
|
|
+ logs.Error("DocumentHistory InsertOrUpdate => ", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}(history)
|
|
}(history)
|
|
@@ -841,7 +842,7 @@ func (c *DocumentController) Export() {
|
|
if err == orm.ErrNoRows {
|
|
if err == orm.ErrNoRows {
|
|
c.ShowErrorPage(404, "项目不存在")
|
|
c.ShowErrorPage(404, "项目不存在")
|
|
} else {
|
|
} else {
|
|
- beego.Error("查找项目时出错 ->", err)
|
|
|
|
|
|
+ logs.Error("查找项目时出错 ->", err)
|
|
c.ShowErrorPage(500, "查找项目时出错")
|
|
c.ShowErrorPage(500, "查找项目时出错")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -861,7 +862,7 @@ func (c *DocumentController) Export() {
|
|
if bookResult.Editor != "markdown" {
|
|
if bookResult.Editor != "markdown" {
|
|
c.ShowErrorPage(500, "当前项目不支持Markdown编辑器")
|
|
c.ShowErrorPage(500, "当前项目不支持Markdown编辑器")
|
|
}
|
|
}
|
|
- p, err := bookResult.ExportMarkdown(c.CruSession.SessionID())
|
|
|
|
|
|
+ p, err := bookResult.ExportMarkdown(c.CruSession.SessionID(context.TODO()))
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
c.ShowErrorPage(500, "导出文档失败")
|
|
c.ShowErrorPage(500, "导出文档失败")
|
|
@@ -896,7 +897,7 @@ func (c *DocumentController) Export() {
|
|
c.Abort("200")
|
|
c.Abort("200")
|
|
|
|
|
|
} else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi" {
|
|
} else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi" {
|
|
- if err := models.BackgroundConvert(c.CruSession.SessionID(), bookResult); err != nil && err != gopool.ErrHandlerIsExist {
|
|
|
|
|
|
+ if err := models.BackgroundConvert(c.CruSession.SessionID(context.TODO()), bookResult); err != nil && err != gopool.ErrHandlerIsExist {
|
|
c.ShowErrorPage(500, "导出失败,请查看系统日志")
|
|
c.ShowErrorPage(500, "导出失败,请查看系统日志")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -922,13 +923,13 @@ func (c *DocumentController) QrCode() {
|
|
uri := conf.URLFor("DocumentController.Index", ":key", identify)
|
|
uri := conf.URLFor("DocumentController.Index", ":key", identify)
|
|
code, err := qr.Encode(uri, qr.L, qr.Unicode)
|
|
code, err := qr.Encode(uri, qr.L, qr.Unicode)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("生成二维码失败 ->", err)
|
|
|
|
|
|
+ logs.Error("生成二维码失败 ->", err)
|
|
c.ShowErrorPage(500, "生成二维码失败")
|
|
c.ShowErrorPage(500, "生成二维码失败")
|
|
}
|
|
}
|
|
|
|
|
|
code, err = barcode.Scale(code, 150, 150)
|
|
code, err = barcode.Scale(code, 150, 150)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("生成二维码失败 ->", err)
|
|
|
|
|
|
+ logs.Error("生成二维码失败 ->", err)
|
|
c.ShowErrorPage(500, "生成二维码失败")
|
|
c.ShowErrorPage(500, "生成二维码失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -938,7 +939,7 @@ func (c *DocumentController) QrCode() {
|
|
|
|
|
|
err = png.Encode(c.Ctx.ResponseWriter, code)
|
|
err = png.Encode(c.Ctx.ResponseWriter, code)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("生成二维码失败 ->", err)
|
|
|
|
|
|
+ logs.Error("生成二维码失败 ->", err)
|
|
c.ShowErrorPage(500, "生成二维码失败")
|
|
c.ShowErrorPage(500, "生成二维码失败")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -964,7 +965,7 @@ func (c *DocumentController) Search() {
|
|
|
|
|
|
docs, err := models.NewDocumentSearchResult().SearchDocument(keyword, bookResult.BookId)
|
|
docs, err := models.NewDocumentSearchResult().SearchDocument(keyword, bookResult.BookId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6002, "搜索结果错误")
|
|
c.JsonResult(6002, "搜索结果错误")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -998,7 +999,7 @@ func (c *DocumentController) History() {
|
|
if c.Member.IsAdministrator() {
|
|
if c.Member.IsAdministrator() {
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("查找项目失败 ->", err)
|
|
|
|
|
|
+ logs.Error("查找项目失败 ->", err)
|
|
c.Data["ErrorMessage"] = "项目不存在或权限不足"
|
|
c.Data["ErrorMessage"] = "项目不存在或权限不足"
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1008,7 +1009,7 @@ func (c *DocumentController) History() {
|
|
} else {
|
|
} else {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("查找项目失败 ->", err)
|
|
|
|
|
|
+ logs.Error("查找项目失败 ->", err)
|
|
c.Data["ErrorMessage"] = "项目不存在或权限不足"
|
|
c.Data["ErrorMessage"] = "项目不存在或权限不足"
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1024,7 +1025,7 @@ func (c *DocumentController) History() {
|
|
|
|
|
|
doc, err := models.NewDocument().Find(docId)
|
|
doc, err := models.NewDocument().Find(docId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("Delete => ", err)
|
|
|
|
|
|
+ logs.Error("Delete => ", err)
|
|
c.Data["ErrorMessage"] = "获取历史失败"
|
|
c.Data["ErrorMessage"] = "获取历史失败"
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1037,7 +1038,7 @@ func (c *DocumentController) History() {
|
|
|
|
|
|
histories, totalCount, err := models.NewDocumentHistory().FindToPager(docId, pageIndex, conf.PageSize)
|
|
histories, totalCount, err := models.NewDocumentHistory().FindToPager(docId, pageIndex, conf.PageSize)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("分页查找文档历史失败 ->", err)
|
|
|
|
|
|
+ logs.Error("分页查找文档历史失败 ->", err)
|
|
c.Data["ErrorMessage"] = "获取历史失败"
|
|
c.Data["ErrorMessage"] = "获取历史失败"
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1071,7 +1072,7 @@ func (c *DocumentController) DeleteHistory() {
|
|
if c.Member.IsAdministrator() {
|
|
if c.Member.IsAdministrator() {
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("查找项目失败 ->", err)
|
|
|
|
|
|
+ logs.Error("查找项目失败 ->", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1079,7 +1080,7 @@ func (c *DocumentController) DeleteHistory() {
|
|
} else {
|
|
} else {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("查找项目失败 ->", err)
|
|
|
|
|
|
+ logs.Error("查找项目失败 ->", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1092,7 +1093,7 @@ func (c *DocumentController) DeleteHistory() {
|
|
|
|
|
|
doc, err := models.NewDocument().Find(docId)
|
|
doc, err := models.NewDocument().Find(docId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("Delete => ", err)
|
|
|
|
|
|
+ logs.Error("Delete => ", err)
|
|
c.JsonResult(6001, "获取历史失败")
|
|
c.JsonResult(6001, "获取历史失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1103,7 +1104,7 @@ func (c *DocumentController) DeleteHistory() {
|
|
|
|
|
|
err = models.NewDocumentHistory().Delete(historyId, docId)
|
|
err = models.NewDocumentHistory().Delete(historyId, docId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6002, "删除失败")
|
|
c.JsonResult(6002, "删除失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1129,7 +1130,7 @@ func (c *DocumentController) RestoreHistory() {
|
|
if c.Member.IsAdministrator() {
|
|
if c.Member.IsAdministrator() {
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("FindByIdentify => ", err)
|
|
|
|
|
|
+ logs.Error("FindByIdentify => ", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1137,7 +1138,7 @@ func (c *DocumentController) RestoreHistory() {
|
|
} else {
|
|
} else {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("FindByIdentify => ", err)
|
|
|
|
|
|
+ logs.Error("FindByIdentify => ", err)
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
c.JsonResult(6002, "项目不存在或权限不足")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1150,7 +1151,7 @@ func (c *DocumentController) RestoreHistory() {
|
|
|
|
|
|
doc, err := models.NewDocument().Find(docId)
|
|
doc, err := models.NewDocument().Find(docId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("Delete => ", err)
|
|
|
|
|
|
+ logs.Error("Delete => ", err)
|
|
c.JsonResult(6001, "获取历史失败")
|
|
c.JsonResult(6001, "获取历史失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1161,7 +1162,7 @@ func (c *DocumentController) RestoreHistory() {
|
|
|
|
|
|
err = models.NewDocumentHistory().Restore(historyId, docId, c.Member.MemberId)
|
|
err = models.NewDocumentHistory().Restore(historyId, docId, c.Member.MemberId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.JsonResult(6002, "删除失败")
|
|
c.JsonResult(6002, "删除失败")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1183,7 +1184,7 @@ func (c *DocumentController) Compare() {
|
|
if c.Member.IsAdministrator() {
|
|
if c.Member.IsAdministrator() {
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("DocumentController.Compare => ", err)
|
|
|
|
|
|
+ logs.Error("DocumentController.Compare => ", err)
|
|
c.ShowErrorPage(403, "权限不足")
|
|
c.ShowErrorPage(403, "权限不足")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1194,7 +1195,7 @@ func (c *DocumentController) Compare() {
|
|
} else {
|
|
} else {
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
if err != nil || bookResult.RoleId == conf.BookObserver {
|
|
- beego.Error("FindByIdentify => ", err)
|
|
|
|
|
|
+ logs.Error("FindByIdentify => ", err)
|
|
c.ShowErrorPage(403, "权限不足")
|
|
c.ShowErrorPage(403, "权限不足")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -1210,7 +1211,7 @@ func (c *DocumentController) Compare() {
|
|
|
|
|
|
history, err := models.NewDocumentHistory().Find(historyId)
|
|
history, err := models.NewDocumentHistory().Find(historyId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("DocumentController.Compare => ", err)
|
|
|
|
|
|
+ logs.Error("DocumentController.Compare => ", err)
|
|
c.ShowErrorPage(60003, err.Error())
|
|
c.ShowErrorPage(60003, err.Error())
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1237,7 +1238,7 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error(err)
|
|
|
|
|
|
+ logs.Error(err)
|
|
c.ShowErrorPage(500, "项目不存在")
|
|
c.ShowErrorPage(500, "项目不存在")
|
|
}
|
|
}
|
|
bookResult := models.NewBookResult().ToBookResult(*book)
|
|
bookResult := models.NewBookResult().ToBookResult(*book)
|
|
@@ -1262,7 +1263,7 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
|
if token != "" && strings.EqualFold(token, book.PrivateToken) {
|
|
if token != "" && strings.EqualFold(token, book.PrivateToken) {
|
|
c.SetSession(identify, token)
|
|
c.SetSession(identify, token)
|
|
} else if token, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(token, book.PrivateToken) {
|
|
} else if token, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(token, book.PrivateToken) {
|
|
- beego.Info("尝试访问文档但权限不足 ->", identify, token)
|
|
|
|
|
|
+ logs.Info("尝试访问文档但权限不足 ->", identify, token)
|
|
c.ShowErrorPage(403, "权限不足")
|
|
c.ShowErrorPage(403, "权限不足")
|
|
}
|
|
}
|
|
} else if password := c.GetString("bPassword", ""); !isOk && book.BookPassword != "" && password != "" {
|
|
} else if password := c.GetString("bPassword", ""); !isOk && book.BookPassword != "" && password != "" {
|
|
@@ -1282,12 +1283,12 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
|
if password, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(password, book.BookPassword) {
|
|
if password, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(password, book.BookPassword) {
|
|
body, err := c.ExecuteViewPathTemplate("document/document_password.tpl", map[string]string{"Identify": book.Identify})
|
|
body, err := c.ExecuteViewPathTemplate("document/document_password.tpl", map[string]string{"Identify": book.Identify})
|
|
if err != nil {
|
|
if err != nil {
|
|
- beego.Error("显示密码页面失败 ->", err)
|
|
|
|
|
|
+ logs.Error("显示密码页面失败 ->", err)
|
|
}
|
|
}
|
|
c.CustomAbort(200, body)
|
|
c.CustomAbort(200, body)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- beego.Info("尝试访问文档但权限不足 ->", identify, token)
|
|
|
|
|
|
+ logs.Info("尝试访问文档但权限不足 ->", identify, token)
|
|
c.ShowErrorPage(403, "权限不足")
|
|
c.ShowErrorPage(403, "权限不足")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1298,8 +1299,8 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
|
}
|
|
}
|
|
|
|
|
|
func promptUserToLogIn(c *DocumentController) {
|
|
func promptUserToLogIn(c *DocumentController) {
|
|
- beego.Info("Access " + c.Ctx.Request.URL.RequestURI() + " not permitted.")
|
|
|
|
- beego.Info(" Access will be redirected to login page(SessionId: " + c.CruSession.SessionID() + ").")
|
|
|
|
|
|
+ logs.Info("Access " + c.Ctx.Request.URL.RequestURI() + " not permitted.")
|
|
|
|
+ logs.Info(" Access will be redirected to login page(SessionId: " + c.CruSession.SessionID(context.TODO()) + ").")
|
|
|
|
|
|
if c.IsAjax() {
|
|
if c.IsAjax() {
|
|
c.JsonResult(6000, "请重新登录。")
|
|
c.JsonResult(6000, "请重新登录。")
|