Skip to content

Commit

Permalink
#2486 菜单绑定API权限
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjiawei committed Jan 9, 2025
1 parent 29e413e commit f7798ea
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions platform-core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN mkdir -p $BASE_HOME $BASE_HOME/config $BASE_HOME/logs

ADD build/start.sh $BASE_HOME/
ADD config/default.json $BASE_HOME/config/
ADD config/menu-api-map.json $BASE_HOME/config/
ADD config/i18n $BASE_HOME/config/i18n/
ADD platform-core $BASE_HOME/

Expand Down
2 changes: 1 addition & 1 deletion platform-core/api/middleware/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func AuthToken(c *gin.Context) {
ReturnAuthError(c, exterror.Catch(exterror.New().RequestTokenValidateError, err), c.GetHeader(models.AuthorizationHeader))
c.Abort()
} else {
if models.Config.MenuApiMap.Enable {
if models.Config.MenuApiMap.Enable == "true" || strings.TrimSpace(models.Config.MenuApiMap.Enable) == "" || strings.ToUpper(models.Config.MenuApiMap.Enable) == "Y" {
legal := validateMenuApi(GetRequestRoles(c), c.Request.URL.Path, c.Request.Method)
if legal {
c.Next()
Expand Down
1 change: 1 addition & 0 deletions platform-core/build/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sed -i "s~{{sub_system_private_key}}~$sub_system_private_key~g" /app/platform-co
sed -i "s~{{cron_keep_batch_exec_days}}~$cron_keep_batch_exec_days~g" /app/platform-core/config/default.json
sed -i "s~{{host_ip}}~$host_ip~g" /app/platform-core/config/default.json
sed -i "s~{{encrypt_seed}}~$encrypt_seed~g" /app/platform-core/config/default.json
sed -i "s~{{menu_api_map_enable}}~$menu_api_map_enable~g" /app/platform-core/config/default.json

exec ./platform-core

2 changes: 1 addition & 1 deletion platform-core/common/exterror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ErrorTemplate struct {
RequestJsonUnmarshalError CustomError `json:"request_json_unmarshal_error"`
RequestTokenValidateError CustomError `json:"request_token_validate_error"`
RequestTokenExpireError CustomError `json:"request_token_expire_error"`
ApiPermissionDeniedError CustomError `json:"api_permission_error"`
ApiPermissionDeniedError CustomError `json:"api_permission_deny"`
// database error
DatabaseQueryError CustomError `json:"database_query_error"`
DatabaseQueryEmptyError CustomError `json:"database_query_empty_error"`
Expand Down
2 changes: 1 addition & 1 deletion platform-core/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"host_ports": "{{gateway_host_ports}}"
},
"menu_api_map": {
"enable": true,
"enable": "{{menu_api_map_enable}}",
"file": "config/menu-api-map.json"
},
"cron": {
Expand Down
8 changes: 4 additions & 4 deletions platform-core/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
"code": 10000031,
"message": "System error [Failed to handle request]"
},
"api_permission_error": {
"code": 10000032,
"message": "System error [Permission denied]"
},
"plugin_dependency_illegal": {
"code": 20000001,
"message": "Installation Failed: The plug-in version dependency verification failed"
Expand Down Expand Up @@ -183,5 +179,9 @@
"export_customer_add_name_exist_error": {
"code": 20000040,
"message": "Save Failed: The target customer with the same name already exists. Please modify the name and try again"
},
"api_permission_deny": {
"code": 20000041,
"message": "Api Permission Deny"
}
}
8 changes: 4 additions & 4 deletions platform-core/config/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
"code": 10000031,
"message": "系统报错 [服务请求处理失败]"
},
"api_permission_error": {
"code": 10000032,
"message": "系统报错 [没有API权限]"
},
"plugin_dependency_illegal": {
"code": 20000001,
"message": "安装失败:插件版本依赖校验失败"
Expand Down Expand Up @@ -183,5 +179,9 @@
"export_customer_add_name_exist_error": {
"code": 20000040,
"message": "保存失败:同名目标客户已存在,请修改名称后重试"
},
"api_permission_deny": {
"code": 20000041,
"message": "无接口访问权限"
}
}
1 change: 1 addition & 0 deletions platform-core/docker-compose.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ services:
- cron_keep_batch_exec_days=[#cron_keep_batch_exec_days]
- host_ip=[#host_ip]
- encrypt_seed=[#encrypt_seed]
- menu_api_map_enable=[#menu_api_map_enable]
4 changes: 2 additions & 2 deletions platform-core/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type CronConfig struct {
KeepBatchExecDays int64 `json:"keep_batch_exec_days"`
}
type MenuApiMapConfig struct {
Enable bool `json:"enable"`
Enable string `json:"enable"`
File string `json:"file"`
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func InitConfig(configFile string) (errMessage string) {
c.Auth.SubSystemPrivateKey = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAwnTN7JDXFcSoikXuNOQDtAjic1Wu6oAtCQJquCJmXrBTqB7hwS2mK6TuT8P7Jx60BQcaRL12hPLi6cOiCawuVwIDAQABAkB9NORazDARjhzPW5OzbpWL2KSmiqcjywA0at/4S/4KPPM8vwRjzEMs7pV9nSJ2M+/YOqPMBDl8iBUSLpfKf/uxAiEA52UroIvo2URlmAycaJm7+e4QqqfhEnM9wlGCJwL2jTsCIQDXIh2zwN7KQEIypmOL+uXvlZUjmx0Tj29mWOwP/fBBlQIhAI9+VLSlror1eE73GxNeqoxNznYVz2RCpLzZEO4iT0S7AiARg0Z1tpKsVjTNWLwrzf3f1gZxApSIXhnMdBqrZpmjTQIhAJhgYctlaydmggTPCqWLGub9WqEyH2HrrcabRvpWdEcV"
}
Config = &c
if Config.MenuApiMap.Enable {
if Config.MenuApiMap.Enable == "true" || strings.TrimSpace(Config.MenuApiMap.Enable) == "" || strings.ToUpper(Config.MenuApiMap.Enable) == "Y" {
maBytes, err := ioutil.ReadFile(Config.MenuApiMap.File)
if err != nil {
errMessage = "read menu api map file fail," + err.Error()
Expand Down

0 comments on commit f7798ea

Please sign in to comment.