Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:users): extend clearWhitelistCaches to support clearing all entries, and call it after user creation to prevent stale user cache

johaven92d78c987e70
diff --git a/backend/src/applications/users/services/admin-users-manager.service.spec.ts b/backend/src/applications/users/services/admin-users-manager.service.spec.ts
index bf24d464..5cdc1e8b 100644
--- a/backend/src/applications/users/services/admin-users-manager.service.spec.ts
+++ b/backend/src/applications/users/services/admin-users-manager.service.spec.ts
@@ -58,6 +58,7 @@ describe(AdminUsersManager.name, () => {
checkGroupNameExists: jest.Mock
checkUserExists: jest.Mock
searchUsersOrGroups: jest.Mock
+ clearWhiteListCaches: jest.Mock
}
updateUserGroups: jest.Mock
updateGuestManagers: jest.Mock
@@ -100,7 +101,8 @@ describe(AdminUsersManager.name, () => {
compareUserPassword: jest.fn(),
checkGroupNameExists: jest.fn(),
checkUserExists: jest.fn(),
- searchUsersOrGroups: jest.fn()
+ searchUsersOrGroups: jest.fn(),
+ clearWhiteListCaches: jest.fn()
},
updateUserGroups: jest.fn(),
updateGuestManagers: jest.fn(),
diff --git a/backend/src/applications/users/services/admin-users-manager.service.ts b/backend/src/applications/users/services/admin-users-manager.service.ts
index 27a5dcec..364f00d0 100644
--- a/backend/src/applications/users/services/admin-users-manager.service.ts
+++ b/backend/src/applications/users/services/admin-users-manager.service.ts
@@ -67,6 +67,7 @@ export class AdminUsersManager {
this.logger.log(
`${this.createUserOrGuest.name} - ${USER_ROLE[userRole]} (${userId}) was created : ${JSON.stringify(anonymizePassword(createUserDto))}`
)
+ this.adminQueries.usersQueries.clearWhiteListCaches('*')
await user.makePaths()
if (userRole <= USER_ROLE.USER) {
return asAdmin ? this.getUser(user.id) : user
diff --git a/backend/src/applications/users/services/users-manager.service.spec.ts b/backend/src/applications/users/services/users-manager.service.spec.ts
index 856f114f..b8232a6e 100755
--- a/backend/src/applications/users/services/users-manager.service.spec.ts
+++ b/backend/src/applications/users/services/users-manager.service.spec.ts
@@ -143,6 +143,7 @@ describe(UsersManager.name, () => {
usersQueriesService.checkUserExists = jest.fn().mockReturnValue(undefined)
usersQueriesService.createUserOrGuest = jest.fn().mockReturnValue(888)
+ usersQueriesService.clearWhiteListCaches = jest.fn()
const created = await adminUsersManager.createUserOrGuest(userTest satisfies CreateUserDto, USER_ROLE.USER)
expect(created).toBeInstanceOf(UserModel)
expect(await isPathExists(created.filesPath)).toBe(true)
diff --git a/backend/src/applications/users/services/users-queries.service.ts b/backend/src/applications/users/services/users-queries.service.ts
index be8e9053..9abb7c41 100644
--- a/backend/src/applications/users/services/users-queries.service.ts
+++ b/backend/src/applications/users/services/users-queries.service.ts
@@ -544,13 +544,30 @@ export class UsersQueries {
return JSON.parse(r[0].ids) || []
}
- clearWhiteListCaches(userIds: number[]) {
- this.cache
- .mdel([
- ...userIds.map((id) => this.cache.genSlugKey(this.constructor.name, this.usersWhitelist.name, id)),
- ...userIds.map((id) => this.cache.genSlugKey(this.constructor.name, this.groupsWhitelist.name, id))
- ])
- .catch((e: Error) => this.logger.error(`${this.clearWhiteListCaches.name} - ${e}`))
+ clearWhiteListCaches(userIds: number[] | '*') {
+ if (userIds === '*') {
+ // means all entries
+ for (const pattern of [
+ this.cache.genSlugKey(this.constructor.name, this.usersWhitelist.name, userIds),
+ this.cache.genSlugKey(this.constructor.name, this.groupsWhitelist.name, userIds)
+ ]) {
+ this.cache
+ .keys(pattern)
+ .then((keys: string[]) => {
+ if (!keys.length) return
+ this.logger.verbose(`${this.clearWhiteListCaches.name} - ${JSON.stringify(keys)}`)
+ this.cache.mdel(keys).catch((e: Error) => this.logger.error(`${this.clearWhiteListCaches.name} - ${e}`))
+ })
+ .catch((e: Error) => this.logger.error(`${this.clearWhiteListCaches.name} - ${e}`))
+ }
+ } else {
+ this.cache
+ .mdel([
+ ...userIds.map((id: number) => this.cache.genSlugKey(this.constructor.name, this.usersWhitelist.name, id)),
+ ...userIds.map((id: number) => this.cache.genSlugKey(this.constructor.name, this.groupsWhitelist.name, id))
+ ])
+ .catch((e: Error) => this.logger.error(`${this.clearWhiteListCaches.name} - ${e}`))
+ }
}
async allUserIdsFromGroupsAndSubGroups(groupIds: number[]): Promise<number[]> {
diff --git a/frontend/src/app/applications/users/components/user-account.component.html b/frontend/src/app/applications/users/components/user-account.component.html
index aa2b0996..f5f68964 100755
--- a/frontend/src/app/applications/users/components/user-account.component.html
+++ b/frontend/src/app/applications/users/components/user-account.component.html
@@ -68,7 +68,7 @@
</li>
}
<li class="list-group-item d-flex justify-content-between align-items-center">
- <span class="me-auto pe-4" l10nTranslate>WebDAV</span>
+ <span class="me-auto pe-4">WebDAV</span>
<span (click)="clipBoardLink()" class="text-primary text-end cursor-pointer">
<fa-icon [icon]="icons.faCopy"></fa-icon>
{{ webdavUrl }}