Skip to content

Commit

Permalink
fix: typo (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky authored Jul 25, 2024
1 parent e870606 commit 4ccf020
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions internal/middleware/rbac/access_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"github.com/gin-gonic/gin"
)

// RABC 获取用户角色,存入上下文,进行权限控制,allowRoles 为允许的角色,为空则不限制
func RABC(allowRoles ...string) gin.HandlerFunc {
// RBAC 获取用户角色,存入上下文,进行权限控制,allowRoles 为允许的角色,为空则不限制
func RBAC(allowRoles ...string) gin.HandlerFunc {
return func(c *gin.Context) {
userID, _ := resp.GetUserIDFromGinContext(c)

// 从 Redis 获取用户角色
roles, err := cache_logic.GetUserRolesByID(userID)
if err != nil {
// 处理 Redis 查询错误
log.Logger.Error("RABC GetUserRolesByID Error: " + err.Error())
log.Logger.Error("RBAC GetUserRolesByID Error: " + err.Error())
resp.AbortWithMsg(c, code.UnknownError, err.Error())
return
}
Expand All @@ -36,7 +36,7 @@ func RABC(allowRoles ...string) gin.HandlerFunc {
// 用户没有合适的角色,拦截请求
if !hasAllowedRole {
resp.AbortWithMsg(c, code.AuthErrorNoPermission, "Role has no permission")
log.Logger.Errorf("RABC Role has no permission, userID: %d, roles: %v", userID, roles)
log.Logger.Errorf("RBAC Role has no permission, userID: %d, roles: %v", userID, roles)
return
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/router/api/v1/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package v1
8 changes: 4 additions & 4 deletions internal/router/api/v1/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ func TorrentRouterGroup(api *gin.RouterGroup) {
// 种子上传
torrent.POST("upload",
jwt.RequireAuth(false),
rbac.RABC(role.ADMIN, role.UPLOADER, role.ADVANCED_USER),
rbac.RBAC(role.ADMIN, role.UPLOADER, role.ADVANCED_USER),
torrent_service.Upload)
// 种子编辑
torrent.POST("edit",
jwt.RequireAuth(false),
rbac.RABC(),
rbac.RBAC(),
torrent_service.Edit)
// 种子删除
torrent.POST("delete",
jwt.RequireAuth(false),
rbac.RABC(role.ADMIN),
rbac.RBAC(role.ADMIN),
torrent_service.Delete)
// 种子审核
torrent.POST("review",
jwt.RequireAuth(false),
rbac.RABC(role.REVIEWER),
rbac.RBAC(role.REVIEWER),
torrent_service.Review)
// 种子首页官种
torrent.GET("official",
Expand Down
2 changes: 1 addition & 1 deletion internal/router/api/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func UserRouterGroup(api *gin.RouterGroup) {
// 用户邀请码生成
user.POST("invitation/gen",
jwt.RequireAuth(false),
rbac.RABC(role.ADVANCED_USER, role.VIP), // 高级用户权限
rbac.RBAC(role.ADVANCED_USER, role.VIP), // 高级用户权限
user_service.InvitationGen)
// 用户邀请码列表
user.GET("invitation/me",
Expand Down
1 change: 1 addition & 0 deletions internal/service/admin/edit_role.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package admin

0 comments on commit 4ccf020

Please sign in to comment.