mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-06 03:51:25 +08:00
【feature】添加组织数据读取权限
This commit is contained in:
@@ -6,12 +6,13 @@ type BaseModel struct {
|
||||
Id string `json:"id" gorm:"primary_key;"`
|
||||
CreatedAt time.Time `gorm:"column:create_time" json:"createTime" form:"create_time"`
|
||||
UpdatedAt time.Time `gorm:"column:update_time" json:"updateTime" form:"update_time"`
|
||||
OrgId int64 `json:"orgId" gorm:"type:int;comment:机构ID"`
|
||||
}
|
||||
|
||||
type BaseAuthModel struct {
|
||||
Id string `json:"id" gorm:"primary_key;"`
|
||||
Owner string `json:"owner" gorm:"type:varchar(64);comment:创建者,所有者"`
|
||||
OrgId string `json:"orgId" gorm:"type:varchar(64);comment:机构ID"`
|
||||
OrgId int64 `json:"orgId" gorm:"type:int;comment:机构ID"`
|
||||
CreatedAt time.Time `gorm:"column:create_time" json:"createTime" form:"create_time"`
|
||||
UpdatedAt time.Time `gorm:"column:update_time" json:"updateTime" form:"update_time"`
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func InitRouter() *transport.HttpServer {
|
||||
// 设置路由组
|
||||
{
|
||||
sysRouter.InitSystemRouter(container)
|
||||
sysRouter.InitDeptRouter(container)
|
||||
sysRouter.InitOrganizationRouter(container)
|
||||
sysRouter.InitConfigRouter(container)
|
||||
sysRouter.InitApiRouter(container)
|
||||
sysRouter.InitDictRouter(container)
|
||||
|
||||
@@ -16,7 +16,7 @@ func InitTable() {
|
||||
biz.ErrIsNil(
|
||||
global.Db.AutoMigrate(
|
||||
//casbin.CasbinRule{},
|
||||
systemEntity.SysDept{},
|
||||
systemEntity.SysOrganization{},
|
||||
systemEntity.SysApi{},
|
||||
systemEntity.SysConfig{},
|
||||
systemEntity.SysDictType{},
|
||||
@@ -27,7 +27,7 @@ func InitTable() {
|
||||
systemEntity.SysMenu{},
|
||||
systemEntity.SysPost{},
|
||||
systemEntity.SysRoleMenu{},
|
||||
systemEntity.SysRoleDept{},
|
||||
systemEntity.SysRoleOrganization{},
|
||||
systemEntity.SysNotice{},
|
||||
|
||||
logEntity.LogLogin{},
|
||||
|
||||
@@ -20,6 +20,7 @@ func OperationHandler(rc *restfulx.ReqCtx) error {
|
||||
go func() {
|
||||
oper := entity.LogOper{
|
||||
Title: rc.LogInfo.Description,
|
||||
OrgId: rc.LoginAccount.OrganizationId,
|
||||
BusinessType: "0",
|
||||
Method: c.Request.Method,
|
||||
OperName: rc.LoginAccount.UserName,
|
||||
|
||||
@@ -60,6 +60,7 @@ func (n *createAlarmNode) Handle(msg *message.Message) error {
|
||||
alarm.State = global.ALARMING
|
||||
alarm.Type = n.AlarmType
|
||||
alarm.Time = time.Now()
|
||||
alarm.OrgId = msg.Metadata.GetValue("orgId").(int64)
|
||||
marshal, _ := json.Marshal(msg.Msg)
|
||||
alarm.Details = string(marshal)
|
||||
err := services.DeviceAlarmModelDao.Insert(*alarm)
|
||||
|
||||
@@ -40,6 +40,7 @@ func (n *logNode) Handle(msg *message.Message) error {
|
||||
MessageId: msg.Id,
|
||||
MsgType: msg.MsgType,
|
||||
DeviceId: msg.Metadata["deviceId"].(string),
|
||||
OrgId: msg.Metadata["orgId"].(int64),
|
||||
DeviceName: msg.Metadata["deviceName"].(string),
|
||||
Ts: msg.Ts,
|
||||
Content: logMessage,
|
||||
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"pandax/apps/system/services"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -12,6 +15,7 @@ import (
|
||||
|
||||
type DeviceAuth struct {
|
||||
User string `json:"user"`
|
||||
OrgId int64 `json:"orgId"`
|
||||
DeviceId string `json:"device_id"`
|
||||
DeviceType string `json:"device_type"`
|
||||
ProductId string `json:"product_id"`
|
||||
@@ -60,3 +64,11 @@ func (m *DeviceAuth) MarshalBinary() (data []byte, err error) {
|
||||
func (m *DeviceAuth) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, m)
|
||||
}
|
||||
|
||||
func OrgAuthSet(tx *gorm.DB, roleId int64) {
|
||||
// todo 使用缓存
|
||||
ids, err := services.SysRoleOrganizationModelDao.FindOrganizationsByRoleId(roleId)
|
||||
biz.ErrIsNil(err, "查询角色数据权限失败")
|
||||
biz.IsTrue(len(ids) > 0, "该角色下未分配组织权限")
|
||||
tx.Where("org_id in (?)", ids)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user