实现项目和文档锁定功能

This commit is contained in:
Minho
2018-04-09 10:53:28 +08:00
parent cb458e6a63
commit 7a05cdfea4
4 changed files with 43 additions and 25 deletions

View File

@@ -587,7 +587,9 @@ func (c *DocumentController) RemoveAttachment() {
beego.Error(err)
c.JsonResult(6003, "文档不存在")
}
if document.IsLock == 1 {
c.JsonResult(6004,"不能编辑已锁定的文档")
}
if c.Member.Role != conf.MemberSuperRole {
rel, err := models.NewRelationship().FindByBookIdAndMemberId(document.BookId, c.Member.MemberId)
if err != nil {
@@ -679,6 +681,8 @@ func (c *DocumentController) Content() {
bookId := 0
autoRelease := false
isLock := false
// 如果是超级管理员,则忽略权限
if c.Member.IsAdministrator() {
@@ -686,9 +690,9 @@ func (c *DocumentController) Content() {
if err != nil {
c.JsonResult(6002, "项目不存在或权限不足")
}
bookId = book.BookId
autoRelease = book.AutoRelease == 1
isLock = book.IsLock == 1
} else {
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
@@ -696,9 +700,12 @@ func (c *DocumentController) Content() {
beego.Error("FindByIdentify => ", err)
c.JsonResult(6002, "项目不存在或权限不足")
}
if bookResult.IsLock {
c.JsonResult(6003,"锁定的项目不能编辑")
}
bookId = bookResult.BookId
autoRelease = bookResult.AutoRelease
isLock = bookResult.IsLock
}
if docId <= 0 {
@@ -706,6 +713,11 @@ func (c *DocumentController) Content() {
}
if c.Ctx.Input.IsPost() {
if isLock {
//如果项目锁定了,则不能编辑
c.JsonResult(6003,"锁定的项目不能编辑")
}
markdown := strings.TrimSpace(c.GetString("markdown", ""))
content := c.GetString("html")
version, _ := c.GetInt64("version", 0)

View File

@@ -66,6 +66,8 @@ type Book struct {
HistoryCount int `orm:"column(history_count);type(int);default(0)" json:"history_count"`
//是否启用分享0启用/1不启用
IsEnableShare int `orm:"column(is_enable_share);type(int);default(0)" json:"is_enable_share"`
//是否锁定,锁定状态下不能编辑,0 否/1 是
IsLock int `orm:"column(is_lock);type(int);default(0)" json:"is_lock"`
MemberId int `orm:"column(member_id);size(100)" json:"member_id"`
ModifyTime time.Time `orm:"type(datetime);column(modify_time);null;auto_now" json:"modify_time"`
Version int64 `orm:"type(bigint);column(version)" json:"version"`

View File

@@ -59,6 +59,7 @@ type BookResult struct {
LastModifyText string `json:"last_modify_text"`
IsDisplayComment bool `json:"is_display_comment"`
IsDownload bool `json:"is_download"`
IsLock bool `json:"is_lock"`
}
func NewBookResult() *BookResult {
@@ -162,29 +163,30 @@ func (m *BookResult) FindToPager(pageIndex, pageSize int) (books []*BookResult,
//实体转换
func (m *BookResult) ToBookResult(book Book) *BookResult {
m.BookId = book.BookId
m.BookName = book.BookName
m.Identify = book.Identify
m.OrderIndex = book.OrderIndex
m.Description = strings.Replace(book.Description, "\r\n", "<br/>", -1)
m.PrivatelyOwned = book.PrivatelyOwned
m.PrivateToken = book.PrivateToken
m.DocCount = book.DocCount
m.CommentStatus = book.CommentStatus
m.CommentCount = book.CommentCount
m.CreateTime = book.CreateTime
m.ModifyTime = book.ModifyTime
m.Cover = book.Cover
m.Label = book.Label
m.Status = book.Status
m.Editor = book.Editor
m.Theme = book.Theme
m.AutoRelease = book.AutoRelease == 1
m.IsEnableShare = book.IsEnableShare == 0
m.BookId = book.BookId
m.BookName = book.BookName
m.Identify = book.Identify
m.OrderIndex = book.OrderIndex
m.Description = strings.Replace(book.Description, "\r\n", "<br/>", -1)
m.PrivatelyOwned = book.PrivatelyOwned
m.PrivateToken = book.PrivateToken
m.DocCount = book.DocCount
m.CommentStatus = book.CommentStatus
m.CommentCount = book.CommentCount
m.CreateTime = book.CreateTime
m.ModifyTime = book.ModifyTime
m.Cover = book.Cover
m.Label = book.Label
m.Status = book.Status
m.Editor = book.Editor
m.Theme = book.Theme
m.AutoRelease = book.AutoRelease == 1
m.IsEnableShare = book.IsEnableShare == 0
m.Publisher = book.Publisher
m.HistoryCount = book.HistoryCount
m.IsDownload = book.IsDownload == 0
m.IsLock = book.IsLock == 1
m.IsUseFirstDocument = book.IsUseFirstDocument == 1
m.Publisher = book.Publisher
m.HistoryCount = book.HistoryCount
m.IsDownload = book.IsDownload == 0
if book.Theme == "" {
m.Theme = "default"

View File

@@ -33,6 +33,8 @@ type Document struct {
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
Version int64 `orm:"type(bigint);column(version)" json:"version"`
//是否锁定,锁定状态下不能编辑,0 否/1 是
IsLock int `orm:"column(is_lock);type(int);default(0)" json:"is_lock"`
AttachList []*Attachment `orm:"-" json:"attach"`
}