Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
phachon committed Jul 31, 2018
1 parent d822803 commit cf9ecd5
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 85 deletions.
1 change: 0 additions & 1 deletion app/models/privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (p *Privilege) GetTypePrivilegesByUserId(userId string) (menus, controllers
}
roleId := user["role_id"]

fmt.Println(user)
if roleId == fmt.Sprintf("%d", Role_Root_Id) {
return PrivilegeModel.GetTypePrivileges()
}
Expand Down
3 changes: 3 additions & 0 deletions app/models/space_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func (s *SpaceUser) DeleteBySpaceIdAndUserId(spaceId string, userId string) (err

// insert space_user
func (s *SpaceUser) Insert(spaceUserValue map[string]interface{}) (id int64, err error) {

spaceUserValue["create_time"] = time.Now().Unix()
spaceUserValue["update_time"] = time.Now().Unix()
db := G.DB()
var rs *mysql.ResultSet
rs, err = db.Exec(db.AR().Insert(Table_SpaceUser_Name, spaceUserValue))
Expand Down
14 changes: 14 additions & 0 deletions app/modules/system/controllers/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ func (this *SpaceController) Save() {
this.jsonError("添加空间失败!")
}

// add space member
insertValue := map[string]interface{}{
"user_id": this.UserId,
"space_id": spaceId,
"privilege": models.SpaceUser_Privilege_Manager,
}
_, err = models.SpaceUserModel.Insert(insertValue)
if err != nil {
// delete space
models.SpaceModel.Delete(fmt.Sprintf("%d", spaceId))
this.ErrorLog("添加空间添加空间成员失败: " + err.Error())
this.jsonError("添加空间失败!")
}

this.InfoLog("添加空间 "+utils.Convert.IntToString(spaceId, 10)+" 成功")
this.jsonSuccess("添加空间成功", nil, "/system/space/list")
}
Expand Down
2 changes: 0 additions & 2 deletions app/modules/system/controllers/space_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ func (this *Space_UserController) Save() {
"user_id": userId,
"space_id": spaceId,
"privilege": privilege,
"create_time": time.Now().Unix(),
"update_time": time.Now().Unix(),
}
_, err = models.SpaceUserModel.Insert(insertValue)
if err != nil {
Expand Down
34 changes: 0 additions & 34 deletions conf/mm-wiki.bck.conf

This file was deleted.

33 changes: 21 additions & 12 deletions docs/databases/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,27 @@ INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (7, 3, 7, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (8, 3, 8, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (9, 3, 9, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (10, 2, 37, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (11, 2, 38, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (12, 2, 39, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (13, 2, 40, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (14, 2, 41, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (15, 2, 42, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (16, 2, 43, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (17, 2, 44, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (18, 2, 45, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (19, 2, 46, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (20, 2, 47, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (21, 2, 48, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (10, 2, 1, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (11, 2, 2, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (12, 2, 3, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (13, 2, 4, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (14, 2, 5, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (15, 2, 6, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (16, 2, 7, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (17, 2, 8, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (18, 2, 9, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (19, 2, 37, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (20, 2, 38, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (21, 2, 39, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (22, 2, 40, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (23, 2, 41, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (24, 2, 42, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (25, 2, 43, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (26, 2, 44, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (27, 2, 45, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (28, 2, 46, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (29, 2, 47, unix_timestamp(now()));
INSERT INTO mw_role_privilege (role_privilege_id, role_id, privilege_id, create_time) VALUES (30, 2, 48, unix_timestamp(now()));


-- -------------------------------------------
Expand Down
24 changes: 18 additions & 6 deletions install/controllers/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,34 @@ func (this *InstallController) Env() {
templateConfDir["result"] = "0"
}

docsDir := map[string]string{
databaseTable := map[string]string{
"path": "docs/databases/table.sql",
"require": "读/写",
"result": "1",
}
err = fileTool.IsWriterReadable(installDir+docsDir["path"])
err = fileTool.IsWriterReadable(installDir+databaseTable["path"])
if err != nil {
storage.Data.Env = storage.Env_NotAccess
docsDir["result"] = "0"
databaseTable["result"] = "0"
}

databaseData := map[string]string{
"path": "docs/databases/data.sql",
"require": "读/写",
"result": "1",
}
err = fileTool.IsWriterReadable(installDir+databaseData["path"])
if err != nil {
storage.Data.Env = storage.Env_NotAccess
databaseData["result"] = "0"
}

viewsDir := map[string]string{
"path": "views",
"require": "存在且不为空",
"result": "1",
}
isEmpty := utils.NewFile().PathIsEmpty(installDir+viewsDir["path"])
isEmpty := utils.File.PathIsEmpty(installDir+viewsDir["path"])
if isEmpty == true {
storage.Data.Env = storage.Env_NotAccess
viewsDir["result"] = "0"
Expand All @@ -131,15 +142,16 @@ func (this *InstallController) Env() {
"require": "存在且不为空",
"result": "1",
}
isEmpty = utils.NewFile().PathIsEmpty(installDir+staticDir["path"])
isEmpty = utils.File.PathIsEmpty(installDir+staticDir["path"])
if isEmpty == true {
storage.Data.Env = storage.Env_NotAccess
staticDir["result"] = "0"
}

dirData := []map[string]string{}
dirData = append(dirData, templateConfDir)
dirData = append(dirData, docsDir)
dirData = append(dirData, databaseTable)
dirData = append(dirData, databaseData)
dirData = append(dirData, viewsDir)
dirData = append(dirData, staticDir)

Expand Down
2 changes: 1 addition & 1 deletion install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
os.Exit(1)
}

beego.BConfig.RunMode = "prod"
//beego.BConfig.RunMode = "prod"
beego.Run(":"+*port)
}

51 changes: 34 additions & 17 deletions install/storage/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io/ioutil"
"time"
"mm-wiki/app/utils"
"os/exec"
"runtime"
"encoding/json"
)
Expand Down Expand Up @@ -176,6 +175,33 @@ func createAdmin() (err error) {
return
}

// write database install data
func writeInstallData() (err error) {
host := Data.DatabaseConf["host"]
port := Data.DatabaseConf["port"]
user := Data.DatabaseConf["user"]
pass := Data.DatabaseConf["pass"]
name := Data.DatabaseConf["name"]

installDir, _ := os.Getwd()
installDir = strings.Replace(installDir, "install", "", 1)
sqlBytes, err := ioutil.ReadFile(installDir+"docs/databases/data.sql")
if err != nil {
return err
}
sqlTable := string(sqlBytes)
db, err := sql.Open("mysql", user+":"+pass+"@tcp("+host+":"+port+")/"+name+"?charset=utf8&multiStatements=true")
if err != nil {
return
}
defer db.Close()
_, err = db.Exec(sqlTable)
if err != nil {
return
}
return nil
}

// write conf
func makeConf() (err error) {
installDir, _ := os.Getwd()
Expand Down Expand Up @@ -207,22 +233,6 @@ func makeConf() (err error) {
return
}

// run mm-wiki command
func runCodePub() (err error) {
var cmd *exec.Cmd
installDir, _ := os.Getwd()
installDir = strings.Replace(installDir, "install", "", 1)

if runtime.GOOS == "windows" {
cmd = exec.Command(installDir+"mm-wiki.exe")
}else {
cmd = exec.Command("./"+installDir+"mm-wiki")
}
cmd.Dir = installDir
err = cmd.Start()
return
}

func installFailed(err string) {
Data.Result = err
Data.Status = Install_End
Expand Down Expand Up @@ -298,6 +308,13 @@ func ListenInstall() {
continue
}
log.Println("create admin user success")
// 写入安装数据
err = writeInstallData()
if err != nil {
installFailed("导入安装数据出错:"+err.Error())
continue
}
log.Println("write install data success")
// 写入 conf 文件
err = makeConf()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion views/install/env.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</div>
<!-- 目录权限检测 -->
<div class="panel panel-default">
<div class="panel-heading"><strong><i class="fa fa-folder-open"></i> 安装目录文件检测</strong></div>
<div class="panel-heading"><strong><i class="fa fa-folder-open"></i> 目录文件检测</strong></div>
<div class="panel-body"></div>
<div class="table-responsive">
<table class="table table-bordered">
Expand Down
22 changes: 11 additions & 11 deletions views/system/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
</ul>
</li>
{{end}}
<li>
<a href="javascript:;"><i class="fa fa-lock"></i> 权限管理<span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li>
<a href="/system/privilege/add" target="mainFrame"><i class="glyphicon glyphicon-list"></i> 添加权限 </a>
</li>
<li>
<a href="/system/privilege/list" target="mainFrame"><i class="glyphicon glyphicon-list"></i> 权限列表 </a>
</li>
</ul>
</li>
{{/*<li>*/}}
{{/*<a href="javascript:;"><i class="glyphicon glyphicon-lock"></i> 权限管理<span class="fa arrow"></span></a>*/}}
{{/*<ul class="nav nav-second-level">*/}}
{{/*<li>*/}}
{{/*<a href="/system/privilege/add" target="mainFrame"><i class="glyphicon glyphicon-list"></i> 添加权限 </a>*/}}
{{/*</li>*/}}
{{/*<li>*/}}
{{/*<a href="/system/privilege/list" target="mainFrame"><i class="glyphicon glyphicon-list"></i> 权限列表 </a>*/}}
{{/*</li>*/}}
{{/*</ul>*/}}
{{/*</li>*/}}
</ul>
</div>
<script type="text/javascript">
Expand Down

0 comments on commit cf9ecd5

Please sign in to comment.