2
3
lining 5 rokov pred
rodič
commit
a65574f1b1

+ 68 - 2
src/dashoo.cn/backend/api/controllers/casbin/role.go

@@ -73,6 +73,27 @@ func (this *RoleController) RoleList() {
 	this.ServeJSON()
 }
 
+// @Title 是否是管理员
+// @Description 是否是管理员
+// @Success 200 {object} controllers.Request
+// @router /getAdmin [get]
+func (this *RoleController) GetAdmin() {
+	var datainfo ErrorDataInfo
+	//判断超级管理员和有查看所有数据权限的用户
+	svcPerm := permission.GetPermissionService(utils.DBE)
+	if svcPerm.IsAdmin(this.User.Id) {
+		datainfo.Code = 1
+		this.Data["json"] = &datainfo
+		this.ServeJSON()
+		return
+	} else {
+		datainfo.Code = 0
+		this.Data["json"] = &datainfo
+		this.ServeJSON()
+		return
+	}
+}
+
 // @Title 角色列表
 // @Description 获取角色列表
 // @Success 200 {object} controllers.Request
@@ -81,7 +102,7 @@ func (this *RoleController) GetAdminPermision() {
 	var datainfo ErrorDataInfo
 	//判断超级管理员和有查看所有数据权限的用户
 	svcPerm := permission.GetPermissionService(utils.DBE)
-	isauth := svcPerm.IsAuthorized(this.User.Id, "oil_supplier.marketAccess.AllRecord")
+	isauth := svcPerm.IsAuthorized(this.User.Id, "oil_admin")
 	if svcPerm.IsAdmin(this.User.Id) || isauth {
 		datainfo.Code = 1
 		this.Data["json"] = &datainfo
@@ -674,10 +695,11 @@ func (this *RoleController) RoleAddPost() {
 	roleentity.CreateBy = this.User.Realname
 	svc := userRole.GetRoleService(utils.DBE)
 	err := svc.AddRole(&roleentity)
-	var errinfo ErrorInfo
+	var errinfo ErrorDataInfo
 	if err == nil {
 		errinfo.Message = utils.AlertProcess("创建角色成功!")
 		errinfo.Code = 0
+		errinfo.Item = &roleentity
 		this.Data["json"] = &errinfo
 		this.ServeJSON()
 	} else {
@@ -715,3 +737,47 @@ func (this *RoleController) RoleEditPost() {
 		this.ServeJSON()
 	}
 }
+
+
+// @Title 添加角色后 添加到角色管理
+// @Description 用户角色设置
+// @Success	200	{object} controllers.Request
+// @router /addsetrolemanage/:id [put]
+func (this *RoleController) AddSetRoleManage() {
+
+	inputstr := this.Ctx.Input.Param(":id")
+	serial := strings.Split(inputstr, "-")
+	roleid := serial[0]
+
+	var errinfo ErrorInfo
+	if roleid == "" || roleid == "0" {
+		errinfo.Message = "操作失败!请求信息不完整"
+		errinfo.Code = -2
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+		return
+	}
+	svc := permission.GetPermissionService(utils.DBE)
+	roleids := svc.GetManRoleForRole("rid_" + roleid)
+	roleids = roleids + "," + serial[1]
+	roleArr := strings.Split(roleids, ",")
+	utils.RBAC.RemoveFilteredNamedGroupingPolicy("g5", 0, "rid_"+roleid, utils.DOMAIN)
+	if len(roleArr) > 0 {
+		for i := 0; i < len(roleArr); i++ {
+			roids := utils.ToStr(roleArr[i])
+			utils.RBAC.AddNamedGroupingPolicy("g5", "rid_"+roleid, utils.DOMAIN, "rid_"+roids)
+		}
+	}
+	var err error = nil
+	if err == nil {
+		errinfo.Message = utils.AlertProcess("添加成功!")
+		errinfo.Code = 0
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+	} else {
+		errinfo.Message = utils.AlertProcess("添加失败!" + err.Error())
+		errinfo.Code = -1
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+	}
+}

+ 51 - 9
src/dashoo.cn/frontend_web/src/pages/system/userrole.vue

@@ -80,7 +80,7 @@
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button @click="dialogVisible = false">取 消</el-button>
-        <el-button type="primary" @click="savedata()">确 定</el-button>
+        <el-button type="primary" @click="savedata()" :loading="roleloading">确 定</el-button>
       </div>
     </el-dialog>
     <!-- 用户列表 -->
@@ -272,10 +272,12 @@
   export default {
     name: 'userrole',
     computed: mapGetters({
-      session: 'session'
+      session: 'session',
+      authUser: 'authUser'
     }),
     data() {
       return {
+        roleloading: false,
         //超级管理员添加用户
         adminadduser: false,
         orgtreelist: [],
@@ -367,11 +369,14 @@
         equipCheckAll: false,
         rolesToOpsPerList: [],
         currentPerIdForAddRoleToOps: '',
-        appclient: ''
+        appclient: '',
+        Roleids: '',
       }
     },
     created() {
       this.appclient = process.env.appclient
+      this.Roleids = this.authUser.Profile.Roleids
+
       // initial data
       this.initData()
       //this.getallequipmentlist()
@@ -521,7 +526,6 @@
           _size: this.setrolesize
         }
         this.$axios.get('role/getauditerbydept/' + deptid, {params}).then(res => {
-          console.log(res, 'res')
           this.userOptions = res.data.items
           this.currentSetRoleItemCount = res.data.currentItemCount
             //this.adminuserlistfilter()
@@ -669,6 +673,7 @@
       },
       initUserList(rid) {
         let _this = this
+        _this.userList = []
         // paginate
         const params = {
           _currentPage: this.currentUserPage,
@@ -894,17 +899,27 @@
           return
         }
         let _this = this
+        _this.roleloading = true
         if (this.dialogtitle === '添加角色') {
           _this.$axios.post('role/', _this.roleform)
             .then(res => {
               // response
               if (res.data.code === 0) {
-                _this.$message({
-                  type: 'success',
-                  message: res.data.message
-                })
+                if (this.Roleids.indexOf('10000216') !== -1) {
+                  if (res.data.item) {
+                    this.addSetRoleManage('10000216', res.data.item.Id)
+                  }
+                } else {
+                  this.getallrolelist()
+                  this.getroleData()
+                  this.initData()
+                  _this.$message({
+                    type: 'success',
+                    message: res.data.message
+                  })
+                }
                 _this.dialogVisible = false
-                this.initData()
+                _this.roleloading = false
               } else {
                 _this.$message({
                   type: 'warning',
@@ -914,6 +929,7 @@
             })
             .catch(err => {
               // handle error
+              _this.roleloading = false
               console.error(err)
             })
         } else {
@@ -938,6 +954,32 @@
             .catch(() => {})
         }
       },
+      addSetRoleManage (val, id) {
+        // request
+        this.$axios.put('role/addsetrolemanage/' + val + '-' + id)
+          .then(res => {
+            if (res.data.code === 0) {
+              this.$message({
+                type: 'success',
+                message: res.data.message
+              })
+              this.dialogVisible = false
+              // 更新界面
+              this.getallrolelist()
+              this.getroleData()
+              this.initData()
+            } else {
+              this.$message({
+                type: 'warning',
+                message: res.data.message
+              })
+            }
+          })
+          .catch(err => {
+            // handle error
+            console.error(err)
+          })
+      },
       savepower() {
         let orgids = []
         let selectnodes = this.$refs.modulepowertree.getCheckedNodes(false, true)