Skip to content

Commit

Permalink
CB-5384 feat: Resolves users collision in UsersResource
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Aug 13, 2024
1 parent 9992e14 commit dc86a59
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions webapp/packages/core-authentication/src/UsersResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@cloudbeaver/core-resource';
import { EAdminPermission, ServerConfigResource, SessionPermissionsResource } from '@cloudbeaver/core-root';
import { AdminConnectionGrantInfo, AdminUserInfo, AdminUserInfoFragment, GetUsersListQueryVariables, GraphQLService } from '@cloudbeaver/core-sdk';
import { isDefined } from '@cloudbeaver/core-utils';

import { AUTH_PROVIDER_LOCAL_ID } from './AUTH_PROVIDER_LOCAL_ID';
import { AuthInfoService } from './AuthInfoService';
Expand Down Expand Up @@ -292,14 +293,38 @@ export class UsersResource extends CachedMapResource<string, AdminUser, UserReso

this.offsetPagination.setPageEnd(CachedResourceOffsetPageListKey(offset, users.length).setTarget(filterKey), users.length === limit);
}

this.resolveUsersCollision(key, usersList);
});

const key = resourceKeyList(usersList.map(user => user.userId));

this.set(key, usersList);

return this.data;
}

private resolveUsersCollision(key: ResourceKey<string>, newUsers: AdminUserInfoFragment[]): void {
const userListIds = new Set(newUsers.map(user => user.userId));
const currentUsers = this.get(key);

if (!isDefined(currentUsers) || !this.isOutdated(key)) {
return;
}

if (currentUsers instanceof Array) {
currentUsers
.filter(user => !user?.userId || !userListIds.has(user.userId))
.filter(isDefined)
.forEach(user => this.data.delete(user.userId));
return;
}

if (currentUsers?.userId) {
this.data.delete(currentUsers.userId);
}
}

private getDefaultIncludes(): UserResourceIncludes {
return {
customIncludeOriginDetails: false,
Expand Down

0 comments on commit dc86a59

Please sign in to comment.