Skip to content

Commit

Permalink
[fix]bug
Browse files Browse the repository at this point in the history
  • Loading branch information
piupuer committed Oct 15, 2024
1 parent c9c7989 commit e67ec01
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions internal/biz/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type ActionRepo interface {
Update(ctx context.Context, item *UpdateAction) error
Delete(ctx context.Context, ids ...uint64) error
CodeExists(ctx context.Context, code string) error
Permission(ctx context.Context, code string, req CheckPermission) bool
MatchResource(ctx context.Context, resource string, req CheckPermission) bool
Permission(ctx context.Context, code string, req *CheckPermission) bool
MatchResource(ctx context.Context, resource string, req *CheckPermission) bool
}

type ActionUseCase struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/biz/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CheckPermission struct {
}

type PermissionRepo interface {
Check(ctx context.Context, item CheckPermission) bool
Check(ctx context.Context, item *CheckPermission) bool
GetByUserCode(ctx context.Context, code string) *Permission
}

Expand All @@ -36,7 +36,7 @@ func NewPermissionUseCase(c *conf.Bootstrap, repo PermissionRepo) *PermissionUse
}
}

func (uc *PermissionUseCase) Check(ctx context.Context, item CheckPermission) (rp bool) {
func (uc *PermissionUseCase) Check(ctx context.Context, item *CheckPermission) (rp bool) {
rp = uc.repo.Check(ctx, item)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/biz/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type UserRepo interface {
Update(ctx context.Context, item *UpdateUser) error
Delete(ctx context.Context, ids ...uint64) error
LastLogin(ctx context.Context, username string) error
WrongPwd(ctx context.Context, req LoginTime) error
WrongPwd(ctx context.Context, req *LoginTime) error
UpdatePassword(ctx context.Context, item *User) error
IdExists(ctx context.Context, id uint64) error
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func (uc *UserUseCase) LastLogin(ctx context.Context, username string) error {
})
}

func (uc *UserUseCase) WrongPwd(ctx context.Context, req LoginTime) error {
func (uc *UserUseCase) WrongPwd(ctx context.Context, req *LoginTime) error {
return uc.tx.Tx(ctx, func(ctx context.Context) (err error) {
err = uc.repo.WrongPwd(ctx, req)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions internal/biz/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
const (
WhitelistPermissionCategory uint32 = iota
WhitelistJwtCategory
WhitelistIdempotentCategory
)

type Whitelist struct {
Expand All @@ -28,8 +27,8 @@ type FindWhitelist struct {
}

type HasWhitelist struct {
Category uint32 `json:"category"`
Permission CheckPermission `json:"permission"`
Category uint32 `json:"category"`
Permission *CheckPermission `json:"permission"`
}

type FindWhitelistCache struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/data/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (ro actionRepo) WordExists(ctx context.Context, word string) (ok bool) {
return
}

func (ro actionRepo) Permission(ctx context.Context, code string, req biz.CheckPermission) (pass bool) {
func (ro actionRepo) Permission(ctx context.Context, code string, req *biz.CheckPermission) (pass bool) {
arr := strings.Split(code, ",")
for _, item := range arr {
pass = ro.permission(ctx, item, req)
Expand All @@ -195,15 +195,15 @@ func (ro actionRepo) Permission(ctx context.Context, code string, req biz.CheckP
return
}

func (ro actionRepo) permission(ctx context.Context, code string, req biz.CheckPermission) (pass bool) {
func (ro actionRepo) permission(ctx context.Context, code string, req *biz.CheckPermission) (pass bool) {
if code == "" {
return
}
action := ro.hotspot.GetActionByCode(ctx, code)
return ro.MatchResource(ctx, action.Resource, req)
}

func (actionRepo) MatchResource(_ context.Context, resource string, req biz.CheckPermission) (pass bool) {
func (actionRepo) MatchResource(_ context.Context, resource string, req *biz.CheckPermission) (pass bool) {
if resource == "" {
// empty resource no need match
return
Expand Down
2 changes: 1 addition & 1 deletion internal/data/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewPermissionRepo(data *Data, action biz.ActionRepo, hotspot biz.HotspotRep
}
}

func (ro permissionRepo) Check(ctx context.Context, item biz.CheckPermission) (pass bool) {
func (ro permissionRepo) Check(ctx context.Context, item *biz.CheckPermission) (pass bool) {
user := ro.hotspot.GetUserByCode(ctx, item.UserCode)
// 1. check default permission
defaultAction := ro.hotspot.GetActionByWord(ctx, "default")
Expand Down
2 changes: 1 addition & 1 deletion internal/data/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (ro userRepo) LastLogin(ctx context.Context, username string) (err error) {
return
}

func (ro userRepo) WrongPwd(ctx context.Context, req biz.LoginTime) (err error) {
func (ro userRepo) WrongPwd(ctx context.Context, req *biz.LoginTime) (err error) {
oldItem, err := ro.GetByUsername(ctx, req.Username)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func process(t task) (err error) {
case t.c.Task.Group.LoginFailed:
var req biz.LoginTime
utils.Json2Struct(&req, t.payload.Payload)
err = t.user.WrongPwd(ctx, req)
err = t.user.WrongPwd(ctx, &req)
case t.c.Task.Group.LoginLast:
var req biz.LoginTime
utils.Json2Struct(&req, t.payload.Payload)
Expand Down
6 changes: 3 additions & 3 deletions internal/server/middleware/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
pubURIPrefix = "/pub/"
jwtTokenCachePrefix = "jwt.token."
jwtTokenCachePrefix = "jwt.token"
jwtTokenCacheExpire = 10 * time.Minute
permissionHeaderMethod = "x-original-method"
permissionHeaderURI = "x-permission-uri"
Expand Down Expand Up @@ -96,7 +96,7 @@ func permissionWhitelist(ctx context.Context, whitelist *biz.WhitelistUseCase, r
// check if it is on the whitelist
ok = whitelist.Has(ctx, &biz.HasWhitelist{
Category: biz.WhitelistPermissionCategory,
Permission: r,
Permission: &r,
})
// override params
v, ok2 := req.(*auth.PermissionRequest)
Expand All @@ -113,7 +113,7 @@ func jwtWhitelist(ctx context.Context, whitelist *biz.WhitelistUseCase) bool {
tr, _ := transport.FromServerContext(ctx)
return whitelist.Has(ctx, &biz.HasWhitelist{
Category: biz.WhitelistJwtCategory,
Permission: biz.CheckPermission{
Permission: &biz.CheckPermission{
Resource: tr.Operation(),
},
})
Expand Down
2 changes: 1 addition & 1 deletion internal/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (s *AuthService) Permission(ctx context.Context, req *auth.PermissionReques
defer span.End()
rp = &emptypb.Empty{}
user := jwt.FromServerContext(ctx)
r := biz.CheckPermission{
r := &biz.CheckPermission{
UserCode: user.Attrs["code"],
}
if req.Resource != nil {
Expand Down

0 comments on commit e67ec01

Please sign in to comment.