From 2ea4cd21a01e515059d5224d8568a5b600358442 Mon Sep 17 00:00:00 2001 From: Hugo Renard Date: Wed, 23 Feb 2022 18:15:36 +0100 Subject: [PATCH] fix some issues --- src/endpoints/GroupEndpoint.ts | 1 + src/endpoints/UserEndpoint.ts | 2 +- src/endpoints/UsersEndpoint.ts | 5 +---- src/rc-sdk/RcSdk.ts | 13 +++++++++---- src/scim/Group.ts | 1 - src/scim/User.ts | 1 - 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/endpoints/GroupEndpoint.ts b/src/endpoints/GroupEndpoint.ts index 931f6ec..014a7fc 100644 --- a/src/endpoints/GroupEndpoint.ts +++ b/src/endpoints/GroupEndpoint.ts @@ -35,6 +35,7 @@ export class GroupEndpoint extends ScimEndpoint implements IScimEndpoint { const targetIds = new Set( SCIMGroup.fromPlain(ctx.content()).members.map((x) => x.value), ); + targetIds.add(await ctx.rc.getUserId()); const currentIds = new Set( membersRaw.members.map((x) => x.user._id), ); diff --git a/src/endpoints/UserEndpoint.ts b/src/endpoints/UserEndpoint.ts index 6eaf6a9..2d8b2df 100644 --- a/src/endpoints/UserEndpoint.ts +++ b/src/endpoints/UserEndpoint.ts @@ -24,7 +24,7 @@ export class UserEndpoint extends ScimEndpoint implements IScimEndpoint { userId: ctx.id(), data: { email: u.getEmail(), - name: u.displayName, + name: u.displayName || undefined, username: u.userName, active: u.active, verified: true, diff --git a/src/endpoints/UsersEndpoint.ts b/src/endpoints/UsersEndpoint.ts index e52cfd8..0f51658 100644 --- a/src/endpoints/UsersEndpoint.ts +++ b/src/endpoints/UsersEndpoint.ts @@ -30,10 +30,7 @@ export class UsersEndpoint extends ScimEndpoint implements IScimEndpoint { const u = SCIMUser.fromPlain(ctx.content()); const o = await ctx.rc.user.create({ email: u.getEmail(), - name: - u.displayName || - `${u.name.givenName} ${u.name.familyName}` || - u.userName, + name: u.displayName || u.userName, username: u.userName, password: crypto.randomBytes(64).toString("base64").slice(0, 64), verified: true, diff --git a/src/rc-sdk/RcSdk.ts b/src/rc-sdk/RcSdk.ts index 96438d1..07b24a3 100644 --- a/src/rc-sdk/RcSdk.ts +++ b/src/rc-sdk/RcSdk.ts @@ -70,6 +70,14 @@ export class RcSdk { } return content; } + + public async getUserId(): Promise { + return await this.read + .getEnvironmentReader() + .getSettings() + .getValueById("rc-user-id"); + } + private buildUrl(url: string): string { return `${this.baseUrl}/${url}`; } @@ -77,10 +85,7 @@ export class RcSdk { private async buildOptions(content?: any): Promise { const options: IHttpRequest = { headers: { - "X-User-Id": await this.read - .getEnvironmentReader() - .getSettings() - .getValueById("rc-user-id"), + "X-User-Id": await this.getUserId(), "X-Auth-Token": await this.read .getEnvironmentReader() .getSettings() diff --git a/src/scim/Group.ts b/src/scim/Group.ts index e4dd2db..c563626 100644 --- a/src/scim/Group.ts +++ b/src/scim/Group.ts @@ -23,7 +23,6 @@ export class SCIMGroup implements ISCIMResource { value: member.user._id, $ref: `/Users/${member.user._id}`, display: member.user.name, - type: "User", })); return group; } diff --git a/src/scim/User.ts b/src/scim/User.ts index 0f2e5e8..5d903a2 100644 --- a/src/scim/User.ts +++ b/src/scim/User.ts @@ -18,7 +18,6 @@ export class SCIMUser implements ISCIMResource { public static fromRC(rc: IUser): SCIMUser { const user = new SCIMUser(); user.id = rc._id; - user.externalId = rc._id; user.setEmail(rc.emails[0].address); user.displayName = rc.name; user.userName = rc.username;