Closed aiwilliams closed 3 years ago
@aiwilliams
Took a look at the code and to me it looks like the issue is how users are being added. The users are fetched using workspaces. Looking at this code to me looks like if a user belongs to multiple workspace, they would get added twice with the key of user.uuid
. I'm just wondering how this hasn't caused an issue before.
src/steps/users.ts
:
await jobState.iterateEntities(
{
_type: BITBUCKET_WORKSPACE_ENTITY_TYPE,
},
async (workspaceEntity) => {
if (workspaceEntity.slug) {
const slug: string = <string>workspaceEntity.slug;
await apiClient.iterateUsers(slug, async (user) => {
const convertedUser = createUserEntity(user);
const userEntity = (await jobState.addEntity(
createIntegrationEntity({
entityData: {
source: user,
assign: convertedUser,
},
}),
)) as BitbucketUserEntity;
const workspace: BitbucketWorkspaceEntity = <
BitbucketWorkspaceEntity
>workspaceEntity;
await jobState.addRelationship(
createWorkspaceHasUserRelationship(workspace, userEntity),
);
userByIdMap[user.uuid] = userEntity;
userIds.push(userEntity._key);
});
}
},
);
I think this could be solved like this:
await jobState.iterateEntities(
{
_type: BITBUCKET_WORKSPACE_ENTITY_TYPE,
},
async (workspaceEntity) => {
if (workspaceEntity.slug) {
const slug: string = <string>workspaceEntity.slug;
await apiClient.iterateUsers(slug, async (user) => {
const convertedUser = createUserEntity(user);
// CHECK IF USER WAS IN ANOTHER WORKSPACE
const userEntity = (await jobState.findEntity(
convertedUser._key
)) as BitbucketUserEntity;
if( !userEntity ) {
// Make sure this user doesn't already exist
const userEntity = (await jobState.addEntity(
createIntegrationEntity({
entityData: {
source: user,
assign: convertedUser,
},
}),
)) as BitbucketUserEntity;
userByIdMap[user.uuid] = userEntity;
userIds.push(userEntity._key);
}
// END
const workspace: BitbucketWorkspaceEntity = <
BitbucketWorkspaceEntity
>workspaceEntity;
await jobState.addRelationship(
createWorkspaceHasUserRelationship(workspace, userEntity),
);
});
}
},
);
Looking at /src/steps/groups.ts
, I'm wondering what the point of this check is?:
for (const user of group.members) {
if (user.uuid) {
if (userByIdMap[user.uuid]) {
await jobState.addRelationship(
createGroupHasUserRelationship(
groupEntity,
userByIdMap[user.uuid],
),
);
}
}
}
It seems like to me its looking to make sure that a user belongs to both the workspace and the group? Is it possible to have a user that is part of a group but not part of the workspace that a group belongs to? I ask because the potential fix above may effect this.
Confirmed the issue was that some users are in multiple workspace. The job now runs and I can see the log msg we added
That leads to the
fetch-groups
step failing with: