Skip to content

Commit f8c2266

Browse files
committed
fix
Signed-off-by: Min Min <[email protected]>
1 parent 2cb6c22 commit f8c2266

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkg/microservice/user/core/service/permission/internal.go

+23
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ package permission
1818

1919
import (
2020
"fmt"
21+
"time"
2122

23+
"github.com/koderover/zadig/v2/pkg/config"
24+
"github.com/koderover/zadig/v2/pkg/tool/cache"
2225
"github.com/koderover/zadig/v2/pkg/types"
2326
"go.uber.org/zap"
2427

@@ -117,7 +120,27 @@ func InitializeProjectAuthorization(namespace string, isPublic bool, admins []st
117120
return fmt.Errorf("failed to bind project-admin role to given user list, error: %s", err)
118121
}
119122

123+
roleCache := cache.NewRedisCache(config.RedisCommonCacheTokenDB())
124+
// flush cache for every identity that is affected
125+
for _, uid := range admins {
126+
uidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, uid)
127+
err = roleCache.Delete(uidRoleKey)
128+
if err != nil {
129+
log.Warnf("failed to flush user-role cache for key: %s, error: %s", uidRoleKey, err)
130+
}
131+
}
132+
120133
tx.Commit()
134+
135+
go func(uids []string, redisCache *cache.RedisCache) {
136+
time.Sleep(2 * time.Second)
137+
138+
for _, uid := range uids {
139+
uidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, uid)
140+
err = roleCache.Delete(uidRoleKey)
141+
}
142+
}(admins, roleCache)
143+
121144
return nil
122145
}
123146

pkg/microservice/user/core/service/permission/role_binding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func CreateRoleBindings(role, ns string, identityList []*types.Identity, log *za
243243
}
244244

245245
for _, gid := range groupIDList {
246-
gidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, gid)
246+
gidRoleKey := fmt.Sprintf(GIDRoleKeyFormat, gid)
247247
err = roleCache.Delete(gidRoleKey)
248248
if err != nil {
249249
log.Warnf("failed to flush user-role cache for key: %s, error: %s", gidRoleKey, err)
@@ -259,7 +259,7 @@ func CreateRoleBindings(role, ns string, identityList []*types.Identity, log *za
259259
}
260260

261261
for _, gid := range gids {
262-
gidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, gid)
262+
gidRoleKey := fmt.Sprintf(GIDRoleKeyFormat, gid)
263263
err = roleCache.Delete(gidRoleKey)
264264
}
265265
}(userIDList, groupIDList, roleCache)

0 commit comments

Comments
 (0)