mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-18 09:44:26 +08:00
User
refactor and update i18n, to be continue
This commit is contained in:
@@ -37,7 +37,7 @@ func (c *BookController) Index() {
|
||||
|
||||
pageIndex, _ := c.GetInt("page", 1)
|
||||
|
||||
books, totalCount, err := models.NewBook().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId)
|
||||
books, totalCount, err := models.NewBook().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId, c.Lang)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("BookController.Index => ", err)
|
||||
@@ -79,7 +79,7 @@ func (c *BookController) Dashboard() {
|
||||
c.Abort("404")
|
||||
}
|
||||
|
||||
book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId)
|
||||
book, err := models.NewBookResult().SetLang(c.Lang).FindByIdentify(key, c.Member.MemberId)
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.Abort("403")
|
||||
@@ -204,7 +204,7 @@ func (c *BookController) SaveBook() {
|
||||
book.AutoSave = 0
|
||||
}
|
||||
if err := book.Update(); err != nil {
|
||||
c.JsonResult(6006, "保存失败")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
bookResult.BookName = bookName
|
||||
bookResult.Description = description
|
||||
@@ -221,7 +221,7 @@ func (c *BookController) PrivatelyOwned() {
|
||||
status := c.GetString("status")
|
||||
|
||||
if status != "open" && status != "close" {
|
||||
c.JsonResult(6003, "参数错误")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
state := 0
|
||||
if status == "open" {
|
||||
@@ -238,13 +238,13 @@ func (c *BookController) PrivatelyOwned() {
|
||||
}
|
||||
//只有创始人才能变更私有状态
|
||||
if bookResult.RoleId != conf.BookFounder {
|
||||
c.JsonResult(6002, "权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
|
||||
book, err := models.NewBook().Find(bookResult.BookId)
|
||||
|
||||
if err != nil {
|
||||
c.JsonResult(6005, "项目不存在")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
return
|
||||
}
|
||||
book.PrivatelyOwned = state
|
||||
@@ -253,7 +253,7 @@ func (c *BookController) PrivatelyOwned() {
|
||||
|
||||
if err != nil {
|
||||
logs.Error("PrivatelyOwned => ", err)
|
||||
c.JsonResult(6004, "保存失败")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
logs.Info("用户 【", c.Member.Account, "]修改了项目权限 ->", state)
|
||||
c.JsonResult(0, "ok")
|
||||
@@ -265,19 +265,19 @@ func (c *BookController) Transfer() {
|
||||
account := c.GetString("account")
|
||||
|
||||
if account == "" {
|
||||
c.JsonResult(6004, "接受者账号不能为空")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.receive_account_empty"))
|
||||
}
|
||||
member, err := models.NewMember().FindByAccount(account)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("FindByAccount => ", err)
|
||||
c.JsonResult(6005, "接受用户不存在")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.receive_account_not_exist"))
|
||||
}
|
||||
if member.Status != 0 {
|
||||
c.JsonResult(6006, "接受用户已被禁用")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.receive_account_disabled"))
|
||||
}
|
||||
if member.MemberId == c.Member.MemberId {
|
||||
c.JsonResult(6007, "不能转让给自己")
|
||||
c.JsonResult(6007, i18n.Tr(c.Lang, "message.cannot_handover_myself"))
|
||||
}
|
||||
bookResult, err := c.IsPermission()
|
||||
|
||||
@@ -404,7 +404,7 @@ func (c *BookController) Users() {
|
||||
pageIndex, _ := c.GetInt("page", 1)
|
||||
|
||||
if key == "" {
|
||||
c.ShowErrorPage(404, "项目不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
|
||||
book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId)
|
||||
@@ -421,7 +421,7 @@ func (c *BookController) Users() {
|
||||
}
|
||||
c.Data["Model"] = *book
|
||||
|
||||
members, totalCount, err := models.NewMemberRelationshipResult().FindForUsersByBookId(book.BookId, pageIndex, conf.PageSize)
|
||||
members, totalCount, err := models.NewMemberRelationshipResult().FindForUsersByBookId(c.Lang, book.BookId, pageIndex, conf.PageSize)
|
||||
|
||||
if totalCount > 0 {
|
||||
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
||||
@@ -553,7 +553,7 @@ func (c *BookController) Copy() {
|
||||
|
||||
identify := strings.TrimSpace(c.GetString("identify", ""))
|
||||
if identify == "" {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
book := models.NewBook()
|
||||
err := book.Copy(identify)
|
||||
@@ -641,7 +641,7 @@ func (c *BookController) Import() {
|
||||
book.Editor = "markdown"
|
||||
book.Theme = "default"
|
||||
|
||||
go book.ImportBook(tempPath)
|
||||
go book.ImportBook(tempPath, c.Lang)
|
||||
|
||||
logs.Info("用户[", c.Member.Account, "]导入了项目 ->", book)
|
||||
|
||||
@@ -657,10 +657,10 @@ func (c *BookController) Import() {
|
||||
//
|
||||
// if err != nil {
|
||||
// if err == models.ErrPermissionDenied {
|
||||
// c.JsonResult(403, "权限不足")
|
||||
// c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
// }
|
||||
// if err == orm.ErrNoRows {
|
||||
// c.JsonResult(404, "项目不存在")
|
||||
// c.JsonResult(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
// }
|
||||
// logs.Error("生成阅读令牌失败 =>", err)
|
||||
// c.JsonResult(6002, err.Error())
|
||||
@@ -668,7 +668,7 @@ func (c *BookController) Import() {
|
||||
// book := models.NewBook()
|
||||
//
|
||||
// if _, err := book.Find(bookResult.BookId); err != nil {
|
||||
// c.JsonResult(6001, "项目不存在")
|
||||
// c.JsonResult(6001, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
// }
|
||||
// if action == "create" {
|
||||
// if bookResult.PrivatelyOwned == 0 {
|
||||
@@ -710,7 +710,7 @@ func (c *BookController) Delete() {
|
||||
err = models.NewBook().ThoroughDeleteBook(bookResult.BookId)
|
||||
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(6002, "项目不存在")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
if err != nil {
|
||||
logs.Error("删除项目 => ", err)
|
||||
@@ -741,22 +741,22 @@ func (c *BookController) Release() {
|
||||
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.JsonResult(6001, "权限不足")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(6002, "项目不存在")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
logs.Error(err)
|
||||
c.JsonResult(6003, "未知错误")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.unknown_exception"))
|
||||
}
|
||||
if book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder && book.RoleId != conf.BookEditor {
|
||||
c.JsonResult(6003, "权限不足")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
bookId = book.BookId
|
||||
}
|
||||
go models.NewBook().ReleaseContent(bookId)
|
||||
go models.NewBook().ReleaseContent(bookId, c.Lang)
|
||||
|
||||
c.JsonResult(0, "发布任务已推送到任务队列,稍后将在后台执行。")
|
||||
c.JsonResult(0, i18n.Tr(c.Lang, "message.publish_to_queue"))
|
||||
}
|
||||
|
||||
//文档排序.
|
||||
@@ -772,7 +772,7 @@ func (c *BookController) SaveSort() {
|
||||
if c.Member.IsAdministrator() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil || book == nil {
|
||||
c.JsonResult(6001, "项目不存在")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
return
|
||||
}
|
||||
bookId = book.BookId
|
||||
@@ -784,7 +784,7 @@ func (c *BookController) SaveSort() {
|
||||
c.Abort("403")
|
||||
}
|
||||
if bookResult.RoleId == conf.BookObserver {
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
bookId = bookResult.BookId
|
||||
}
|
||||
@@ -808,7 +808,7 @@ func (c *BookController) SaveSort() {
|
||||
continue
|
||||
}
|
||||
if doc.BookId != bookId {
|
||||
logs.Info("%s", "权限错误")
|
||||
logs.Info("%s", i18n.Tr(c.Lang, "message.no_permission"))
|
||||
continue
|
||||
}
|
||||
sort, ok := item["sort"].(float64)
|
||||
@@ -848,15 +848,15 @@ func (c *BookController) Team() {
|
||||
pageIndex, _ := c.GetInt("page", 1)
|
||||
|
||||
if key == "" {
|
||||
c.ShowErrorPage(404, "项目不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
|
||||
book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId)
|
||||
if err != nil || book == nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.ShowErrorPage(403, "权限不足")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
c.ShowErrorPage(500, "系统错误")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error"))
|
||||
return
|
||||
}
|
||||
//如果不是创始人也不是管理员则不能操作
|
||||
@@ -927,7 +927,7 @@ func (c *BookController) TeamDelete() {
|
||||
teamId, _ := c.GetInt("teamId")
|
||||
|
||||
if teamId <= 0 {
|
||||
c.JsonResult(5001, "参数错误")
|
||||
c.JsonResult(5001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
book, err := c.IsPermission()
|
||||
|
||||
@@ -992,22 +992,22 @@ func (c *BookController) IsPermission() (*models.BookResult, error) {
|
||||
identify := c.GetString("identify")
|
||||
|
||||
if identify == "" {
|
||||
return nil, errors.New("参数错误")
|
||||
return nil, errors.New(i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
return book, errors.New("权限不足")
|
||||
return book, errors.New(i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
if err == orm.ErrNoRows {
|
||||
return book, errors.New("项目不存在")
|
||||
return book, errors.New(i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
return book, err
|
||||
}
|
||||
if book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder {
|
||||
return book, errors.New("权限不足")
|
||||
return book, errors.New(i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
return book, nil
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
)
|
||||
@@ -20,7 +21,7 @@ func (c *BookMemberController) AddMember() {
|
||||
roleId, _ := c.GetInt("role_id", 3)
|
||||
logs.Info(account)
|
||||
if identify == "" || account <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
book, err := c.IsPermission()
|
||||
|
||||
@@ -31,14 +32,14 @@ func (c *BookMemberController) AddMember() {
|
||||
member := models.NewMember()
|
||||
|
||||
if _, err := member.Find(account); err != nil {
|
||||
c.JsonResult(404, "用户不存在")
|
||||
c.JsonResult(404, i18n.Tr(c.Lang, "message.user_not_existed"))
|
||||
}
|
||||
if member.Status == 1 {
|
||||
c.JsonResult(6003, "用户已被禁用")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.user_disable"))
|
||||
}
|
||||
|
||||
if _, err := models.NewRelationship().FindForRoleId(book.BookId, member.MemberId); err == nil {
|
||||
c.JsonResult(6003, "用户已存在该项目中")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.user_exist_in_proj"))
|
||||
}
|
||||
|
||||
relationship := models.NewRelationship()
|
||||
@@ -51,7 +52,7 @@ func (c *BookMemberController) AddMember() {
|
||||
memberRelationshipResult.RoleId = conf.BookRole(roleId)
|
||||
memberRelationshipResult.RelationshipId = relationship.RelationshipId
|
||||
memberRelationshipResult.BookId = book.BookId
|
||||
memberRelationshipResult.ResolveRoleName()
|
||||
memberRelationshipResult.ResolveRoleName(c.Lang)
|
||||
|
||||
c.JsonResult(0, "ok", memberRelationshipResult)
|
||||
}
|
||||
@@ -65,33 +66,33 @@ func (c *BookMemberController) ChangeRole() {
|
||||
role, _ := c.GetInt("role_id", 0)
|
||||
|
||||
if identify == "" || memberId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
if memberId == c.Member.MemberId {
|
||||
c.JsonResult(6006, "不能变更自己的权限")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.cannot_change_own_priv"))
|
||||
}
|
||||
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.JsonResult(403, "权限不足")
|
||||
c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(404, "项目不存在")
|
||||
c.JsonResult(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
c.JsonResult(6002, err.Error())
|
||||
}
|
||||
if book.RoleId != 0 && book.RoleId != 1 {
|
||||
c.JsonResult(403, "权限不足")
|
||||
c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
|
||||
member := models.NewMember()
|
||||
|
||||
if _, err := member.Find(memberId); err != nil {
|
||||
c.JsonResult(6003, "用户不存在")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.user_not_existed"))
|
||||
}
|
||||
if member.Status == 1 {
|
||||
c.JsonResult(6004, "用户已被禁用")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.user_disable"))
|
||||
}
|
||||
|
||||
relationship, err := models.NewRelationship().UpdateRoleId(book.BookId, memberId, conf.BookRole(role))
|
||||
@@ -105,7 +106,7 @@ func (c *BookMemberController) ChangeRole() {
|
||||
memberRelationshipResult.RoleId = relationship.RoleId
|
||||
memberRelationshipResult.RelationshipId = relationship.RelationshipId
|
||||
memberRelationshipResult.BookId = book.BookId
|
||||
memberRelationshipResult.ResolveRoleName()
|
||||
memberRelationshipResult.ResolveRoleName(c.Lang)
|
||||
|
||||
c.JsonResult(0, "ok", memberRelationshipResult)
|
||||
}
|
||||
@@ -116,25 +117,25 @@ func (c *BookMemberController) RemoveMember() {
|
||||
member_id, _ := c.GetInt("member_id", 0)
|
||||
|
||||
if identify == "" || member_id <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
if member_id == c.Member.MemberId {
|
||||
c.JsonResult(6006, "不能删除自己")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.cannot_delete_self"))
|
||||
}
|
||||
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.JsonResult(403, "权限不足")
|
||||
c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(404, "项目不存在")
|
||||
c.JsonResult(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
c.JsonResult(6002, err.Error())
|
||||
}
|
||||
//如果不是创始人也不是管理员则不能操作
|
||||
if book.RoleId != conf.BookFounder && book.RoleId != conf.BookAdmin {
|
||||
c.JsonResult(403, "权限不足")
|
||||
c.JsonResult(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
err = models.NewRelationship().DeleteByBookIdAndMemberId(book.BookId, member_id)
|
||||
|
||||
@@ -150,15 +151,15 @@ func (c *BookMemberController) IsPermission() (*models.BookResult, error) {
|
||||
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
return book, errors.New("权限不足")
|
||||
return book, errors.New(i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
if err == orm.ErrNoRows {
|
||||
return book, errors.New("项目不存在")
|
||||
return book, errors.New(i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
return book, err
|
||||
}
|
||||
if book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder {
|
||||
return book, errors.New("权限不足")
|
||||
return book, errors.New(i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
return book, nil
|
||||
}
|
||||
|
@@ -112,7 +112,6 @@ func (c *DocumentController) Read() {
|
||||
c.TplName = fmt.Sprintf("document/%s_read.tpl", bookResult.Theme)
|
||||
|
||||
doc := models.NewDocument()
|
||||
|
||||
if docId, err := strconv.Atoi(id); err == nil {
|
||||
doc, err = doc.FromCacheById(docId)
|
||||
if err != nil || doc == nil {
|
||||
@@ -136,7 +135,7 @@ func (c *DocumentController) Read() {
|
||||
if doc.BookId != bookResult.BookId {
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
}
|
||||
|
||||
doc.Lang = c.Lang
|
||||
doc.Processor()
|
||||
|
||||
attach, err := models.NewAttachment().FindListByDocumentId(doc.DocumentId)
|
||||
@@ -712,7 +711,6 @@ func (c *DocumentController) Content() {
|
||||
isCover := c.GetString("cover")
|
||||
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
|
||||
if err != nil || doc == nil {
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.read_file_error"))
|
||||
return
|
||||
@@ -768,6 +766,7 @@ func (c *DocumentController) Content() {
|
||||
//如果启用了自动发布
|
||||
if autoRelease {
|
||||
go func() {
|
||||
doc.Lang = c.Lang
|
||||
err := doc.ReleaseContent()
|
||||
if err == nil {
|
||||
logs.Informational(i18n.Tr(c.Lang, "message.doc_auto_published")+"-> document_id=%d;document_name=%s", doc.DocumentId, doc.DocumentName)
|
||||
|
@@ -192,6 +192,7 @@ func (c *ManagerController) ChangeMemberRole() {
|
||||
if err := member.Update(); err != nil {
|
||||
c.JsonResult(6003, "用户权限设置失败")
|
||||
}
|
||||
member.Lang = c.Lang
|
||||
member.ResolveRoleName()
|
||||
c.JsonResult(0, "ok", member)
|
||||
}
|
||||
|
Reference in New Issue
Block a user