Skip to content

Commit

Permalink
fix bug of permission
Browse files Browse the repository at this point in the history
  • Loading branch information
3xxx committed May 3, 2018
1 parent e5a881c commit b1922c6
Show file tree
Hide file tree
Showing 25 changed files with 240 additions and 129 deletions.
8 changes: 5 additions & 3 deletions History.txt
@@ -1,11 +1,13 @@
EngineerCMS revision history
7, EngineerCMS 1.01 (Apr 30, 2018)
8, EngineerCMS 1.03 (May 3, 2018)
*) Fixed bug of role permission
7, EngineerCMS 1.02 (Apr 30, 2018)
*) Fixed bug of onlyoffice permission
6, EngineerCMS 1.01 (Apr 25, 2018)
+) Add project permission query&update
5, EngineerCMS 1.01 (Feb 20, 2018)
5, EngineerCMS 1.0 (Feb 20, 2018)
+) Add ONLYOFFICE Document Server
4, EngineerCMS 0.92 (Feb 10, 2017)
4, EngineerCMS 0.93 (Feb 10, 2017)
+) Add project role
+) Add cms service
*) Fixed bug of product editor
Expand Down
4 changes: 2 additions & 2 deletions controllers/default.go
Expand Up @@ -299,10 +299,10 @@ func (c *MainController) Test() {
beego.Error(err)
}
if matched == true {
beego.Info("移动端~")
// beego.Info("移动端~")
c.TplName = "test1.tpl"
} else {
beego.Info("电脑端!")
// beego.Info("电脑端!")
c.TplName = "test.tpl"
}
// var u = navigator.userAgent, app = navigator.appVersion;
Expand Down
13 changes: 12 additions & 1 deletion controllers/login.go
Expand Up @@ -51,7 +51,18 @@ func (c *LoginController) Get() {
// c.Ctx.Input.CruSession.Delete("gosessionid")这句与上面一句重复
// c.Ctx.Input.CruSession.Flush()
// beego.GlobalSessions.SessionDestroy(c.Ctx.ResponseWriter, c.Ctx.Request)
c.DelSession("uname")
v := c.GetSession("uname")
// islogin := false
if v != nil {
//删除指定的session
c.DelSession("uname")
//销毁全部的session
c.DestroySession()
// islogin = true

//beego.Info("当前的session:")
//beego.Info(c.CruSession)
}
// sess.Flush()//这个不灵
c.Redirect("/", 301)
return
Expand Down
6 changes: 3 additions & 3 deletions controllers/onlyoffice.go
Expand Up @@ -204,10 +204,10 @@ func (c *OnlyController) Get() {
beego.Error(err)
}
if matched == true {
beego.Info("移动端~")
// beego.Info("移动端~")
c.TplName = "onlyoffice/docs.tpl"
} else {
beego.Info("电脑端!")
// beego.Info("电脑端!")
c.TplName = "onlyoffice/docs.tpl"
}
// c.Data["Url"] = c.Ctx.Request.URL.String()
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func (c *OnlyController) Addpermission() {
if err != nil {
beego.Error(err)
}
//循环删除成果

//根据成果id取得所有附件——这里只取第一个
attachments, err := models.GetOnlyAttachments(idNum)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/record.go
Expand Up @@ -476,7 +476,7 @@ func SubStrings(filenameWithSuffix string) (substr1, substr2 string) {
re, _ := regexp.Compile("[^a-zA-Z0-9-~]") //2016-1-11日拟修改DZ122D.5-10-15~15.dwg
loc := re.FindStringIndex(filenameOnly)
// fmt.Println(str[loc[0]:loc[1]])
beego.Info(loc[0])
// beego.Info(loc[0])
if loc != nil {
end = loc[0]
fulleFilename1 = SubString(filenameOnly, 0, end)
Expand Down
76 changes: 61 additions & 15 deletions controllers/roleControllers.go
Expand Up @@ -431,15 +431,36 @@ func (c *RoleController) UserRole() {
//给角色赋项目目录的权限
//先删除角色对于这个项目的所有权限
func (c *RoleController) RolePermission() {
var success bool
var nodeidint int
var projurl, action, suf1, suf string
var err error
roleids := c.GetString("roleids")
rolearray := strings.Split(roleids, ",")
// beego.Info(rolearray)
permissionids := c.GetString("permissionids")
permissionarray := strings.Split(permissionids, ",")
switch permissionarray[0] {
case "添加成果":
action = "POST"
case "编辑成果":
action = "PUT"
case "删除成果":
action = "DELETE"
case "读取成果":
action = "GET"
}
// beego.Info(permissionarray)
sufids := c.GetString("sufids")
sufarray := strings.Split(sufids, ",")

switch sufids {
case "任意":
suf = ".*"
case "":
suf = "(?i:PDF)"
case "PDF":
suf = "(?i:PDF)"
}
treeids := c.GetString("treeids") //项目目录id,25001,25002
treearray := strings.Split(treeids, ",")
// beego.Info(treearray)
Expand All @@ -455,10 +476,6 @@ func (c *RoleController) RolePermission() {
// beego.Error(err)
// }

var success bool
var nodeidint int
var projurl, action, suf1, suf string
var err error
//取出项目目录的顶级
var nodesid, nodesids []string
// beego.Info(len(treenodearray))
Expand All @@ -472,16 +489,25 @@ func (c *RoleController) RolePermission() {
}
// beego.Info(nodesids)

//删除这些角色、项目id的全部权限
//删除这些角色、项目id、权限的全部权限
for _, v1 := range rolearray {
// var paths []beegoormadapter.CasbinRule
o := orm.NewOrm()
qs := o.QueryTable("casbin_rule")
_, err := qs.Filter("PType", "p").Filter("v0", "role_"+v1).Filter("v1__contains", "/"+projectid+"/").Delete()
if err != nil {
beego.Error(err)
if action == "GET" {
_, err := qs.Filter("PType", "p").Filter("v0", "role_"+v1).Filter("v1__contains", "/"+projectid+"/").Filter("v2", action).Filter("v3", suf).Delete()
if err != nil {
beego.Error(err)
}
} else {
_, err := qs.Filter("PType", "p").Filter("v0", "role_"+v1).Filter("v1__contains", "/"+projectid+"/").Filter("v2", action).Delete()
if err != nil {
beego.Error(err)
}
}
}

e.LoadPolicy() //重载权限
// e.RemoveFilteredPolicy(1, "/onlyoffice/"+strconv.FormatInt(attachments[0].Id, 10))

for _, v1 := range rolearray {
Expand All @@ -504,7 +530,7 @@ func (c *RoleController) RolePermission() {
suf = ".*"
break
} else if v4 == "" { //用户没展开则读取不到table4的select
suf = "(?i:pdf)"
suf = "(?i:PDF)"
break
} else {
suf1 = "(?i:" + v4 + ")"
Expand Down Expand Up @@ -538,7 +564,7 @@ func (c *RoleController) RolePermission() {
} else {
projurl = "/" + strings.Replace(proj.ParentIdPath, "-", "/", -1) + "/" + treearray[nodeidint] + "/*"
}
beego.Info(v1)
// beego.Info(v1)
// beego.Info(projurl)
// beego.Info(action)
// beego.Info(suf)
Expand All @@ -551,7 +577,7 @@ func (c *RoleController) RolePermission() {
}
}

e.LoadPolicy() //重载权限
// e.LoadPolicy() //重载权限

if success == true {
c.Data["json"] = "ok"
Expand Down Expand Up @@ -596,6 +622,18 @@ func (c *RoleController) GetRolePermission() {
roleid := c.GetString("roleid") //角色id
action := c.GetString("action")
projectid := c.GetString("projectid")
sufids := c.GetString("sufids") //扩展名
// beego.Info(sufids)
var suf string
switch sufids {
case "任意":
suf = ".*"
case "":
suf = "(?i:PDF)"
case "PDF":
suf = "(?i:PDF)"
}
// beego.Info(suf)
// beego.Info(roleid)
// beego.Info(action)
// beego.Info(projectid)
Expand All @@ -615,9 +653,17 @@ func (c *RoleController) GetRolePermission() {
var paths []beegoormadapter.CasbinRule
o := orm.NewOrm()
qs := o.QueryTable("casbin_rule")
_, err := qs.Filter("PType", "p").Filter("v0", "role_"+roleid).Filter("v1__contains", "/"+projectid+"/").Filter("v2", action).All(&paths)
if err != nil {
beego.Error(err)
if action == "GET" || action == "" {
_, err := qs.Filter("PType", "p").Filter("v0", "role_"+roleid).Filter("v1__contains", "/"+projectid+"/").Filter("v2", "GET").Filter("v3", suf).All(&paths)
if err != nil {
beego.Error(err)
}
// beego.Info(paths)
} else {
_, err := qs.Filter("PType", "p").Filter("v0", "role_"+roleid).Filter("v1__contains", "/"+projectid+"/").Filter("v2", action).All(&paths)
if err != nil {
beego.Error(err)
}
}
// beego.Info(paths)
var projids []string
Expand Down
6 changes: 3 additions & 3 deletions controllers/ueditor.go
Expand Up @@ -137,7 +137,7 @@ func (c *UeditorController) ControllerUE() {
default:
//解析表单
pid := c.Input().Get("pid")
beego.Info(pid)
// beego.Info(pid)
//pid转成64为
pidNum, err := strconv.ParseInt(pid, 10, 64)
if err != nil {
Expand All @@ -148,7 +148,7 @@ func (c *UeditorController) ControllerUE() {
if err != nil {
beego.Error(err)
}
beego.Info(DiskDirectory)
// beego.Info(DiskDirectory)
//获取上传的文件
_, h, err := c.GetFile("upfile")
if err != nil {
Expand Down Expand Up @@ -315,7 +315,7 @@ func (c *UeditorController) ControllerUE() {
c.ServeJSON()

file, header, err := c.GetFile("source") // r.FormFile("upfile")
beego.Info(header.Filename)
// beego.Info(header.Filename)
if err != nil {
panic(err)
}
Expand Down
Binary file modified database/engineer.db
Binary file not shown.
Binary file removed document/施工分院用户数据.xlsx
Binary file not shown.
Binary file added document/用户数据.xlsx
Binary file not shown.
Binary file added static/img/EngineerCMS onlyoffice.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/oo doc role permission.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/oo doc user permission.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/个人日历事件.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/用户-角色.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/组织结构.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/编辑目录.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/角色-权限.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/项目分级目录.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/js/bootstrap-table-zh-CN.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions views/admin_calendar.tpl
Expand Up @@ -11,7 +11,7 @@
<script type="text/javascript" src="/static/js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap-table.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap-table-zh-CN.min.js"></script>

<script type="text/javascript" src="/static/js/jquery-ui.min.js"></script>
<link rel='stylesheet' href='/static/css/fullcalendar.min.css'/>
<script src='/static/js/fullcalendar.min.js'></script>
<script src='/static/js/fullcalendar.zh-cn.js'></script>
Expand All @@ -22,6 +22,7 @@
<link rel="stylesheet" type="text/css" href="/static/font-awesome-4.7.0/css/font-awesome.min.css"/>

<style>
#modalDialog .modal-header {cursor: move;}
/*body {
margin: 0;
padding: 0;
Expand Down Expand Up @@ -545,9 +546,9 @@
<div class="container">
<form class="form-horizontal">
<div class="modal fade" id="modalTable">
<div class="modal-dialog">
<div class="modal-dialog" id="modalDialog">
<div class="modal-content">
<div class="modal-header">
<div class="modal-header" style="background-color: #FF5722;">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
</button>
Expand Down Expand Up @@ -861,6 +862,11 @@
$('#add-new-event1').css({"background-color": currColor, "border-color": currColor});
});
//模态框可移动
$(document).ready(function(){
$("#modalDialog").draggable({ handle: ".modal-header" });//为模态对话框添加拖拽,仅头部能拖动
$("#myModal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
})
// $("#isallday").click(function(){//是否是全天事件
// if($("#sel_start").css("display")=="none"){
// $("#sel_start,#sel_end").show();
Expand Down

0 comments on commit b1922c6

Please sign in to comment.