fix some issues

This commit is contained in:
Hugo Renard 2022-02-23 18:15:36 +01:00
parent 3470a4ce60
commit 2ea4cd21a0
Signed by: hougo
GPG key ID: 3A285FD470209C59
6 changed files with 12 additions and 11 deletions

View file

@ -35,6 +35,7 @@ export class GroupEndpoint extends ScimEndpoint implements IScimEndpoint {
const targetIds = new Set<string>( const targetIds = new Set<string>(
SCIMGroup.fromPlain(ctx.content()).members.map((x) => x.value), SCIMGroup.fromPlain(ctx.content()).members.map((x) => x.value),
); );
targetIds.add(await ctx.rc.getUserId());
const currentIds = new Set<string>( const currentIds = new Set<string>(
membersRaw.members.map((x) => x.user._id), membersRaw.members.map((x) => x.user._id),
); );

View file

@ -24,7 +24,7 @@ export class UserEndpoint extends ScimEndpoint implements IScimEndpoint {
userId: ctx.id(), userId: ctx.id(),
data: { data: {
email: u.getEmail(), email: u.getEmail(),
name: u.displayName, name: u.displayName || undefined,
username: u.userName, username: u.userName,
active: u.active, active: u.active,
verified: true, verified: true,

View file

@ -30,10 +30,7 @@ export class UsersEndpoint extends ScimEndpoint implements IScimEndpoint {
const u = SCIMUser.fromPlain(ctx.content()); const u = SCIMUser.fromPlain(ctx.content());
const o = await ctx.rc.user.create({ const o = await ctx.rc.user.create({
email: u.getEmail(), email: u.getEmail(),
name: name: u.displayName || u.userName,
u.displayName ||
`${u.name.givenName} ${u.name.familyName}` ||
u.userName,
username: u.userName, username: u.userName,
password: crypto.randomBytes(64).toString("base64").slice(0, 64), password: crypto.randomBytes(64).toString("base64").slice(0, 64),
verified: true, verified: true,

View file

@ -70,6 +70,14 @@ export class RcSdk {
} }
return content; return content;
} }
public async getUserId(): Promise<string> {
return await this.read
.getEnvironmentReader()
.getSettings()
.getValueById("rc-user-id");
}
private buildUrl(url: string): string { private buildUrl(url: string): string {
return `${this.baseUrl}/${url}`; return `${this.baseUrl}/${url}`;
} }
@ -77,10 +85,7 @@ export class RcSdk {
private async buildOptions(content?: any): Promise<IHttpRequest> { private async buildOptions(content?: any): Promise<IHttpRequest> {
const options: IHttpRequest = { const options: IHttpRequest = {
headers: { headers: {
"X-User-Id": await this.read "X-User-Id": await this.getUserId(),
.getEnvironmentReader()
.getSettings()
.getValueById("rc-user-id"),
"X-Auth-Token": await this.read "X-Auth-Token": await this.read
.getEnvironmentReader() .getEnvironmentReader()
.getSettings() .getSettings()

View file

@ -23,7 +23,6 @@ export class SCIMGroup implements ISCIMResource {
value: member.user._id, value: member.user._id,
$ref: `/Users/${member.user._id}`, $ref: `/Users/${member.user._id}`,
display: member.user.name, display: member.user.name,
type: "User",
})); }));
return group; return group;
} }

View file

@ -18,7 +18,6 @@ export class SCIMUser implements ISCIMResource {
public static fromRC(rc: IUser): SCIMUser { public static fromRC(rc: IUser): SCIMUser {
const user = new SCIMUser(); const user = new SCIMUser();
user.id = rc._id; user.id = rc._id;
user.externalId = rc._id;
user.setEmail(rc.emails[0].address); user.setEmail(rc.emails[0].address);
user.displayName = rc.name; user.displayName = rc.name;
user.userName = rc.username; user.userName = rc.username;