mirror of https://github.com/mindoc-org/mindoc.git
update i18n(template)
parent
a92739d4a0
commit
883fcec5b2
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
"github.com/beego/i18n"
|
||||||
"github.com/mindoc-org/mindoc/conf"
|
"github.com/mindoc-org/mindoc/conf"
|
||||||
"github.com/mindoc-org/mindoc/models"
|
"github.com/mindoc-org/mindoc/models"
|
||||||
)
|
)
|
||||||
|
@ -14,13 +15,13 @@ type TemplateController struct {
|
||||||
BookId int
|
BookId int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TemplateController) isPermission() (error) {
|
func (c *TemplateController) isPermission() error {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
|
|
||||||
bookIdentify := c.GetString("identify", "")
|
bookIdentify := c.GetString("identify", "")
|
||||||
|
|
||||||
if bookIdentify == "" {
|
if bookIdentify == "" {
|
||||||
return errors.New("参数错误")
|
return errors.New(i18n.Tr(c.Lang, "message.param_error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Member.IsAdministrator() {
|
if !c.Member.IsAdministrator() {
|
||||||
|
@ -44,39 +45,40 @@ func (c *TemplateController) isPermission() (error) {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取指定模板信息
|
//获取指定模板信息
|
||||||
func (c *TemplateController) Get() {
|
func (c *TemplateController) Get() {
|
||||||
if err := c.isPermission() ; err != nil {
|
if err := c.isPermission(); err != nil {
|
||||||
c.JsonResult(500,err.Error())
|
c.JsonResult(500, err.Error())
|
||||||
}
|
}
|
||||||
templateId, _ := c.GetInt("template_id",0)
|
templateId, _ := c.GetInt("template_id", 0)
|
||||||
|
|
||||||
template,err := models.NewTemplate().Find(templateId)
|
template, err := models.NewTemplate().Find(templateId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JsonResult(500,"读取模板失败")
|
c.JsonResult(500, "读取模板失败")
|
||||||
}
|
}
|
||||||
if template.IsGlobal == 0 && template.BookId != c.BookId {
|
if template.IsGlobal == 0 && template.BookId != c.BookId {
|
||||||
c.JsonResult(404,"模板不存在或已删除")
|
c.JsonResult(404, "模板不存在或已删除")
|
||||||
}
|
}
|
||||||
c.JsonResult(0,"OK",template)
|
c.JsonResult(0, "OK", template)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取模板列表
|
//获取模板列表
|
||||||
func (c *TemplateController) List() {
|
func (c *TemplateController) List() {
|
||||||
c.TplName = "template/list.tpl"
|
c.TplName = "template/list.tpl"
|
||||||
if err := c.isPermission() ; err != nil {
|
if err := c.isPermission(); err != nil {
|
||||||
c.Data["ErrorMessage"] = err.Error()
|
c.Data["ErrorMessage"] = err.Error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
templateList,err := models.NewTemplate().FindAllByBookId(c.BookId)
|
templateList, err := models.NewTemplate().FindAllByBookId(c.BookId)
|
||||||
|
|
||||||
if err != nil && err != orm.ErrNoRows{
|
if err != nil && err != orm.ErrNoRows {
|
||||||
c.Data["ErrorMessage"] = "查询项目模板失败"
|
c.Data["ErrorMessage"] = "查询项目模板失败"
|
||||||
}
|
}
|
||||||
if templateList != nil {
|
if templateList != nil {
|
||||||
for i,t := range templateList {
|
for i, t := range templateList {
|
||||||
templateList[i] = t.Preload()
|
templateList[i] = t.Preload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,32 +88,30 @@ func (c *TemplateController) List() {
|
||||||
|
|
||||||
//添加模板
|
//添加模板
|
||||||
func (c *TemplateController) Add() {
|
func (c *TemplateController) Add() {
|
||||||
if err := c.isPermission() ; err != nil {
|
if err := c.isPermission(); err != nil {
|
||||||
c.JsonResult(500,err.Error())
|
c.JsonResult(500, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
templateId, _ := c.GetInt("template_id",0)
|
templateId, _ := c.GetInt("template_id", 0)
|
||||||
content := c.GetString("content")
|
content := c.GetString("content")
|
||||||
isGlobal,_ := c.GetInt("is_global",0)
|
isGlobal, _ := c.GetInt("is_global", 0)
|
||||||
templateName := c.GetString("template_name","")
|
templateName := c.GetString("template_name", "")
|
||||||
|
|
||||||
if templateName == "" || strings.Count(templateName,"") > 300 {
|
if templateName == "" || strings.Count(templateName, "") > 300 {
|
||||||
c.JsonResult(500,"模板名称不能为空且必须小于300字")
|
c.JsonResult(500, "模板名称不能为空且必须小于300字")
|
||||||
}
|
}
|
||||||
template := models.NewTemplate()
|
template := models.NewTemplate()
|
||||||
|
|
||||||
|
|
||||||
if templateId > 0 {
|
if templateId > 0 {
|
||||||
t,err := template.Find(templateId);
|
t, err := template.Find(templateId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JsonResult(500,"模板不存在")
|
c.JsonResult(500, "模板不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
template = t
|
template = t
|
||||||
template.ModifyAt = c.Member.MemberId
|
template.ModifyAt = c.Member.MemberId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template.TemplateId = templateId
|
template.TemplateId = templateId
|
||||||
template.BookId = c.BookId
|
template.BookId = c.BookId
|
||||||
template.TemplateContent = content
|
template.TemplateContent = content
|
||||||
|
@ -120,16 +120,16 @@ func (c *TemplateController) Add() {
|
||||||
//只有管理员才能设置全局模板
|
//只有管理员才能设置全局模板
|
||||||
if c.Member.IsAdministrator() {
|
if c.Member.IsAdministrator() {
|
||||||
template.IsGlobal = isGlobal
|
template.IsGlobal = isGlobal
|
||||||
}else{
|
} else {
|
||||||
template.IsGlobal = 0
|
template.IsGlobal = 0
|
||||||
//如果不是管理员需要判断是否有项目权限
|
//如果不是管理员需要判断是否有项目权限
|
||||||
rel,err := models.NewRelationship().FindByBookIdAndMemberId(c.BookId,c.Member.MemberId)
|
rel, err := models.NewRelationship().FindByBookIdAndMemberId(c.BookId, c.Member.MemberId)
|
||||||
if err != nil || rel.RoleId == conf.BookObserver {
|
if err != nil || rel.RoleId == conf.BookObserver {
|
||||||
c.JsonResult(403,"没有权限")
|
c.JsonResult(403, "没有权限")
|
||||||
}
|
}
|
||||||
//如果修改的模板不是本人创建的,并且又不是项目创建者则禁止修改
|
//如果修改的模板不是本人创建的,并且又不是项目创建者则禁止修改
|
||||||
if template.MemberId > 0 && template.MemberId != c.Member.MemberId && rel.RoleId != conf.BookFounder {
|
if template.MemberId > 0 && template.MemberId != c.Member.MemberId && rel.RoleId != conf.BookFounder {
|
||||||
c.JsonResult(403,"没有权限")
|
c.JsonResult(403, "没有权限")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template.MemberId = c.Member.MemberId
|
template.MemberId = c.Member.MemberId
|
||||||
|
@ -137,51 +137,51 @@ func (c *TemplateController) Add() {
|
||||||
var cols []string
|
var cols []string
|
||||||
|
|
||||||
if templateId > 0 {
|
if templateId > 0 {
|
||||||
cols = []string{ "template_content", "modify_time","modify_at","version" }
|
cols = []string{"template_content", "modify_time", "modify_at", "version"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := template.Save(cols...); err != nil {
|
if err := template.Save(cols...); err != nil {
|
||||||
c.JsonResult(500,"报错模板失败")
|
c.JsonResult(500, "报错模板失败")
|
||||||
}
|
}
|
||||||
c.JsonResult(0,"OK",template)
|
c.JsonResult(0, "OK", template)
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除模板
|
//删除模板
|
||||||
func (c *TemplateController) Delete() {
|
func (c *TemplateController) Delete() {
|
||||||
if err := c.isPermission() ; err != nil {
|
if err := c.isPermission(); err != nil {
|
||||||
c.JsonResult(500,err.Error())
|
c.JsonResult(500, err.Error())
|
||||||
}
|
}
|
||||||
templateId, _ := c.GetInt("template_id",0)
|
templateId, _ := c.GetInt("template_id", 0)
|
||||||
|
|
||||||
template,err := models.NewTemplate().Find(templateId)
|
template, err := models.NewTemplate().Find(templateId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JsonResult(404,"模板不存在")
|
c.JsonResult(404, "模板不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Member.IsAdministrator() {
|
if c.Member.IsAdministrator() {
|
||||||
err := models.NewTemplate().Delete(templateId,0)
|
err := models.NewTemplate().Delete(templateId, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JsonResult(500,"删除失败")
|
c.JsonResult(500, "删除失败")
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
//如果不是管理员需要判断是否有项目权限
|
//如果不是管理员需要判断是否有项目权限
|
||||||
rel,err := models.NewRelationship().FindByBookIdAndMemberId(template.BookId,c.Member.MemberId)
|
rel, err := models.NewRelationship().FindByBookIdAndMemberId(template.BookId, c.Member.MemberId)
|
||||||
if err != nil || rel.RoleId == conf.BookObserver {
|
if err != nil || rel.RoleId == conf.BookObserver {
|
||||||
c.JsonResult(403,"没有权限")
|
c.JsonResult(403, "没有权限")
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果是创始人或管理者可以直接删除模板
|
//如果是创始人或管理者可以直接删除模板
|
||||||
if rel.RoleId == conf.BookFounder || rel.RoleId == conf.BookAdmin {
|
if rel.RoleId == conf.BookFounder || rel.RoleId == conf.BookAdmin {
|
||||||
err := models.NewTemplate().Delete(templateId,0)
|
err := models.NewTemplate().Delete(templateId, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JsonResult(500,"删除失败")
|
c.JsonResult(500, "删除失败")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.NewTemplate().Delete(templateId,c.Member.MemberId);err != nil {
|
if err := models.NewTemplate().Delete(templateId, c.Member.MemberId); err != nil {
|
||||||
c.JsonResult(500,"删除失败")
|
c.JsonResult(500, "删除失败")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JsonResult(0,"OK")
|
c.JsonResult(0, "OK")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue