Fix accountId and role not being set correctly when adding org members

This commit is contained in:
Martin Kleinschrodt 2022-06-20 08:09:38 +02:00
parent b3661e47de
commit 16f4a76cb2
2 changed files with 9 additions and 16 deletions

View File

@ -46,7 +46,7 @@ class OrgInfo extends Serializable {
}
class InviteeInfo extends Serializable {
id: AccountID = "";
accountId: AccountID = "";
name: string = "";
email: string = "";
@ -151,7 +151,7 @@ export class Invite extends SimpleContainer {
/** Info about who created the invite. */
invitedBy?: {
id: AccountID;
accountId: AccountID;
name: string;
email: string;
} = undefined;
@ -219,7 +219,7 @@ export class Invite extends SimpleContainer {
*/
async initialize(org: Org, invitor: Account, duration = 12) {
this.id = await uuid();
this.invitedBy = { id: invitor.id, email: invitor.email, name: invitor.name };
this.invitedBy = { accountId: invitor.id, email: invitor.email, name: invitor.name };
// Generate secret
this.secret = bytesToHex(await getProvider().randomBytes(4));
@ -280,7 +280,7 @@ export class Invite extends SimpleContainer {
}
this.invitee = new InviteeInfo({
id: account.id,
accountId: account.id,
name: account.name,
email: account.email,
publicKey: account.publicKey,
@ -318,7 +318,7 @@ export class Invite extends SimpleContainer {
this._verify(
this.invitee.signature,
concatBytes(
[stringToBytes(this.invitee.id), stringToBytes(this.invitee.email), this.invitee.publicKey],
[stringToBytes(this.invitee.accountId), stringToBytes(this.invitee.email), this.invitee.publicKey],
0x00
)
)

View File

@ -340,13 +340,8 @@ export class Org extends SharedContainer implements Storable {
}
/** Get the [[OrgMember]] object for this [[Account]] */
getMember({
email,
accountId,
}: { email: string; accountId?: AccountID } | { accountId: AccountID; email?: string }) {
return accountId
? this.members.find((m) => m.accountId === accountId)
: this.members.find((m) => m.email === email);
getMember({ email }: { email: string; accountId?: AccountID } | { accountId: AccountID; email?: string }) {
return this.members.find((m) => m.email === email);
}
/** Whether the given [[Account]] is an organization member */
@ -622,8 +617,8 @@ export class Org extends SharedContainer implements Storable {
email,
publicKey,
orgSignature,
role,
status,
role = OrgRole.Member,
status = OrgMemberStatus.Active,
}: {
accountId?: string;
name: string;
@ -637,8 +632,6 @@ export class Org extends SharedContainer implements Storable {
throw "Organisation needs to be unlocked first.";
}
role = typeof role !== "undefined" ? role : OrgRole.Member;
const existing = this.getMember({ email, accountId });
const updated = new Date();