sync: 对齐小程序 v1.0.2 生产代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 15:15:12 +08:00
parent a7abd476f0
commit 5fcf74deb0
423 changed files with 15001 additions and 6382 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
// Package mcache
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
// 内存缓存管理
package mcache
@@ -1,17 +1,17 @@
// Package mcache
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package mcache
import (
"context"
"fmt"
"time"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/event"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"time"
"github.com/gogf/gf/v2/frame/g"
)
@@ -28,7 +28,29 @@ func init() {
}
type requestAccessKey struct{}
type requestAccessSnapshot struct {
userId int64
codes []string
scopes []string
}
// WithFreshUserAccess 为小程序请求读取当前权限并保留请求内快照。
// 控制台清理本地缓存不会清理小程序进程内的权限缓存。
func WithFreshUserAccess(ctx context.Context, userId int64) (context.Context, error) {
codes, scopes, err := service.SysAuth().GetUserAccessCodeList(ctx, userId)
if err != nil {
return ctx, err
}
snapshot := requestAccessSnapshot{userId: userId, codes: ensureCurrentUserAccessCode(codes), scopes: scopes}
return context.WithValue(ctx, requestAccessKey{}, snapshot), nil
}
func GetUserAccessCodeList(ctx context.Context, userId int64) ([]string, []string, error) {
if snapshot, ok := ctx.Value(requestAccessKey{}).(requestAccessSnapshot); ok && snapshot.userId == userId {
return snapshot.codes, snapshot.scopes, nil
}
accessCodeList, err := Instance().Get(ctx, fmt.Sprintf(consts.MemCacheUserAccessCodeList, userId))
menuRoleDataAccessCodeList, err := Instance().Get(ctx, fmt.Sprintf(consts.MemCacheUserRoleDataAccessCodeList, userId))
if err != nil || accessCodeList == nil {
@@ -0,0 +1,19 @@
package mcache
import (
"context"
"reflect"
"testing"
)
func TestRequestAccessSnapshotOverridesProcessCache(t *testing.T) {
for _, codes := range [][]string{{"cpm:iot:tSimCardAllocate:batch:submit"}, {}} {
ctx := context.WithValue(context.Background(), requestAccessKey{}, requestAccessSnapshot{
userId: 123, codes: ensureCurrentUserAccessCode(codes), scopes: []string{"scope-current"},
})
got, scopes, err := GetUserAccessCodeList(ctx, 123)
if err != nil || !reflect.DeepEqual(got, ensureCurrentUserAccessCode(codes)) || !reflect.DeepEqual(scopes, []string{"scope-current"}) {
t.Fatalf("request snapshot was not respected: codes=%v scopes=%v err=%v", got, scopes, err)
}
}
}
@@ -1,20 +1,20 @@
// Package mcache
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package mcache
import (
"context"
"fmt"
"time"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/contexts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/event"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model/request"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"time"
)
func init() {
@@ -1,17 +1,17 @@
// Package mcache
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package mcache
import (
"context"
"fmt"
"time"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/event"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"time"
)
func init() {
@@ -1,18 +1,18 @@
// Package mcache
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package mcache
import (
"context"
"fmt"
"time"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/event"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"time"
"github.com/gogf/gf/v2/util/gconv"
)