feat:实现团队功能

pull/425/head
lifei6671 2018-11-05 18:50:01 +08:00
parent 1d8d74afb1
commit b897c87476
20 changed files with 1411 additions and 208 deletions

View File

@ -63,17 +63,16 @@ func RegisterDataBase() {
if strings.HasPrefix(database, "./") {
database = filepath.Join(conf.WorkingDirectory, string(database[1:]))
}
if p,err := filepath.Abs(database); err == nil {
if p, err := filepath.Abs(database); err == nil {
database = p
}
dbPath := filepath.Dir(database)
if _,err := os.Stat(dbPath); err != nil && os.IsNotExist(err) {
if _, err := os.Stat(dbPath); err != nil && os.IsNotExist(err) {
os.MkdirAll(dbPath, 0777)
}
err := orm.RegisterDataBase("default", "sqlite3", database)
if err != nil {
@ -102,6 +101,9 @@ func RegisterModel() {
new(models.Label),
new(models.Blog),
new(models.Template),
new(models.Team),
new(models.TeamMember),
new(models.TeamRelationship),
)
gob.Register(models.Blog{})
gob.Register(models.Document{})
@ -120,11 +122,11 @@ func RegisterLogger(log string) {
logs.Async(1e3)
}
if log == "" {
logPath,err := filepath.Abs(beego.AppConfig.DefaultString("log_path",conf.WorkingDir("runtime","logs")))
logPath, err := filepath.Abs(beego.AppConfig.DefaultString("log_path", conf.WorkingDir("runtime", "logs")))
if err == nil {
log = logPath
}else{
log = conf.WorkingDir("runtime","logs")
} else {
log = conf.WorkingDir("runtime", "logs")
}
}
@ -155,33 +157,39 @@ func RegisterLogger(log string) {
if level := beego.AppConfig.DefaultString("log_level", "Trace"); level != "" {
switch level {
case "Emergency":
config["level"] = beego.LevelEmergency;break
config["level"] = beego.LevelEmergency;
break
case "Alert":
config["level"] = beego.LevelAlert;break
config["level"] = beego.LevelAlert;
break
case "Critical":
config["level"] = beego.LevelCritical;break
config["level"] = beego.LevelCritical;
break
case "Error":
config["level"] = beego.LevelError; break
config["level"] = beego.LevelError;
break
case "Warning":
config["level"] = beego.LevelWarning; break
config["level"] = beego.LevelWarning;
break
case "Notice":
config["level"] = beego.LevelNotice; break
config["level"] = beego.LevelNotice;
break
case "Informational":
config["level"] = beego.LevelInformational;break
config["level"] = beego.LevelInformational;
break
case "Debug":
config["level"] = beego.LevelDebug;break
config["level"] = beego.LevelDebug;
break
}
}
b, err := json.Marshal(config);
if err != nil {
beego.Error("初始化文件日志时出错 ->",err)
beego.SetLogger("file", `{"filename":"`+ logPath + `"}`)
}else{
beego.Error("初始化文件日志时出错 ->", err)
beego.SetLogger("file", `{"filename":"`+logPath+`"}`)
} else {
beego.SetLogger(logs.AdapterFile, string(b))
}
beego.SetLogFuncCall(true)
}
@ -254,29 +262,29 @@ func ResolveCommand(args []string) {
}
if conf.ConfigurationFile == "" {
conf.ConfigurationFile = conf.WorkingDir( "conf", "app.conf")
conf.ConfigurationFile = conf.WorkingDir("conf", "app.conf")
config := conf.WorkingDir("conf", "app.conf.example")
if !filetil.FileExists(conf.ConfigurationFile) && filetil.FileExists(config) {
filetil.CopyFile(conf.ConfigurationFile, config)
}
}
if err := gocaptcha.ReadFonts(conf.WorkingDir( "static", "fonts"), ".ttf");err != nil {
log.Fatal("读取字体文件时出错 -> ",err)
if err := gocaptcha.ReadFonts(conf.WorkingDir("static", "fonts"), ".ttf"); err != nil {
log.Fatal("读取字体文件时出错 -> ", err)
}
if err := beego.LoadAppConfig("ini", conf.ConfigurationFile);err != nil {
if err := beego.LoadAppConfig("ini", conf.ConfigurationFile); err != nil {
log.Fatal("An error occurred:", err)
}
if conf.LogFile == "" {
logPath,err := filepath.Abs(beego.AppConfig.DefaultString("log_path",conf.WorkingDir("runtime","logs")))
logPath, err := filepath.Abs(beego.AppConfig.DefaultString("log_path", conf.WorkingDir("runtime", "logs")))
if err == nil {
conf.LogFile = logPath
}else{
conf.LogFile = conf.WorkingDir("runtime","logs")
} else {
conf.LogFile = conf.WorkingDir("runtime", "logs")
}
}
conf.AutoLoadDelay = beego.AppConfig.DefaultInt("config_auto_delay",0)
conf.AutoLoadDelay = beego.AppConfig.DefaultInt("config_auto_delay", 0)
uploads := conf.WorkingDir("uploads")
os.MkdirAll(uploads, 0666)
@ -341,7 +349,7 @@ func RegisterCache() {
cache.Init(memory)
} else if cacheProvider == "redis" {
//设置Redis前缀
if key := beego.AppConfig.DefaultString("cache_redis_prefix",""); key != "" {
if key := beego.AppConfig.DefaultString("cache_redis_prefix", ""); key != "" {
redis.DefaultKey = key
}
var redisConfig struct {
@ -394,7 +402,7 @@ func RegisterCache() {
} else {
cache.Init(&cache.NullCache{})
beego.Warn("不支持的缓存管道,缓存将禁用 ->" ,cacheProvider)
beego.Warn("不支持的缓存管道,缓存将禁用 ->", cacheProvider)
return
}
beego.Info("缓存初始化完成.")
@ -407,7 +415,7 @@ func RegisterAutoLoadConfig() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
beego.Error("创建配置文件监控器失败 ->",err)
beego.Error("创建配置文件监控器失败 ->", err)
}
go func() {
for {
@ -436,7 +444,7 @@ func RegisterAutoLoadConfig() {
err = watcher.WatchFlags(conf.ConfigurationFile, fsnotify.FSN_MODIFY|fsnotify.FSN_RENAME)
if err != nil {
beego.Error("监控配置文件失败 ->",err)
beego.Error("监控配置文件失败 ->", err)
}
}
}
@ -446,7 +454,7 @@ func init() {
if configPath, err := filepath.Abs(conf.ConfigurationFile); err == nil {
conf.ConfigurationFile = configPath
}
gocaptcha.ReadFonts(conf.WorkingDir("static","fonts"), ".ttf")
gocaptcha.ReadFonts(conf.WorkingDir("static", "fonts"), ".ttf")
gob.Register(models.Member{})
if p, err := filepath.Abs(os.Args[0]); err == nil {

View File

@ -27,24 +27,30 @@ const PageSize = 10
// 用户权限
const (
// 超级管理员.
MemberSuperRole = 0
MemberSuperRole SystemRole = iota
//普通管理员.
MemberAdminRole = 1
MemberAdminRole
//普通用户.
MemberGeneralRole = 2
MemberGeneralRole
)
//系统角色
type SystemRole int
const (
// 创始人.
BookFounder = 0
BookFounder BookRole = iota
//管理者
BookAdmin = 1
BookAdmin
//编辑者.
BookEditor = 2
BookEditor
//观察者
BookObserver = 3
BookObserver
)
//项目角色
type BookRole int
const (
LoggerOperate = "operate"
LoggerSystem = "system"
@ -139,40 +145,45 @@ func GetUploadFileSize() int64 {
}
return 0
}
//是否启用导出
func GetEnableExport() bool {
return beego.AppConfig.DefaultBool("enable_export",true)
return beego.AppConfig.DefaultBool("enable_export", true)
}
//同一项目导出线程的并发数
func GetExportProcessNum() int {
exportProcessNum := beego.AppConfig.DefaultInt("export_process_num",1)
exportProcessNum := beego.AppConfig.DefaultInt("export_process_num", 1)
if exportProcessNum <= 0 || exportProcessNum > 4 {
exportProcessNum = 1
}
return exportProcessNum;
}
//导出项目队列的并发数量
func GetExportLimitNum() int {
exportLimitNum := beego.AppConfig.DefaultInt("export_limit_num",1)
exportLimitNum := beego.AppConfig.DefaultInt("export_limit_num", 1)
if exportLimitNum < 0 {
exportLimitNum = 1
}
return exportLimitNum;
}
//等待导出队列的长度
func GetExportQueueLimitNum() int {
exportQueueLimitNum := beego.AppConfig.DefaultInt("export_queue_limit_num",10)
exportQueueLimitNum := beego.AppConfig.DefaultInt("export_queue_limit_num", 10)
if exportQueueLimitNum <= 0 {
exportQueueLimitNum = 100
}
return exportQueueLimitNum
}
//默认导出项目的缓存目录
func GetExportOutputPath() string {
exportOutputPath := filepath.Join(beego.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory,"cache")),"books")
exportOutputPath := filepath.Join(beego.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory, "cache")), "books")
return exportOutputPath
}
@ -198,19 +209,19 @@ func IsAllowUploadFileExt(ext string) bool {
//重写生成URL的方法加上完整的域名
func URLFor(endpoint string, values ...interface{}) string {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
pathUrl := beego.URLFor(endpoint, values ...)
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(pathUrl,"http://") {
if strings.HasPrefix(pathUrl, "http://") {
return pathUrl
}
if strings.HasPrefix(pathUrl,"/") && strings.HasSuffix(baseUrl,"/") {
if strings.HasPrefix(pathUrl, "/") && strings.HasSuffix(baseUrl, "/") {
return baseUrl + pathUrl[1:]
}
if !strings.HasPrefix(pathUrl,"/") && !strings.HasSuffix(baseUrl,"/") {
if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") {
return baseUrl + "/" + pathUrl
}
return baseUrl + beego.URLFor(endpoint, values ...)
@ -223,14 +234,14 @@ func URLForWithCdnImage(p string) string {
cdn := beego.AppConfig.DefaultString("cdnimg", "")
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
if strings.HasPrefix(p, "/") && strings.HasSuffix(baseUrl, "/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(baseUrl, "/") {
return baseUrl + "/" + p
}
return baseUrl + p
@ -244,26 +255,26 @@ func URLForWithCdnImage(p string) string {
return cdn + p
}
func URLForWithCdnCss (p string,v ...string) string {
func URLForWithCdnCss(p string, v ...string) string {
cdn := beego.AppConfig.DefaultString("cdncss", "")
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
filePath := WorkingDir(p)
if f,err := os.Stat(filePath); err == nil && !strings.Contains(p, "?") && len(v) > 0 && v[0] == "version" {
p = p + fmt.Sprintf("?v=%s" , f.ModTime().Format("20060102150405"))
if f, err := os.Stat(filePath); err == nil && !strings.Contains(p, "?") && len(v) > 0 && v[0] == "version" {
p = p + fmt.Sprintf("?v=%s", f.ModTime().Format("20060102150405"))
}
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
if strings.HasPrefix(p, "/") && strings.HasSuffix(baseUrl, "/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(baseUrl, "/") {
return baseUrl + "/" + p
}
return baseUrl + p
@ -277,7 +288,7 @@ func URLForWithCdnCss (p string,v ...string) string {
return cdn + p
}
func URLForWithCdnJs(p string,v ...string) string {
func URLForWithCdnJs(p string, v ...string) string {
cdn := beego.AppConfig.DefaultString("cdnjs", "")
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
@ -285,20 +296,20 @@ func URLForWithCdnJs(p string,v ...string) string {
filePath := WorkingDir(p)
if f,err := os.Stat(filePath); err == nil && !strings.Contains(p, "?") && len(v) > 0 && v[0] == "version" {
p = p + fmt.Sprintf("?v=%s" , f.ModTime().Format("20060102150405"))
if f, err := os.Stat(filePath); err == nil && !strings.Contains(p, "?") && len(v) > 0 && v[0] == "version" {
p = p + fmt.Sprintf("?v=%s", f.ModTime().Format("20060102150405"))
}
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
if strings.HasPrefix(p, "/") && strings.HasSuffix(baseUrl, "/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(baseUrl, "/") {
return baseUrl + "/" + p
}
return baseUrl + p
@ -314,19 +325,19 @@ func URLForWithCdnJs(p string,v ...string) string {
func WorkingDir(elem ...string) string {
elems := append([]string{ WorkingDirectory },elem...)
elems := append([]string{WorkingDirectory}, elem...)
return filepath.Join(elems...)
}
func init() {
if p,err := filepath.Abs("./conf/app.conf"); err == nil {
if p, err := filepath.Abs("./conf/app.conf"); err == nil {
ConfigurationFile = p
}
if p,err := filepath.Abs("./"); err == nil {
if p, err := filepath.Abs("./"); err == nil {
WorkingDirectory = p
}
if p,err := filepath.Abs("./runtime/logs"); err == nil {
if p, err := filepath.Abs("./runtime/logs"); err == nil {
LogFile = p
}
}

View File

@ -117,6 +117,30 @@ func (c *BaseController) JsonResult(errCode int, errMsg string, data ...interfac
c.StopRun()
}
//如果错误不为空,则响应错误信息到浏览器.
func (c *BaseController) CheckJsonError(code int,err error) {
if err == nil {
return
}
jsonData := make(map[string]interface{}, 3)
jsonData["errcode"] = code
jsonData["message"] = err.Error()
returnJSON, err := json.Marshal(jsonData)
if err != nil {
beego.Error(err)
}
c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json; charset=utf-8")
c.Ctx.ResponseWriter.Header().Set("Cache-Control", "no-cache, no-store")
io.WriteString(c.Ctx.ResponseWriter, string(returnJSON))
c.StopRun()
}
// ExecuteViewPathTemplate 执行指定的模板并返回执行结果.
func (c *BaseController) ExecuteViewPathTemplate(tplName string, data interface{}) (string, error) {
var buf bytes.Buffer
@ -160,7 +184,13 @@ func (c *BaseController) ShowErrorPage(errCode int, errMsg string) {
}
if errCode >= 200 && errCode <= 510 {
c.CustomAbort(errCode, buf.String())
}else{
} else {
c.CustomAbort(500, buf.String())
}
}
func (c *BaseController) CheckErrorResult(code int,err error) {
if err != nil {
c.ShowErrorPage(code, err.Error())
}
}

View File

@ -18,7 +18,7 @@ type BookMemberController struct {
func (c *BookMemberController) AddMember() {
identify := c.GetString("identify")
account,_ := c.GetInt("account")
role_id, _ := c.GetInt("role_id", 3)
roleId, _ := c.GetInt("role_id", 3)
beego.Info(account)
if identify == "" || account <= 0 {
c.JsonResult(6001, "参数错误")
@ -46,11 +46,11 @@ func (c *BookMemberController) AddMember() {
relationship := models.NewRelationship()
relationship.BookId = book.BookId
relationship.MemberId = member.MemberId
relationship.RoleId = role_id
relationship.RoleId = conf.BookRole(roleId)
if err := relationship.Insert(); err == nil {
memberRelationshipResult := models.NewMemberRelationshipResult().FromMember(member)
memberRelationshipResult.RoleId = role_id
memberRelationshipResult.RoleId = conf.BookRole(roleId)
memberRelationshipResult.RelationshipId = relationship.RelationshipId
memberRelationshipResult.BookId = book.BookId
memberRelationshipResult.ResolveRoleName()
@ -63,13 +63,13 @@ func (c *BookMemberController) AddMember() {
// 变更指定用户在指定项目中的权限
func (c *BookMemberController) ChangeRole() {
identify := c.GetString("identify")
member_id, _ := c.GetInt("member_id", 0)
memberId, _ := c.GetInt("member_id", 0)
role, _ := c.GetInt("role_id", 0)
if identify == "" || member_id <= 0 {
if identify == "" || memberId <= 0 {
c.JsonResult(6001, "参数错误")
}
if member_id == c.Member.MemberId {
if memberId == c.Member.MemberId {
c.JsonResult(6006, "不能变更自己的权限")
}
book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
@ -89,14 +89,14 @@ func (c *BookMemberController) ChangeRole() {
member := models.NewMember()
if _, err := member.Find(member_id); err != nil {
if _, err := member.Find(memberId); err != nil {
c.JsonResult(6003, "用户不存在")
}
if member.Status == 1 {
c.JsonResult(6004, "用户已被禁用")
}
relationship, err := models.NewRelationship().UpdateRoleId(book.BookId, member_id, role)
relationship, err := models.NewRelationship().UpdateRoleId(book.BookId, memberId, conf.BookRole(role))
if err != nil {
logs.Error("变更用户在项目中的权限 => ", err)

View File

@ -59,7 +59,7 @@ func (c *ManagerController) Users() {
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
c.Data["PageHtml"] = pager.HtmlPages()
for _,item := range members {
for _, item := range members {
item.Avatar = conf.URLForWithCdnImage(item.Avatar)
}
} else {
@ -114,7 +114,7 @@ func (c *ManagerController) CreateMember() {
member.Account = account
member.Password = password1
member.Role = role
member.Role = conf.SystemRole(role)
member.Avatar = conf.GetDefaultAvatar()
member.CreateAt = c.Member.MemberId
member.Email = email
@ -167,17 +167,17 @@ func (c *ManagerController) UpdateMemberStatus() {
func (c *ManagerController) ChangeMemberRole() {
c.Prepare()
member_id, _ := c.GetInt("member_id", 0)
memberId, _ := c.GetInt("member_id", 0)
role, _ := c.GetInt("role", 0)
if member_id <= 0 {
if memberId <= 0 {
c.JsonResult(6001, "参数错误")
}
if role != conf.MemberAdminRole && role != conf.MemberGeneralRole {
if role != int(conf.MemberAdminRole) && role != int(conf.MemberGeneralRole) {
c.JsonResult(6001, "用户权限不正确")
}
member := models.NewMember()
if _, err := member.Find(member_id); err != nil {
if _, err := member.Find(memberId); err != nil {
c.JsonResult(6002, "用户不存在")
}
if member.MemberId == c.Member.MemberId {
@ -186,7 +186,7 @@ func (c *ManagerController) ChangeMemberRole() {
if member.Role == conf.MemberSuperRole {
c.JsonResult(6005, "不能变更超级管理员的权限")
}
member.Role = role
member.Role = conf.SystemRole(role)
if err := member.Update(); err != nil {
c.JsonResult(6003, "用户权限设置失败")
@ -670,7 +670,7 @@ func (c *ManagerController) AttachDelete() {
beego.Error("AttachDelete => ", err)
c.JsonResult(6001, err.Error())
}
attach.FilePath = filepath.Join(conf.WorkingDirectory,attach.FilePath)
attach.FilePath = filepath.Join(conf.WorkingDirectory, attach.FilePath)
if err := attach.Delete(); err != nil {
beego.Error("AttachDelete => ", err)
@ -732,33 +732,265 @@ func (c *ManagerController) Config() {
if c.Ctx.Input.IsPost() {
content := strings.TrimSpace(c.GetString("configFileTextArea"))
if content == "" {
c.JsonResult(500,"配置文件不能为空")
c.JsonResult(500, "配置文件不能为空")
}
tf,err := ioutil.TempFile(os.TempDir(),"mindoc")
tf, err := ioutil.TempFile(os.TempDir(), "mindoc")
if err != nil {
beego.Error("创建临时文件失败 ->",err)
c.JsonResult(5001,"创建临时文件失败")
beego.Error("创建临时文件失败 ->", err)
c.JsonResult(5001, "创建临时文件失败")
}
defer tf.Close()
tf.WriteString(content)
err = beego.LoadAppConfig("ini",tf.Name())
err = beego.LoadAppConfig("ini", tf.Name())
if err != nil {
beego.Error("加载配置文件失败 ->",err)
c.JsonResult(5002,"加载配置文件失败")
beego.Error("加载配置文件失败 ->", err)
c.JsonResult(5002, "加载配置文件失败")
}
err = filetil.CopyFile(tf.Name(), conf.ConfigurationFile)
if err != nil {
beego.Error("保存配置文件失败 ->",err)
c.JsonResult(5003,"保存配置文件失败")
beego.Error("保存配置文件失败 ->", err)
c.JsonResult(5003, "保存配置文件失败")
}
c.JsonResult(0,"保存成功")
c.JsonResult(0, "保存成功")
}
c.Data["ConfigContent"] = ""
if b,err := ioutil.ReadFile(conf.ConfigurationFile); err == nil {
if b, err := ioutil.ReadFile(conf.ConfigurationFile); err == nil {
c.Data["ConfigContent"] = string(b)
}
}
func (c *ManagerController) Team() {
c.Prepare()
c.TplName = "manager/team.tpl"
pageIndex, _ := c.GetInt("page", 0)
teams, totalCount, err := models.NewTeam().FindToPager(pageIndex, conf.PageSize)
if err != nil && err != orm.ErrNoRows {
c.ShowErrorPage(500, err.Error())
}
if err == orm.ErrNoRows || len(teams) <= 0 {
c.Data["Result"] = template.JS("[]")
c.Data["PageHtml"] = ""
return
}
if totalCount > 0 {
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
c.Data["PageHtml"] = pager.HtmlPages()
} else {
c.Data["PageHtml"] = ""
}
b, err := json.Marshal(teams)
if err != nil {
c.Data["Result"] = template.JS("[]")
} else {
c.Data["Result"] = template.JS(string(b))
}
}
func (c *ManagerController) TeamCreate() {
c.Prepare()
teamName := c.GetString("teamName")
if teamName == "" {
c.JsonResult(5001, "团队名称不能为空")
}
team := models.NewTeam()
team.MemberId = c.Member.MemberId
team.TeamName = teamName
if err := team.Save(); err == nil {
c.JsonResult(0, "OK", team)
} else {
c.JsonResult(5002, err.Error())
}
}
func (c *ManagerController) TeamEdit() {
c.Prepare()
teamName := c.GetString("teamName")
teamId, _ := c.GetInt("teamId")
if teamName == "" {
c.JsonResult(5001, "团队名称不能为空")
}
if teamId <= 0 {
c.JsonResult(5002, "团队标识不能为空")
}
team, err := models.NewTeam().First(teamId)
c.CheckJsonError(5003, err)
team.TeamName = teamName
err = team.Save()
c.CheckJsonError(5004, err)
c.JsonResult(0, "OK", team)
}
func (c *ManagerController) TeamDelete() {
c.Prepare()
teamId, _ := c.GetInt("teamId")
if teamId <= 0 {
c.JsonResult(5002, "团队标识不能为空")
}
err := models.NewTeam().Delete(teamId)
c.CheckJsonError(5001, err)
c.JsonResult(0, "")
}
func (c *ManagerController) TeamMemberList() {
c.Prepare()
c.TplName = "manager/team_member_list.tpl"
teamId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
pageIndex, _ := c.GetInt("page", 0)
if teamId <= 0 {
c.ShowErrorPage(500, "参数错误")
}
team, err := models.NewTeam().First(teamId)
if err == orm.ErrNoRows {
c.ShowErrorPage(404, "团队不存在")
}
c.CheckErrorResult(500, err)
c.Data["Model"] = team
teams, totalCount, err := models.NewTeamMember().FindToPager(teamId, pageIndex, conf.PageSize)
if err != nil && err != orm.ErrNoRows {
c.ShowErrorPage(500, err.Error())
}
if err == orm.ErrNoRows || len(teams) <= 0 {
c.Data["Result"] = template.JS("[]")
c.Data["PageHtml"] = ""
return
}
if totalCount > 0 {
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
c.Data["PageHtml"] = pager.HtmlPages()
} else {
c.Data["PageHtml"] = ""
}
b, err := json.Marshal(teams)
if err != nil {
beego.Error("编码 JSON 结果失败 ->", err)
c.Data["Result"] = template.JS("[]")
} else {
c.Data["Result"] = template.JS(string(b))
}
}
//搜索团队用户.
func (c *ManagerController) TeamSearchMember() {
c.Prepare()
teamId, _ := c.GetInt("teamId")
keyword := strings.TrimSpace(c.GetString("q"))
if teamId <= 0 {
c.JsonResult(500, "参数错误")
}
searchResult, err := models.NewTeamMember().FindNotJoinMemberByAccount(teamId, keyword, 10)
if err != nil {
c.JsonResult(500, err.Error())
}
c.JsonResult(0, "OK", searchResult)
}
func (c *ManagerController) TeamMemberAdd() {
c.Prepare()
teamId, _ := c.GetInt("teamId")
memberId, _ := c.GetInt("memberId")
roleId, _ := c.GetInt("roleId")
if teamId <= 0 || memberId <= 0 || roleId <= 0 || roleId > int(conf.BookObserver) {
c.JsonResult(5001, "参数不正确")
}
teamMember := models.NewTeamMember()
teamMember.MemberId = memberId
teamMember.TeamId = teamId
teamMember.RoleId = conf.BookRole(roleId)
if err := teamMember.Save(); err != nil {
c.CheckJsonError(5001, err)
}
teamMember.Include()
c.JsonResult(0, "OK", teamMember)
}
func (c *ManagerController) TeamMemberDelete() {
c.Prepare()
memberId, _ := c.GetInt("memberId")
teamId, _ := c.GetInt("teamId")
teamMember, err := models.NewTeamMember().FindFirst(teamId, memberId)
if err != nil {
c.JsonResult(5001, "用户不存在或已禁用")
}
err = teamMember.Delete(teamMember.TeamMemberId)
if err != nil {
c.JsonResult(5002, "删除失败")
}
c.JsonResult(0, "ok")
}
func (c *ManagerController) TeamChangeMemberRole() {
c.Prepare()
memberId, _ := c.GetInt("memberId")
roleId, _ := c.GetInt("roleId")
teamId, _ := c.GetInt("teamId")
if memberId <= 0 || roleId <= 0 || teamId <= 0 || roleId > int(conf.BookObserver) {
c.JsonResult(5001, "参数错误")
}
teamMember, err := models.NewTeamMember().ChangeRoleId(teamId, memberId, conf.BookRole(roleId))
if err != nil {
c.JsonResult(5002, err.Error())
} else {
c.JsonResult(0, "OK", teamMember)
}
}
func (c *ManagerController) TeamBookList() {
c.Prepare()
c.TplName = "manager/team_book_list.tpl"
}
func (c *ManagerController) TeamBookAdd() {
c.Prepare()
}
func (c *ManagerController) TeamBookDelete() {
c.Prepare()
}

View File

@ -279,7 +279,7 @@ func (b *Blog) FindToPager(pageIndex, pageSize int,memberId int,status string) (
offset := (pageIndex - 1) * pageSize
query := o.QueryTable(b.TableNameWithPrefix());
query := o.QueryTable(b.TableNameWithPrefix())
if memberId > 0 {
query = query.Filter("member_id",memberId)

View File

@ -55,7 +55,7 @@ type BookResult struct {
HistoryCount int `json:"history_count"`
RelationshipId int `json:"relationship_id"`
RoleId int `json:"role_id"`
RoleId conf.BookRole `json:"role_id"`
RoleName string `json:"role_name"`
Status int `json:"status"`
IsEnableShare bool `json:"is_enable_share"`
@ -447,14 +447,14 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "css", "markdown.preview.css"), filepath.Join(tempOutputPath, "styles", "css", "markdown.preview.css")); err != nil {
beego.Error("复制CSS样式出错 -> static/css/markdown.preview.css", err)
}
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static","editor.md","lib", "highlight", "styles", "github.css"), filepath.Join(tempOutputPath, "styles","css", "github.css")); err != nil {
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "lib", "highlight", "styles", "github.css"), filepath.Join(tempOutputPath, "styles", "css", "github.css")); err != nil {
beego.Error("复制CSS样式出错 -> static/editor.md/lib/highlight/styles/github.css", err)
}
if err := filetil.CopyDir(filepath.Join(conf.WorkingDirectory,"static","font-awesome"), filepath.Join(tempOutputPath,"styles","font-awesome")); err != nil {
if err := filetil.CopyDir(filepath.Join(conf.WorkingDirectory, "static", "font-awesome"), filepath.Join(tempOutputPath, "styles", "font-awesome")); err != nil {
beego.Error("复制CSS样式出错 -> static/font-awesome", err)
}
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static","editor.md","lib","mermaid","mermaid.css"), filepath.Join(tempOutputPath, "styles", "css", "mermaid.css")); err != nil {
if err := filetil.CopyFile(filepath.Join(conf.WorkingDirectory, "static", "editor.md", "lib", "mermaid", "mermaid.css"), filepath.Join(tempOutputPath, "styles", "css", "mermaid.css")); err != nil {
beego.Error("复制CSS样式出错 -> static/editor.md/lib/mermaid/mermaid.css", err)
}

View File

@ -39,3 +39,20 @@ var (
ErrCommentClosed = errors.New("评论已关闭")
ErrCommentContentNotEmpty = errors.New("评论内容不能为空")
)
type Error struct {
code int
message string
}
func (e Error) Error() string {
return e.message
}
func (e Error) Code() int {
return e.code
}
func NewError(code int, message string) Error {
return Error{code: code, message: message}
}

View File

@ -30,7 +30,7 @@ type Member struct {
Phone string `orm:"size(255);column(phone);null;default(null)" json:"phone"`
Avatar string `orm:"size(1000);column(avatar)" json:"avatar"`
//用户角色0 超级管理员 /1 管理员/ 2 普通用户 .
Role int `orm:"column(role);type(int);default(1);index" json:"role"`
Role conf.SystemRole `orm:"column(role);type(int);default(1);index" json:"role"`
RoleName string `orm:"-" json:"role_name"`
Status int `orm:"column(status);type(int);default(0)" json:"status"` //用户状态0 正常/1 禁用
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
@ -63,7 +63,7 @@ func (m *Member) Login(account string, password string) (*Member, error) {
member := &Member{}
//err := o.QueryTable(m.TableNameWithPrefix()).Filter("account", account).Filter("status", 0).One(member)
err := o.Raw("select * from md_members where (account = ? or email = ?) and status = 0 limit 1;",account,account).QueryRow(member)
err := o.Raw("select * from md_members where (account = ? or email = ?) and status = 0 limit 1;", account, account).QueryRow(member)
if err != nil {
if beego.AppConfig.DefaultBool("ldap_enable", false) == true {
@ -100,13 +100,13 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
var err error
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", beego.AppConfig.String("ldap_host"), beego.AppConfig.DefaultInt("ldap_port", 3268)))
if err != nil {
beego.Error("绑定 LDAP 用户失败 ->",err)
beego.Error("绑定 LDAP 用户失败 ->", err)
return m, ErrLDAPConnect
}
defer lc.Close()
err = lc.Bind(beego.AppConfig.String("ldap_user"), beego.AppConfig.String("ldap_password"))
if err != nil {
beego.Error("绑定 LDAP 用户失败 ->",err)
beego.Error("绑定 LDAP 用户失败 ->", err)
return m, ErrLDAPFirstBind
}
searchRequest := ldap.NewSearchRequest(
@ -119,7 +119,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
)
searchResult, err := lc.Search(searchRequest)
if err != nil {
beego.Error("绑定 LDAP 用户失败 ->",err)
beego.Error("绑定 LDAP 用户失败 ->", err)
return m, ErrLDAPSearch
}
if len(searchResult.Entries) != 1 {
@ -128,7 +128,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
userdn := searchResult.Entries[0].DN
err = lc.Bind(userdn, password)
if err != nil {
beego.Error("绑定 LDAP 用户失败 ->",err)
beego.Error("绑定 LDAP 用户失败 ->", err)
return m, ErrorMemberPasswordError
}
if m.Account == "" {
@ -136,7 +136,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
m.Email = searchResult.Entries[0].GetAttributeValue("mail")
m.AuthMethod = "ldap"
m.Avatar = "/static/images/headimgurl.jpg"
m.Role = beego.AppConfig.DefaultInt("ldap_user_role", 2)
m.Role = conf.SystemRole(beego.AppConfig.DefaultInt("ldap_user_role", 2))
m.CreateTime = time.Now()
err = m.Add()
@ -174,7 +174,7 @@ func (m *Member) Add() error {
hash, err := utils.PasswordHash(m.Password)
if err != nil {
beego.Error("加密用户密码失败 =>",err)
beego.Error("加密用户密码失败 =>", err)
return errors.New("加密用户密码失败")
}
@ -185,7 +185,7 @@ func (m *Member) Add() error {
_, err = o.Insert(m)
if err != nil {
beego.Error("保存用户数据到数据时失败 =>",err)
beego.Error("保存用户数据到数据时失败 =>", err)
return errors.New("保存用户失败")
}
m.ResolveRoleName()
@ -199,26 +199,27 @@ func (m *Member) Update(cols ...string) error {
if m.Email == "" {
return errors.New("邮箱不能为空")
}
if c, err := o.QueryTable(m.TableNameWithPrefix()).Filter("email", m.Email).Exclude("member_id",m.MemberId).Count(); err == nil && c > 0 {
if c, err := o.QueryTable(m.TableNameWithPrefix()).Filter("email", m.Email).Exclude("member_id", m.MemberId).Count(); err == nil && c > 0 {
return errors.New("邮箱已被使用")
}
if _, err := o.Update(m, cols...); err != nil {
beego.Error("保存用户信息失败=>",err)
beego.Error("保存用户信息失败=>", err)
return errors.New("保存用户信息失败")
}
return nil
}
func (m *Member) Find(id int,cols ...string) (*Member, error) {
func (m *Member) Find(id int, cols ...string) (*Member, error) {
o := orm.NewOrm()
if err := o.QueryTable(m.TableNameWithPrefix()).Filter("member_id",id).One(m,cols...); err != nil {
if err := o.QueryTable(m.TableNameWithPrefix()).Filter("member_id", id).One(m, cols...); err != nil {
return m, err
}
m.ResolveRoleName()
return m, nil
}
func (m *Member) ResolveRoleName() {
if m.Role == conf.MemberSuperRole {
m.RoleName = "超级管理员"
@ -240,15 +241,16 @@ func (m *Member) FindByAccount(account string) (*Member, error) {
}
return m, err
}
//批量查询用户
func (m *Member) FindByAccountList(accounts ...string) ([]*Member,error) {
func (m *Member) FindByAccountList(accounts ...string) ([]*Member, error) {
o := orm.NewOrm()
var members []*Member
_,err := o.QueryTable(m.TableNameWithPrefix()).Filter("account__in", accounts).All(&members)
_, err := o.QueryTable(m.TableNameWithPrefix()).Filter("account__in", accounts).All(&members)
if err == nil {
for _,item := range members {
for _, item := range members {
item.ResolveRoleName()
}
}
@ -354,7 +356,6 @@ func (m *Member) Valid(is_hash_password bool) error {
}
//删除一个用户.
func (m *Member) Delete(oldId int, newId int) error {
o := orm.NewOrm()
@ -401,7 +402,7 @@ func (m *Member) Delete(oldId int, newId int) error {
o.Rollback()
return err
}
_,err = o.Raw("UPDATE md_blogs SET member_id = ? WHERE member_id = ?;", newId, oldId).Exec()
_, err = o.Raw("UPDATE md_blogs SET member_id = ? WHERE member_id = ?;", newId, oldId).Exec()
if err != nil {
o.Rollback()
@ -424,6 +425,13 @@ func (m *Member) Delete(oldId int, newId int) error {
o.Rollback()
return err
}
_,err = o.QueryTable(NewTeamMember()).Filter("member_id",oldId).Delete()
if err != nil {
o.Rollback()
return err
}
//_,err = o.Raw("UPDATE md_relationship SET member_id = ? WHERE member_id = ?",newId,oldId).Exec()
//if err != nil {
//

View File

@ -14,14 +14,14 @@ type MemberRelationshipResult struct {
Email string `json:"email"`
Phone string `json:"phone"`
Avatar string `json:"avatar"`
Role int `json:"role"` //用户角色0 管理员/ 1 普通用户
Role conf.SystemRole `json:"role"` //用户角色0 管理员/ 1 普通用户
Status int `json:"status"` //用户状态0 正常/1 禁用
CreateTime time.Time `json:"create_time"`
CreateAt int `json:"create_at"`
RelationshipId int `json:"relationship_id"`
BookId int `json:"book_id"`
// RoleId 角色0 创始人(创始人不能被移除) / 1 管理员/2 编辑者/3 观察者
RoleId int `json:"role_id"`
RoleId conf.BookRole `json:"role_id"`
RoleName string `json:"role_name"`
}
@ -63,6 +63,7 @@ func (m *MemberRelationshipResult) ResolveRoleName() *MemberRelationshipResult {
}
return m
}
// 根据项目ID查询用户
func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
o := orm.NewOrm()
@ -96,44 +97,14 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageS
}
// 查询指定文档中不存在的用户列表
func (m *MemberRelationshipResult) FindNotJoinUsersByAccount(bookId, limit int,account string) ([]*Member,error){
func (m *MemberRelationshipResult) FindNotJoinUsersByAccount(bookId, limit int, account string) ([]*Member, error) {
o := orm.NewOrm()
sql := "SELECT m.* FROM md_members as m LEFT JOIN md_relationship as rel ON m.member_id=rel.member_id AND rel.book_id = ? WHERE rel.relationship_id IS NULL AND m.account LIKE ? LIMIT 0,?;"
var members []*Member
_,err := o.Raw(sql,bookId,account,limit).QueryRows(&members)
_, err := o.Raw(sql, bookId, account, limit).QueryRows(&members)
return members,err
return members, err
}

View File

@ -12,7 +12,7 @@ type Relationship struct {
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
BookId int `orm:"column(book_id);type(int)" json:"book_id"`
// RoleId 角色0 创始人(创始人不能被移除) / 1 管理员/2 编辑者/3 观察者
RoleId int `orm:"column(role_id);type(int)" json:"role_id"`
RoleId conf.BookRole `orm:"column(role_id);type(int)" json:"role_id"`
}
// TableName 获取对应数据库表名.
@ -31,7 +31,7 @@ func (m *Relationship) TableEngine() string {
// 联合唯一键
func (u *Relationship) TableUnique() [][]string {
return [][]string{
[]string{"MemberId", "BookId"},
{"member_id", "book_id"},
}
}
@ -55,28 +55,28 @@ func (m *Relationship) FindFounder(book_id int) (*Relationship, error) {
return m, err
}
func (m *Relationship) UpdateRoleId(book_id, member_id, role_id int) (*Relationship, error) {
func (m *Relationship) UpdateRoleId(bookId, memberId int, roleId conf.BookRole) (*Relationship, error) {
o := orm.NewOrm()
book := NewBook()
book.BookId = book_id
book.BookId = bookId
if err := o.Read(book); err != nil {
logs.Error("UpdateRoleId => ", err)
return m, errors.New("项目不存在")
}
err := o.QueryTable(m.TableNameWithPrefix()).Filter("member_id", member_id).Filter("book_id", book_id).One(m)
err := o.QueryTable(m.TableNameWithPrefix()).Filter("member_id", memberId).Filter("book_id", bookId).One(m)
if err == orm.ErrNoRows {
m = NewRelationship()
m.BookId = book_id
m.MemberId = member_id
m.RoleId = role_id
m.BookId = bookId
m.MemberId = memberId
m.RoleId = roleId
} else if err != nil {
return m, err
} else if m.RoleId == conf.BookFounder {
return m, errors.New("不能变更创始人的权限")
}
m.RoleId = role_id
m.RoleId = roleId
if m.RelationshipId > 0 {
_, err = o.Update(m)
@ -88,7 +88,7 @@ func (m *Relationship) UpdateRoleId(book_id, member_id, role_id int) (*Relations
}
func (m *Relationship) FindForRoleId(book_id, member_id int) (int, error) {
func (m *Relationship) FindForRoleId(book_id, member_id int) (conf.BookRole, error) {
o := orm.NewOrm()
relationship := NewRelationship()

148
models/Team.go 100644
View File

@ -0,0 +1,148 @@
package models
import (
"time"
"github.com/lifei6671/mindoc/conf"
"github.com/astaxie/beego/orm"
"errors"
"github.com/astaxie/beego"
)
//团队.
type Team struct {
TeamId int `orm:"column(team_id);pk;auto;unique;" json:"team_id"`
TeamName string `orm:"column(team_name);size(255)" json:"team_name"`
MemberId int `orm:"column(member_id);type(int);" json:"member_id"`
IsDelete bool `orm:"column(is_delete);default(0)" json:"is_delete"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
MemberCount int `orm:"-" json:"member_count"`
BookCount int `orm:"-" json:"book_count"`
MemberName string `orm:"-" json:"member_name"`
}
// TableName 获取对应数据库表名.
func (t *Team) TableName() string {
return "teams"
}
// TableEngine 获取数据使用的引擎.
func (t *Team) TableEngine() string {
return "INNODB"
}
func (t *Team) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + t.TableName()
}
func NewTeam() *Team {
return &Team{}
}
// 查询一个团队.
func (t *Team) First(id int, cols ...string) (*Team, error) {
if id <= 0 {
return nil, orm.ErrNoRows
}
o := orm.NewOrm()
err := o.QueryTable(t.TableNameWithPrefix()).Filter("team_id", id).One(t, cols...)
return t, err
}
func (t *Team) Delete(id int) (err error) {
if id <= 0 {
return ErrInvalidParameter
}
o := orm.NewOrm()
err = o.Begin()
if err != nil {
beego.Error("开启事物时出错 ->",err)
return
}
_,err = o.QueryTable(t.TableNameWithPrefix()).Filter("team_id",id).Delete()
if err != nil {
beego.Error("删除团队时出错 ->", err)
o.Rollback()
return
}
_,err = o.Raw("delete from md_team_member where team_id=?;", id).Exec()
if err != nil {
beego.Error("删除团队成员时出错 ->", err)
o.Rollback()
return
}
_,err = o.Raw("delete from md_team_relationship where team_id=?;",id).Exec()
if err != nil {
beego.Error("删除团队项目时出错 ->", err)
o.Rollback()
return err
}
err = o.Commit()
return
}
//分页查询团队.
func (t *Team) FindToPager(pageIndex, pageSize int) (list []*Team, totalCount int, err error) {
o := orm.NewOrm()
offset := (pageIndex - 1) * pageSize
_, err = o.QueryTable(t.TableNameWithPrefix()).Offset(offset).Limit(pageSize).All(&list)
if err != nil {
return
}
c, err := o.QueryTable(t.TableNameWithPrefix()).Count()
if err != nil {
return
}
totalCount = int(c)
for i,item := range list {
if member,err := NewMember().Find(item.MemberId,"account","real_name"); err == nil {
if member.RealName != "" {
list[i].MemberName = member.RealName
} else {
list[i].MemberName = member.Account
}
}
if c,err := o.QueryTable(NewTeamRelationship().TableNameWithPrefix()).Filter("team_id", item.TeamId).Count(); err == nil {
list[i].BookCount = int(c)
}
if c,err := o.QueryTable(NewTeamMember().TableNameWithPrefix()).Filter("team_id", item.TeamId).Count(); err == nil {
list[i].MemberCount = int(c)
}
}
return
}
//更新或添加一个团队.
func (t *Team) Save(cols ... string) (err error) {
if t.TeamName == "" {
return NewError(5001, "团队名称不能为空")
}
o := orm.NewOrm()
if t.TeamId <= 0 && o.QueryTable(t.TableNameWithPrefix()).Filter("team_name", t.TeamName).Exist() {
return errors.New("团队名称已存在")
}
if t.TeamId <= 0 {
_, err = o.Insert(t)
} else {
_, err = o.Update(t, cols...)
}
if err != nil {
beego.Error("在保存团队时出错 ->", err)
}
return
}

View File

@ -0,0 +1,221 @@
package models
import (
"github.com/lifei6671/mindoc/conf"
"errors"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego"
)
type TeamMember struct {
TeamMemberId int `orm:"column(team_member_id);pk;auto;unique;" json:"team_member_id"`
TeamId int `orm:"column(team_id);type(int)" json:"team_id"`
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
// RoleId 角色0 创始人(创始人不能被移除) / 1 管理员/2 编辑者/3 观察者
RoleId conf.BookRole `orm:"column(role_id);type(int)" json:"role_id"`
RoleName string `orm:"-" json:"role_name"`
Account string `orm:"-" json:"account"`
RealName string `orm:"-" json:"real_name"`
Avatar string `orm:"-" json:"avatar"`
}
// TableName 获取对应数据库表名.
func (m *TeamMember) TableName() string {
return "team_member"
}
func (m *TeamMember) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + m.TableName()
}
// TableEngine 获取数据使用的引擎.
func (m *TeamMember) TableEngine() string {
return "INNODB"
}
// 联合唯一键
func (m *TeamMember) TableUnique() [][]string {
return [][]string{{"team_id", "member_id"}}
}
func NewTeamMember() *TeamMember {
return &TeamMember{}
}
func (m *TeamMember) First(id int, cols ...string) (*TeamMember, error) {
if id <= 0 {
return nil, errors.New("参数错误")
}
o := orm.NewOrm()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("team_member_id", id).One(m, cols...)
if err != nil && err != orm.ErrNoRows {
beego.Error("查询团队成员错误 ->", err)
}
return m.Include(), err
}
func (m *TeamMember) ChangeRoleId(teamId int, memberId int, roleId conf.BookRole) (member *TeamMember, err error) {
if teamId <= 0 || memberId <= 0 || roleId <= 0 || roleId > conf.BookObserver {
return nil, ErrInvalidParameter
}
o := orm.NewOrm()
err = o.QueryTable(m.TableNameWithPrefix()).Filter("team_id", teamId).Filter("member_id", memberId).One(m)
if err != nil {
beego.Error("查询团队用户时失败 ->", err)
return m, err
}
m.RoleId = roleId
err = m.Save("role_id")
if err == nil {
m.Include()
}
return m, err
}
func (m *TeamMember) FindFirst(teamId, memberId int) (*TeamMember, error) {
if teamId <= 0 || memberId <= 0 {
return nil, ErrInvalidParameter
}
o := orm.NewOrm()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("team_id",teamId).Filter("member_id",memberId).One(m)
if err != nil {
beego.Error("查询团队用户失败 ->",err)
return nil,err
}
return m.Include(),nil
}
func (m *TeamMember) Save(cols ...string) (err error) {
if m.TeamId <= 0 {
return errors.New("团队不能为空")
}
if m.MemberId <= 0 {
return errors.New("用户不能为空")
}
o := orm.NewOrm()
if !o.QueryTable(NewTeam().TableNameWithPrefix()).Filter("team_id", m.TeamId).Exist() {
return errors.New("团队不存在")
}
if !o.QueryTable(NewMember()).Filter("member_id", m.MemberId).Filter("status", 0).Exist() {
return errors.New("用户不存在或已禁用")
}
if m.TeamMemberId <= 0 {
_, err = o.Insert(m)
} else {
_, err = o.Update(m, cols...)
}
if err != nil {
beego.Error("在保存团队时出错 ->", err)
}
return
}
func (m *TeamMember) Delete(id int) (err error) {
if id <= 0 {
return ErrInvalidParameter
}
_, err = orm.NewOrm().QueryTable(m.TableNameWithPrefix()).Filter("team_member_id", id).Delete()
if err != nil {
beego.Error("删除团队用户时出错 ->", err)
}
return
}
func (m *TeamMember) FindToPager(teamId, pageIndex, pageSize int) (list []*TeamMember, totalCount int, err error) {
if teamId <= 0 {
err = ErrInvalidParameter
return
}
offset := (pageIndex - 1) * pageSize
o := orm.NewOrm()
_, err = o.QueryTable(m.TableNameWithPrefix()).Filter("team_id", teamId).Offset(offset).Limit(pageSize).All(&list)
if err != nil {
if err != orm.ErrNoRows {
beego.Error("查询团队成员失败 ->", err)
}
return
}
c, err := o.QueryTable(m.TableNameWithPrefix()).Filter("team_id", teamId).Count()
if err != nil {
return
}
totalCount = int(c)
//将来优化
for _, item := range list {
item.Include()
}
return
}
func (m *TeamMember) Include() *TeamMember {
if member, err := NewMember().Find(m.MemberId, "account", "real_name", "avatar"); err == nil {
m.Account = member.Account
m.RealName = member.RealName
m.Avatar = member.Avatar
}
if m.RoleId == 0 {
m.RoleName = "创始人"
} else if m.RoleId == 1 {
m.RoleName = "管理员"
} else if m.RoleId == 2 {
m.RoleName = "编辑者"
} else if m.RoleId == 3 {
m.RoleName = "观察者"
}
return m
}
func (m *TeamMember) FindNotJoinMemberByAccount(teamId int, account string, limit int) (*SelectMemberResult, error) {
if teamId <= 0 {
return nil, ErrInvalidParameter
}
o := orm.NewOrm()
sql := `select member.member_id,member.account
from md_members as member
left join md_team_member as team on team.team_id = ? and member.member_id != team.member_id
where member.account like ?
order by member.member_id desc
limit ?;`
members := make([]*Member, 0)
_, err := o.Raw(sql, teamId, "%"+account+"%", limit).QueryRows(&members)
if err != nil {
beego.Error("查询团队用户时出错 ->", err)
return nil, err
}
result := SelectMemberResult{}
items := make([]KeyValueItem, 0)
for _, member := range members {
item := KeyValueItem{}
item.Id = member.MemberId
item.Text = member.Account
items = append(items, item)
}
result.Result = items
return &result, err
}

View File

@ -0,0 +1,35 @@
package models
import (
"github.com/lifei6671/mindoc/conf"
"time"
)
type TeamRelationship struct {
TeamRelationshipId int `orm:"column(team_relationship_id);pk;auto;unique;" json:"team_relationship_id"`
BookId int `orm:"column(book_id)"`
TeamId int `orm:"column(team_id)"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
}
// TableName 获取对应数据库表名.
func (m *TeamRelationship) TableName() string {
return "team_relationship"
}
func (m *TeamRelationship) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + m.TableName()
}
// TableEngine 获取数据使用的引擎.
func (m *TeamRelationship) TableEngine() string {
return "INNODB"
}
// 联合唯一键
func (m *TeamRelationship) TableUnique() [][]string {
return [][]string{{"team_id", "team_id"}}
}
func NewTeamRelationship() *TeamRelationship {
return &TeamRelationship{}
}

View File

@ -40,6 +40,23 @@ func init() {
beego.Router("/manager/config", &controllers.ManagerController{}, "*:Config")
beego.Router("/manager/team", &controllers.ManagerController{}, "*:Team")
beego.Router("/manager/team/create", &controllers.ManagerController{}, "POST:TeamCreate")
beego.Router("/manager/team/edit", &controllers.ManagerController{}, "POST:TeamEdit")
beego.Router("/manager/team/delete", &controllers.ManagerController{}, "POST:TeamDelete")
beego.Router("/manager/team/member/list/:id", &controllers.ManagerController{}, "*:TeamMemberList")
beego.Router("/manager/team/member/add", &controllers.ManagerController{}, "POST:TeamMemberAdd")
beego.Router("/manager/team/member/delete", &controllers.ManagerController{}, "POST:TeamMemberDelete")
beego.Router("/manager/team/member/change_role", &controllers.ManagerController{}, "POST:TeamChangeMemberRole")
beego.Router("/manager/team/member/search", &controllers.ManagerController{}, "*:TeamSearchMember")
beego.Router("/manager/team/book/list/:id", &controllers.ManagerController{}, "*:TeamBookList")
beego.Router("/manager/team/book/add", &controllers.ManagerController{}, "POST:TeamBookAdd")
beego.Router("/manager/team/book/delete", &controllers.ManagerController{}, "POST:TeamBookDelete")
beego.Router("/setting", &controllers.SettingController{}, "*:Index")
beego.Router("/setting/password", &controllers.SettingController{}, "*:Password")
beego.Router("/setting/upload", &controllers.SettingController{}, "*:Upload")

View File

@ -12,12 +12,7 @@
<link href="{{cdncss "/static/font-awesome/css/font-awesome.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/select2/4.0.5/css/select2.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/css/main.css" "version"}}" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="{{cdnjs "/static/html5shiv/3.7.3/html5shiv.min.js"}}"></script>
<script src="{{cdnjs "/static/respond.js/1.4.2/respond.min.js"}}"></script>
<![endif]-->
</head>
<body>
<div class="manual-reader">

View File

@ -0,0 +1,263 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>团队管理 - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/font-awesome/css/font-awesome.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/css/main.css" "version"}}" rel="stylesheet">
<style type="text/css">
.table > tbody > tr > td {
vertical-align: middle;
}
</style>
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.tpl" .}}
<div class="container manual-body">
<div class="row">
{{template "manager/widgets.tpl" "team"}}
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title"> 团队管理</strong>
{{if eq .Member.Role 0}}
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal"
data-target="#addTeamDialogModal"><i class="fa fa-user-plus" aria-hidden="true"></i>
创建团队
</button>
{{end}}
</div>
</div>
<div class="box-body">
<div class="users-list" id="teamList">
<template v-if="lists.length <= 0">
<div class="text-center">暂无数据</div>
</template>
<template v-else>
<table class="table">
<thead>
<tr>
<th>团队名称</th>
<th width="150px">成员数量</th>
<th width="150px">项目数量</th>
<th align="center" width="220px">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in lists">
<td>${item.team_name}</td>
<td>${item.member_count}</td>
<td>${item.book_count}</td>
<td>
<a :href="'{{urlfor "ManagerController.TeamBookList" ":id" ""}}' + item.team_id" class="btn btn-primary btn-sm">项目</a>
<a :href="'{{urlfor "ManagerController.TeamMemberList" ":id" ""}}' + item.team_id" type="button" class="btn btn-success btn-sm">成员</a>
<button type="button" class="btn btn-sm btn-default" @click="editTeam(item.team_id)">编辑</button>
<button type="button" class="btn btn-danger btn-sm" @click="deleteTeam(item.team_id,$event)" data-loading-text="删除中">删除</button>
</td>
</tr>
</tbody>
</table>
</template>
<nav class="pagination-container">
{{.PageHtml}}
</nav>
</div>
</div>
</div>
</div>
</div>
{{template "widgets/footer.tpl" .}}
</div>
<!-- Modal -->
<div class="modal fade" id="addTeamDialogModal" tabindex="-1" role="dialog" aria-labelledby="addTeamDialogModalLabel">
<div class="modal-dialog" role="document">
<form method="post" autocomplete="off" class="form-horizontal"
action="{{urlfor "ManagerController.TeamCreate"}}" id="addTeamDialogForm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">创建团队</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label" for="account">团队名称<span
class="error-message">*</span></label>
<div class="col-sm-10">
<input type="text" name="teamName" class="form-control" placeholder="团队名称" id="teamName" maxlength="50">
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<span id="form-error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success" data-loading-text="保存中..." id="btnAddTeam">保存
</button>
</div>
</div>
</form>
</div>
</div><!--END Modal-->
<div class="modal fade" id="editTeamDialogModal" tabindex="-1" role="dialog" aria-labelledby="editTeamDialogModalLabel">
<div class="modal-dialog" role="document">
<form method="post" autocomplete="off" class="form-horizontal" action="{{urlfor "ManagerController.TeamEdit"}}" id="editTeamDialogForm">
<input type="hidden" name="teamId" value="">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">编辑团队</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label" for="account">团队名称<span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="text" name="teamName" class="form-control" placeholder="团队名称" maxlength="50">
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<span id="form-error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success" data-loading-text="保存中..." id="btnEditTeam">保存
</button>
</div>
</div>
</form>
</div>
</div><!--END Modal-->
<script src="{{cdnjs "/static/jquery/1.12.4/jquery.min.js"}}"></script>
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}"></script>
<script src="{{cdnjs "/static/vuejs/vue.min.js"}}"></script>
<script src="{{cdnjs "/static/js/jquery.form.js"}}" type="text/javascript"></script>
<script src="{{cdnjs "/static/js/main.js"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var editTeamDialogModal = $("#editTeamDialogModal");
$("#addTeamDialogModal").on("show.bs.modal", function () {
window.addTeamDialogModalHtml = $(this).find("form").html();
}).on("hidden.bs.modal", function () {
$(this).find("form").html(window.addTeamDialogModalHtml);
});
$("#addTeamDialogForm").ajaxForm({
beforeSubmit: function () {
var account = $.trim($("#addTeamDialogForm #teamName").val());
if (account === "") {
return showError("团队名称不能为空");
}
$("#btnAddTeam").button("loading");
return true;
},
success: function ($res) {
if ($res.errcode === 0) {
app.lists.splice(0, 0, $res.data);
$("#addTeamDialogModal").modal("hide");
} else {
showError($res.message);
}
},
error: function () {
showError("服务器异常");
},
complete: function () {
$("#btnAddTeam").button("reset");
}
});
editTeamDialogModal.on("shown.bs.modal",function () {
$(this).find("input[name='teamName']").focus();
});
$("#editTeamDialogForm").ajaxForm({
beforeSubmit: function () {
var account = $.trim(editTeamDialogModal.find("input[name='teamName']").val());
if (account === "") {
return showError("团队名称不能为空");
}
$("#btnEditTeam").button("loading");
return true;
},success :function ($res) {
if ($res.errcode === 0) {
for (var index in app.lists) {
var item = app.lists[index];
if (item.team_id == $res.data.team_id) {
app.lists.splice(index, 1, $res.data);
break;
}
}
editTeamDialogModal.modal("hide");
}else {
showError($res.message);
}
},
error: function () {
showError("服务器异常");
},
complete: function () {
$("#btnEditTeam").button("reset");
}
});
var app = new Vue({
el: "#teamList",
data: {
lists: {{.Result}}
},
delimiters: ['${', '}'],
methods: {
deleteTeam: function (id, e) {
var $this = this;
$.ajax({
url: "{{urlfor "ManagerController.TeamDelete"}}",
type: "post",
data: {"id": id},
dataType: "json",
success: function (res) {
if (res.errcode === 0) {
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.team_id == id) {
$this.lists.splice(index, 1);
break;
}
}
} else {
alert("操作失败:" + res.message);
}
}
});
},
editTeam : function (id, e) {
var $this = this;
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.team_id == id) {
editTeamDialogModal.find("input[name='teamName']").val(item.team_name);
editTeamDialogModal.find("input[name='teamId']").val(item.team_id);
editTeamDialogModal.modal("show");
break;
}
}
}
}
});
Vue.nextTick(function () {
$("[data-toggle='tooltip']").tooltip();
});
});
</script>
</body>
</html>

View File

View File

@ -0,0 +1,246 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>团队用户管理 - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/font-awesome/css/font-awesome.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/select2/4.0.5/css/select2.min.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/css/main.css" "version"}}" rel="stylesheet">
<style type="text/css">
.table>tbody>tr>td{vertical-align: middle;}
</style>
</head>
<body>
<div class="manual-reader">
{{template "widgets/header.tpl" .}}
<div class="container manual-body">
<div class="row">
{{template "manager/widgets.tpl" "team"}}
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title">{{.Model.TeamName}} - 成员管理</strong>
{{if eq .Member.Role 0}}
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#addTeamMemberDialogModal"><i class="fa fa-user-plus" aria-hidden="true"></i> 添加成员</button>
{{end}}
</div>
</div>
<div class="box-body">
<div class="users-list" id="teamMemberList">
<template v-if="lists.length <= 0">
<div class="text-center">暂无数据</div>
</template>
<template v-else>
<table class="table">
<thead>
<tr>
<th width="80">头像</th>
<th>账号</th>
<th>姓名</th>
<th>角色</th>
<th width="80px">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="item in lists">
<td><img :src="item.avatar" onerror="this.src='{{cdnimg "/static/images/middle.gif"}}'" class="img-circle" width="34" height="34"></td>
<td>${item.account}</td>
<td>${item.real_name}</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-default btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
${item.role_name}
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="javascript:;" @click="setTeamMemberRole(item.member_id,1)">管理员 <p class="text">拥有阅读、写作和管理权限</p></a> </li>
<li><a href="javascript:;" @click="setTeamMemberRole(item.member_id,2)">编辑者 <p class="text">拥有阅读和写作权限</p></a> </li>
<li><a href="javascript:;" @click="setTeamMemberRole(item.member_id,3)">观察者 <p class="text">拥有阅读权限</p></a> </li>
</ul>
</div>
</td>
<td>
<button type="button" class="btn btn-danger btn-sm" @click="deleteMember(item.member_id,$event)" data-loading-text="删除中">删除</button>
</td>
</tr>
</tbody>
</table>
</template>
<nav class="pagination-container">
{{.PageHtml}}
</nav>
</div>
</div>
</div>
</div>
</div>
{{template "widgets/footer.tpl" .}}
</div>
<!-- Modal -->
<div class="modal fade" id="addTeamMemberDialogModal" tabindex="-1" role="dialog" aria-labelledby="addTeamMemberDialogModalLabel">
<div class="modal-dialog modal-sm" role="document" style="width: 400px;">
<form method="post" autocomplete="off" class="form-horizontal" action="{{urlfor "ManagerController.TeamMemberAdd"}}" id="addTeamMemberDialogForm">
<input type="hidden" name="teamId" value="{{.Model.TeamId}}">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">添加成员</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label">账号</label>
<div class="col-sm-10">
<select class="js-data-example-ajax form-control" multiple="multiple" name="memberId" id="memberId"></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">角色</label>
<div class="col-sm-10">
<select name="roleId" class="form-control">
<option value="1">管理员</option>
<option value="2">编辑者</option>
<option value="3">观察者</option>
</select>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="modal-footer">
<span id="form-error-message"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success" data-loading-text="保存中..." id="btnAddMember">保存</button>
</div>
</div>
</form>
</div>
</div><!--END Modal-->
<script src="{{cdnjs "/static/jquery/1.12.4/jquery.min.js"}}"></script>
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}"></script>
<script src="{{cdnjs "/static/vuejs/vue.min.js"}}"></script>
<script src="{{cdnjs "/static/js/jquery.form.js"}}" type="text/javascript"></script>
<script src="{{cdnjs "/static/select2/4.0.5/js/select2.full.min.js"}}"></script>
<script src="{{cdnjs "/static/select2/4.0.5/js/i18n/zh-CN.js"}}"></script>
<script src="{{cdnjs "/static/js/main.js"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var modalCache = $("#addTeamMemberDialogModal form").html();
/**
* 添加用户
*/
$("#addTeamMemberDialogForm").ajaxForm({
beforeSubmit : function () {
var memberId = $.trim($("#memberId").val());
if(memberId === ""){
return showError("账号不能为空");
}
$("#btnAddMember").button("loading");
},
success : function (res) {
if(res.errcode === 0){
app.lists.splice(0,0,res.data);
$("#addTeamMemberDialogModal").modal("hide");
}else{
showError(res.message);
}
$("#btnAddMember").button("reset");
}
});
$("#addTeamMemberDialogModal").on("hidden.bs.modal",function () {
$(this).find("form").html(modalCache);
}).on("show.bs.modal",function () {
$('.js-data-example-ajax').select2({
language: "zh-CN",
minimumInputLength : 1,
minimumResultsForSearch: Infinity,
maximumSelectionLength:1,
width : "100%",
ajax: {
url: '{{urlfor "ManagerController.TeamSearchMember" "teamId" .Model.TeamId}}',
dataType: 'json',
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
return {
results : data.data.results
}
}
}
});
});
var app = new Vue({
el : "#teamMemberList",
data : {
lists : {{.Result}}
},
delimiters : ['${','}'],
methods : {
setTeamMemberRole : function (member_id, role) {
var $this = this;
$.ajax({
url :"{{urlfor "ManagerController.TeamChangeMemberRole"}}",
dataType :"json",
type :"post",
data : { "memberId" : member_id,"roleId" : role ,"teamId":{{.Model.TeamId}}},
success : function (res) {
if(res.errcode === 0){
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.member_id === member_id) {
$this.lists.splice(index,1,res.data);
break;
}
}
}else{
alert("操作失败:" + res.message);
}
}
})
},
deleteMember : function (id, e) {
var $this = this;
$.ajax({
url : "{{urlfor "ManagerController.TeamMemberDelete"}}",
type : "post",
data : { "memberId":id ,"teamId":{{.Model.TeamId}}},
dataType : "json",
success : function (res) {
if (res.errcode === 0) {
for (var index in $this.lists) {
var item = $this.lists[index];
if (item.member_id == id) {
console.log(item);
$this.lists.splice(index,1);
break;
}
}
} else {
alert("操作失败:" + res.message);
}
}
});
}
}
});
Vue.nextTick(function () {
$("[data-toggle='tooltip']").tooltip();
});
});
</script>
</body>
</html>

View File

@ -1,11 +1,12 @@
<div class="page-left">
<ul class="menu">
<li{{if eq "index" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Index"}}" class="item"><i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘</a> </li>
<li{{if eq "users" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-users" aria-hidden="true"></i> 用户管理</a> </li>
<li{{if eq "users" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Users" }}" class="item"><i class="fa fa-user" aria-hidden="true"></i> 用户管理</a> </li>
<li{{if eq "team" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Team" }}" class="item"><i class="fa fa-group" aria-hidden="true"></i> 团队管理</a> </li>
<li{{if eq "books" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Books" }}" class="item"><i class="fa fa-book" aria-hidden="true"></i> 项目管理</a> </li>
{{/*<li><a href="{{urlfor "ManagerController.Comments" }}" class="item"><i class="fa fa-comments-o" aria-hidden="true"></i> </a> </li>*/}}
<li{{if eq "setting" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Setting" }}" class="item"><i class="fa fa-cogs" aria-hidden="true"></i> 配置管理</a> </li>
<li{{if eq "config" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Config" }}" class="item"><i class="fa fa-file" aria-hidden="true"></i> 配置文件</a> </li>
{{/*<li{{if eq "config" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.Config" }}" class="item"><i class="fa fa-file" aria-hidden="true"></i> </a> </li>*/}}
<li{{if eq "attach" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.AttachList" }}" class="item"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 附件管理</a> </li>
<li{{if eq "label" .}} class="active"{{end}}><a href="{{urlfor "ManagerController.LabelList" }}" class="item"><i class="fa fa-bookmark" aria-hidden="true"></i> 标签管理</a> </li>
</ul>