Skip to content

Commit

Permalink
feature(http): add json options to replace body content
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Aug 16, 2022
1 parent dc83eb6 commit 7059235
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
20 changes: 10 additions & 10 deletions authorization/rbac/models/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type Permission struct {

PermissionModule *PermissionModule `gorm:"ForeignKey:ModuleID;references:UniqueID" json:"permissionModule"`

UniqueID string `gorm:"column:index_permission_id;index:,unique" json:"permissionID"`
SubjectAlias string `gorm:"column:subject_alias" json:"subjectAlias"`
SubjectValue string `gorm:"column:subject_value; not null;" json:"subjectValue"`
Action string `gorm:"column:action; not null;" json:"action"`
Description string `gorm:"column:description" json:"description"`
ModuleID *string `gorm:"column:module_id" json:"moduleID"`
UniqueID string `gorm:"column:index_permission_id;index:,unique" json:"permissionID"`
ObjectAlias string `gorm:"column:object_alias" json:"objectAlias"`
ObjectValue string `gorm:"column:object_value; not null;" json:"objectValue"`
Action string `gorm:"column:action; not null;" json:"action"`
Description string `gorm:"column:description" json:"description"`
ModuleID *string `gorm:"column:module_id" json:"moduleID"`
}

const TABLE_NAME_PERMISSION = "rbac_permissions"
Expand All @@ -42,8 +42,8 @@ func NewPermission(mapObject *object.Collection) *Permission {

newPermission := &Permission{
PowerCompactModel: database.NewPowerCompactModel(),
SubjectAlias: mapObject.GetString("subjectAlias", ""),
SubjectValue: mapObject.GetString("subjectValue", ""),
ObjectAlias: mapObject.GetString("objectAlias", ""),
ObjectValue: mapObject.GetString("objectValue", ""),
Action: mapObject.GetString("action", ""),
Description: mapObject.GetString("description", ""),
ModuleID: mapObject.GetStringPointer("moduleID", ""),
Expand Down Expand Up @@ -73,7 +73,7 @@ func (mdl *Permission) GetForeignValue() string {

func (mdl *Permission) GetComposedUniqueID() string {

strKey := mdl.Action + "-" + mdl.SubjectValue
strKey := mdl.Action + "-" + mdl.ObjectValue
//fmt2.Dump(strKey)
hashKey := security.HashStringData(strKey)

Expand All @@ -84,7 +84,7 @@ func (mdl *Permission) CheckPermissionNameAvailable(db *gorm.DB) (err error) {

result := db.
//Debug().
Where("subject_alias", mdl.SubjectAlias).
Where("object_alias", mdl.ObjectAlias).
Where("index_permission_id != ?", mdl.UniqueID).
First(&Permission{})

Expand Down
16 changes: 11 additions & 5 deletions authorization/rbac/models/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const TABLE_NAME_ROLE = "roles"

const ROLE_UNIQUE_ID = "index_role_id"

const ROLE_TYPE_ALL int8 = 0
const ROLE_TYPE_SYSTEM int8 = 1
const ROLE_TYPE_NORMAL int8 = 2

Expand Down Expand Up @@ -102,15 +103,20 @@ func (mdl *Role) GetEmployeeComposedUniqueID() string {
}

func (mdl *Role) GetTreeList(db *gorm.DB, conditions *map[string]interface{}, preloads []string,
parentID *string, needQueryChildren bool,
roleType int8, parentID *string, needQueryChildren bool,
) (roles []*Role, err error) {
roles = []*Role{}

if conditions == nil {
conditions = &map[string]interface{}{}
}

if parentID != nil {
if conditions == nil {
conditions = &map[string]interface{}{}
}
(*conditions)["parent_id"] = parentID
}
if roleType != ROLE_TYPE_ALL {
(*conditions)["type"] = roleType
}

err = database.GetAllList(db, conditions, &roles, preloads)
if err != nil {
Expand All @@ -119,7 +125,7 @@ func (mdl *Role) GetTreeList(db *gorm.DB, conditions *map[string]interface{}, pr

if needQueryChildren {
for _, role := range roles {
children, err := mdl.GetTreeList(db, conditions, preloads, &role.UniqueID, needQueryChildren)
children, err := mdl.GetTreeList(db, conditions, preloads, roleType, &role.UniqueID, needQueryChildren)
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions http/drivers/gout/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func (client *Client) PrepareRequest(method string, uri string, options *object.
} else {
headers = &object.HashMap{}
}

if (*options)["json"] != nil {
(*options)["body"], err = object.JsonEncode((*options)["json"])
if err != nil {
return nil, nil, nil, nil, "", false, err
}
}
if (*options)["body"] != nil {
body = (*options)["body"]
} else {
Expand Down

0 comments on commit 7059235

Please sign in to comment.