提交 26ee865c 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

角色增加数据资源功能 增加数据资源关联返回(go代码完成 api开发完成 数据库配置完成 前端实现逻辑编写中)

上级 be572a07
......@@ -84,6 +84,21 @@ func GetAuthorityList(c *gin.Context) {
}
}
type GetAuthorityId struct {
AuthorityId string `json:"authorityId"`
// @Tags authority
// @Summary 设置角色资源权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body sysModel.SysAuthority true "设置角色资源权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /authority/setDataAuthority [post]
func SetDataAuthority(c *gin.Context) {
var auth sysModel.SysAuthority
_ = c.ShouldBind(&auth)
err := auth.SetDataAuthority()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("设置关联失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "设置关联成功", gin.H{})
}
}
此差异已折叠。
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-12-20 11:36:51.4275267 +0800 CST m=+0.082812601
// 2020-01-06 17:53:22.2207663 +0800 CST m=+0.069844001
package docs
......@@ -365,6 +365,45 @@ var doc = `{
}
}
},
"/authority/setDataAuthority": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"authority"
],
"summary": "设置角色资源权限",
"parameters": [
{
"description": "设置角色资源权限",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/sysModel.SysAuthority"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"设置成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/base/login": {
"post": {
"produces": [
......@@ -616,6 +655,33 @@ var doc = `{
}
}
},
"/jwt/jsonInBlacklist": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jwt"
],
"summary": "jwt加入黑名单",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"拉黑成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/menu/addBaseMenu": {
"post": {
"security": [
......@@ -1266,6 +1332,21 @@ var doc = `{
},
"authorityName": {
"type": "string"
},
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/sysModel.SysAuthority"
}
},
"dataAuthorityId": {
"type": "array",
"items": {
"$ref": "#/definitions/sysModel.SysAuthority"
}
},
"parentId": {
"type": "string"
}
}
},
......
......@@ -348,6 +348,45 @@
}
}
},
"/authority/setDataAuthority": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"authority"
],
"summary": "设置角色资源权限",
"parameters": [
{
"description": "设置角色资源权限",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/sysModel.SysAuthority"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"设置成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/base/login": {
"post": {
"produces": [
......@@ -599,6 +638,33 @@
}
}
},
"/jwt/jsonInBlacklist": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jwt"
],
"summary": "jwt加入黑名单",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"拉黑成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/menu/addBaseMenu": {
"post": {
"security": [
......@@ -1249,6 +1315,21 @@
},
"authorityName": {
"type": "string"
},
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/sysModel.SysAuthority"
}
},
"dataAuthorityId": {
"type": "array",
"items": {
"$ref": "#/definitions/sysModel.SysAuthority"
}
},
"parentId": {
"type": "string"
}
}
},
......
......@@ -99,6 +99,16 @@ definitions:
type: string
authorityName:
type: string
children:
items:
$ref: '#/definitions/sysModel.SysAuthority'
type: array
dataAuthorityId:
items:
$ref: '#/definitions/sysModel.SysAuthority'
type: array
parentId:
type: string
type: object
sysModel.SysBaseMenu:
properties:
......@@ -394,6 +404,30 @@ paths:
summary: 分页获取角色列表
tags:
- authority
/authority/setDataAuthority:
post:
consumes:
- application/json
parameters:
- description: 设置角色资源权限
in: body
name: data
required: true
schema:
$ref: '#/definitions/sysModel.SysAuthority'
type: object
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"设置成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 设置角色资源权限
tags:
- authority
/base/login:
post:
parameters:
......@@ -550,6 +584,22 @@ paths:
summary: 上传文件示例
tags:
- ExaFileUploadAndDownload
/jwt/jsonInBlacklist:
post:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"拉黑成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: jwt加入黑名单
tags:
- jwt
/menu/addBaseMenu:
post:
consumes:
......
......@@ -10,10 +10,11 @@ import (
type SysAuthority struct {
gorm.Model
AuthorityId string `json:"authorityId" gorm:"not null;unique"`
AuthorityName string `json:"authorityName"`
ParentId string `json:"parentId"`
Children []SysAuthority `json:"children"`
AuthorityId string `json:"authorityId" gorm:"not null;unique"`
AuthorityName string `json:"authorityName"`
ParentId string `json:"parentId"`
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;association_jointable_foreignkey:data_id"`
Children []SysAuthority `json:"children"`
}
// 创建角色
......@@ -47,7 +48,7 @@ func (a *SysAuthority) GetInfoList(info modelInterface.PageInfo) (err error, lis
return
} else {
var authority []SysAuthority
err = db.Where("parent_id = 0").Find(&authority).Error
err = db.Preload("DataAuthorityId").Where("parent_id = 0").Find(&authority).Error
if len(authority) > 0 {
for k, _ := range authority {
err = findChildrenAuthority(&authority[k])
......@@ -58,7 +59,7 @@ func (a *SysAuthority) GetInfoList(info modelInterface.PageInfo) (err error, lis
}
func findChildrenAuthority(authority *SysAuthority) (err error) {
err = qmsql.DEFAULTDB.Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error
err = qmsql.DEFAULTDB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error
if len(authority.Children) > 0 {
for k, _ := range authority.Children {
err = findChildrenAuthority(&authority.Children[k])
......@@ -66,3 +67,10 @@ func findChildrenAuthority(authority *SysAuthority) (err error) {
}
return err
}
func (a *SysAuthority) SetDataAuthority() error {
var s SysAuthority
qmsql.DEFAULTDB.Preload("DataAuthorityId").First(&s, "id = ?", a.ID)
err := qmsql.DEFAULTDB.Model(&s).Association("DataAuthorityId").Replace(&a.DataAuthorityId).Error
return err
}
......@@ -12,5 +12,6 @@ func InitAuthorityRouter(Router *gin.RouterGroup) {
AuthorityRouter.POST("createAuthority", api.CreateAuthority) //创建角色
AuthorityRouter.POST("deleteAuthority", api.DeleteAuthority) //删除角色
AuthorityRouter.POST("getAuthorityList", api.GetAuthorityList) //获取角色列表
AuthorityRouter.POST("setDataAuthority", api.SetDataAuthority) //设置角色资源权限
}
}
......@@ -152,3 +152,8 @@ swag init
<h3>qq交流群:622360840</h3>
<h3>微信交流群可以添加任意一位开发者备注"加入gin-vue-admin交流群"</h3>
</div>
## 更新日志
2020/01/07 角色增加数据资源功能 增加数据资源关联返回(go代码完成 api开发完成 数据库配置完成 前端实现逻辑编写中)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册