feat: Implement Oauth2 login log service and repository

- Added Oauth2LogLoginService for managing user authorization logs.
- Implemented methods for inserting logs, cleaning logs, and exporting log data.
- Created a new file for Oauth2 login log service.

refactor: Remove unused open_api module

- Deleted the open_api.go file as it was not utilized in the project.

fix: Update error codes in SysProfileController

- Changed error codes for binding errors and user authentication errors to more descriptive values.

fix: Update cache handling in SysConfig and SysDictType services

- Modified Redis set operations to include expiration time for cached values.

refactor: Update middleware authorization checks

- Replaced PreAuthorize middleware with AuthorizeUser across multiple routes in system and tool modules for consistency.

chore: Clean up trace and ws modules

- Updated middleware authorization in trace and ws modules to use AuthorizeUser.
This commit is contained in:
TsMask
2025-04-27 11:07:34 +08:00
parent b29a36e7b5
commit 56991a0b49
72 changed files with 2334 additions and 873 deletions

View File

@@ -23,15 +23,14 @@ func Setup(router *gin.Engine) {
monitorGroup := router.Group("/monitor")
{
monitorGroup.GET("/load",
middleware.PreAuthorize(nil),
middleware.AuthorizeUser(nil),
controller.NewMonitor.Load,
)
}
// 服务器信息
router.GET("/monitor/system",
// middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:system:info"}}),
middleware.PreAuthorize(nil),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:system:info"}}),
controller.NewSystem.Info,
)
@@ -39,11 +38,11 @@ func Setup(router *gin.Engine) {
sysUserOnlineGroup := router.Group("/monitor/user-online")
{
sysUserOnlineGroup.GET("/list",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:online:list"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:online:list"}}),
controller.NewSysUserOnline.List,
)
sysUserOnlineGroup.DELETE("/logout/:tokenId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:online:logout"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:online:logout"}}),
controller.NewSysUserOnline.Logout,
)
}
@@ -52,32 +51,31 @@ func Setup(router *gin.Engine) {
sysCacheGroup := router.Group("/monitor/cache")
{
sysCacheGroup.GET("",
// middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:info"}}),
middleware.PreAuthorize(nil),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:info"}}),
controller.NewSysCache.Info,
)
sysCacheGroup.GET("/names",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:list"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:list"}}),
controller.NewSysCache.Names,
)
sysCacheGroup.GET("/keys",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:list"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:list"}}),
controller.NewSysCache.Keys,
)
sysCacheGroup.GET("/value",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:query"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:query"}}),
controller.NewSysCache.Value,
)
sysCacheGroup.DELETE("/names",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:remove"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:remove"}}),
controller.NewSysCache.CleanNames,
)
sysCacheGroup.DELETE("/keys",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:remove"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:remove"}}),
controller.NewSysCache.CleanKeys,
)
sysCacheGroup.DELETE("/value",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:cache:remove"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:cache:remove"}}),
controller.NewSysCache.CleanValue,
)
}
@@ -86,26 +84,26 @@ func Setup(router *gin.Engine) {
sysJobLogGroup := router.Group("/monitor/job/log")
{
sysJobLogGroup.GET("/list",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:list"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:list"}}),
controller.NewSysJobLog.List,
)
sysJobLogGroup.GET("/:logId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:query"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:query"}}),
controller.NewSysJobLog.Info,
)
sysJobLogGroup.DELETE("/:logId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:remove"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:remove"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJobLog", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysJobLog.Remove,
)
sysJobLogGroup.DELETE("/clean",
repeat.RepeatSubmit(5),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:remove"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:remove"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJobLog", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysJobLog.Clean,
)
sysJobLogGroup.GET("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:export"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:export"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJobLog", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysJobLog.Export,
)
@@ -115,47 +113,47 @@ func Setup(router *gin.Engine) {
sysJobGroup := router.Group("/monitor/job")
{
sysJobGroup.GET("/list",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:list"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:list"}}),
controller.NewSysJob.List,
)
sysJobGroup.GET("/:jobId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:query"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:query"}}),
controller.NewSysJob.Info,
)
sysJobGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:add"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:add"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysJob.Add,
)
sysJobGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:edit"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:edit"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysJob.Edit,
)
sysJobGroup.DELETE("/:jobId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:remove"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:remove"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysJob.Remove,
)
sysJobGroup.PUT("/status",
repeat.RepeatSubmit(5),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:changeStatus"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:changeStatus"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysJob.Status,
)
sysJobGroup.PUT("/run/:jobId",
repeat.RepeatSubmit(10),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:changeStatus"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:changeStatus"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysJob.Run,
)
sysJobGroup.PUT("/reset",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:changeStatus"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:changeStatus"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysJob.ResetQueueJob,
)
sysJobGroup.GET("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"monitor:job:export"}}),
middleware.AuthorizeUser(map[string][]string{"hasPerms": {"monitor:job:export"}}),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysJob", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysJob.Export,
)