Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-13755] Decouple Invite and Edit User Flows #12277

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<bit-dialog [disablePadding]="!loading" dialogSize="large">
<span bitDialogTitle>
{{ title }}
<span class="tw-text-sm tw-normal-case tw-text-muted" *ngIf="!loading && params.name">{{
params.name
}}</span>
<span
class="tw-text-sm tw-normal-case tw-text-muted"
*ngIf="!loading && this.isEditDialogParams(this.params) && params.name"
>{{ params.name }}</span
>
<span bitBadge variant="secondary" *ngIf="isRevoked">{{ "revoked" | i18n }}</span>
</span>
<div bitDialogContent>
Expand Down Expand Up @@ -263,7 +265,8 @@ <h3 class="tw-mt-4">
</button>
<button
*ngIf="
editMode && (!(accountDeprovisioningEnabled$ | async) || !params.managedByOrganization)
this.isEditDialogParams(this.params) &&
(!(accountDeprovisioningEnabled$ | async) || !params.managedByOrganization)
"
type="button"
bitIconButton="bwi-close"
Expand All @@ -275,7 +278,9 @@ <h3 class="tw-mt-4">
></button>
<button
*ngIf="
editMode && (accountDeprovisioningEnabled$ | async) && params.managedByOrganization
this.isEditDialogParams(this.params) &&
(accountDeprovisioningEnabled$ | async) &&
params.managedByOrganization
"
type="button"
bitIconButton="bwi-trash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
} from "../../../shared/components/access-selector";

import { commaSeparatedEmails } from "./validators/comma-separated-emails.validator";
import { inputEmailLimitValidator } from "./validators/input-email-limit.validator";

Check warning on line 55 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L55

Added line #L55 was not covered by tests
import { orgSeatLimitReachedValidator } from "./validators/org-seat-limit-reached.validator";

export enum MemberDialogTab {
Expand All @@ -60,18 +61,28 @@
Collections = 2,
}

export interface MemberDialogParams {
name: string;
interface CommonMemberDialogParams {
isOnSecretsManagerStandalone: boolean;
organizationId: string;
organizationUserId: string;
}

export interface AddMemberDialogParams extends CommonMemberDialogParams {
kind: "Add";
occupiedSeatCount: number;
allOrganizationUserEmails: string[];
}

export interface EditMemberDialogParams extends CommonMemberDialogParams {
kind: "Edit";
name: string;
organizationUserId: string;
usesKeyConnector: boolean;
isOnSecretsManagerStandalone: boolean;
initialTab?: MemberDialogTab;
numConfirmedMembers: number;
managedByOrganization?: boolean;
initialTab: MemberDialogTab;
}

export type MemberDialogParams = EditMemberDialogParams | AddMemberDialogParams;

export enum MemberDialogResult {
Saved = "saved",
Canceled = "canceled",
Expand Down Expand Up @@ -139,6 +150,12 @@
return this.formGroup.value.type === OrganizationUserType.Custom;
}

isEditDialogParams(
params: EditMemberDialogParams | AddMemberDialogParams,
): params is EditMemberDialogParams {
return params.kind === "Edit";

Check warning on line 156 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L156

Added line #L156 was not covered by tests
}

constructor(
@Inject(DIALOG_DATA) protected params: MemberDialogParams,
private dialogRef: DialogRef<MemberDialogResult>,
Expand All @@ -159,9 +176,22 @@
.get$(this.params.organizationId)
.pipe(shareReplay({ refCount: true, bufferSize: 1 }));

this.editMode = this.params.organizationUserId != null;
this.tabIndex = this.params.initialTab ?? MemberDialogTab.Role;
this.title = this.i18nService.t(this.editMode ? "editMember" : "inviteMember");
let userDetails$;
if (this.isEditDialogParams(this.params)) {
this.editMode = true;
this.title = this.i18nService.t("editMember");
userDetails$ = this.userService.get(

Check warning on line 183 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L181-L183

Added lines #L181 - L183 were not covered by tests
this.params.organizationId,
this.params.organizationUserId,
);
this.tabIndex = this.params.initialTab;

Check warning on line 187 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L187

Added line #L187 was not covered by tests
} else {
this.editMode = false;
this.title = this.i18nService.t("inviteMember");
userDetails$ = of(null);
this.tabIndex = MemberDialogTab.Role;

Check warning on line 192 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L189-L192

Added lines #L189 - L192 were not covered by tests
}

this.isOnSecretsManagerStandalone = this.params.isOnSecretsManagerStandalone;

if (this.isOnSecretsManagerStandalone) {
Expand All @@ -178,10 +208,6 @@
),
);

const userDetails$ = this.params.organizationUserId
? this.userService.get(this.params.organizationId, this.params.organizationUserId)
: of(null);

this.allowAdminAccessToAllCollectionItems$ = this.organization$.pipe(
map((organization) => {
return organization.allowAdminAccessToAllCollectionItems;
Expand Down Expand Up @@ -263,13 +289,21 @@
}

private setFormValidators(organization: Organization) {
if (this.isEditDialogParams(this.params)) {
return;

Check warning on line 293 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L293

Added line #L293 was not covered by tests
}

const emailsControlValidators = [
Validators.required,
commaSeparatedEmails,
inputEmailLimitValidator(organization, (maxEmailsCount: number) =>
this.i18nService.t("tooManyEmails", maxEmailsCount),

Check warning on line 300 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L300

Added line #L300 was not covered by tests
),
orgSeatLimitReachedValidator(
organization,
this.params.allOrganizationUserEmails,
this.i18nService.t("subscriptionUpgrade", organization.seats),
this.params.occupiedSeatCount,
),
];

Expand Down Expand Up @@ -420,14 +454,25 @@
return;
}

const userView = await this.getUserView();

Check warning on line 457 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L457

Added line #L457 was not covered by tests

if (this.isEditDialogParams(this.params)) {
await this.handleEditUser(userView, this.params);

Check warning on line 460 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L460

Added line #L460 was not covered by tests
} else {
await this.handleInviteUsers(userView, organization);

Check warning on line 462 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L462

Added line #L462 was not covered by tests
}
};

private async getUserView(): Promise<OrganizationUserAdminView> {
const userView = new OrganizationUserAdminView();
userView.id = this.params.organizationUserId;
userView.organizationId = this.params.organizationId;
userView.type = this.formGroup.value.type;

userView.permissions = this.setRequestPermissions(
userView.permissions ?? new PermissionsApi(),
userView.type !== OrganizationUserType.Custom,
);

userView.collections = this.formGroup.value.access
.filter((v) => v.type === AccessItemType.Collection)
.map(convertToSelectionView);
Expand All @@ -438,44 +483,40 @@

userView.accessSecretsManager = this.formGroup.value.accessSecretsManager;

if (this.editMode) {
await this.userService.save(userView);
} else {
userView.id = this.params.organizationUserId;
const maxEmailsCount =
organization.productTierType === ProductTierType.TeamsStarter ? 10 : 20;
const emails = [...new Set(this.formGroup.value.emails.trim().split(/\s*,\s*/))];
if (emails.length > maxEmailsCount) {
this.formGroup.controls.emails.setErrors({
tooManyEmails: { message: this.i18nService.t("tooManyEmails", maxEmailsCount) },
});
return;
}
if (
organization.hasReseller &&
this.params.numConfirmedMembers + emails.length > organization.seats
) {
this.formGroup.controls.emails.setErrors({
tooManyEmails: { message: this.i18nService.t("seatLimitReachedContactYourProvider") },
});
return;
}
await this.userService.invite(emails, userView);
}
return userView;

Check warning on line 486 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L486

Added line #L486 was not covered by tests
}

private async handleEditUser(
userView: OrganizationUserAdminView,
params: EditMemberDialogParams,
) {
userView.id = params.organizationUserId;
await this.userService.save(userView);

Check warning on line 494 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L493-L494

Added lines #L493 - L494 were not covered by tests

this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t(
this.editMode ? "editedUserId" : "invitedUsers",
this.params.name,
),
message: this.i18nService.t("editedUserId", params.name),
});

this.close(MemberDialogResult.Saved);
};
}

private async handleInviteUsers(userView: OrganizationUserAdminView, organization: Organization) {
const emails = [...new Set(this.formGroup.value.emails.trim().split(/\s*,\s*/))];

Check warning on line 506 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L506

Added line #L506 was not covered by tests

await this.userService.invite(emails, userView);

Check warning on line 508 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L508

Added line #L508 was not covered by tests

this.toastService.showToast({

Check warning on line 510 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L510

Added line #L510 was not covered by tests
variant: "success",
title: null,
message: this.i18nService.t("invitedUsers"),
});
this.close(MemberDialogResult.Saved);

Check warning on line 515 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L515

Added line #L515 was not covered by tests
}

remove = async () => {
if (!this.editMode) {
if (!this.isEditDialogParams(this.params)) {
return;
}

Expand All @@ -494,7 +535,7 @@
}

if (this.showNoMasterPasswordWarning) {
confirmed = await this.noMasterPasswordConfirmationDialog();
confirmed = await this.noMasterPasswordConfirmationDialog(this.params.name);

Check warning on line 538 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L538

Added line #L538 was not covered by tests

if (!confirmed) {
return false;
Expand All @@ -515,7 +556,7 @@
};

revoke = async () => {
if (!this.editMode) {
if (!this.isEditDialogParams(this.params)) {
return;
}

Expand All @@ -531,7 +572,7 @@
}

if (this.showNoMasterPasswordWarning) {
confirmed = await this.noMasterPasswordConfirmationDialog();
confirmed = await this.noMasterPasswordConfirmationDialog(this.params.name);

Check warning on line 575 in apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/members/components/member-dialog/member-dialog.component.ts#L575

Added line #L575 was not covered by tests

if (!confirmed) {
return false;
Expand All @@ -553,7 +594,7 @@
};

restore = async () => {
if (!this.editMode) {
if (!this.isEditDialogParams(this.params)) {
return;
}

Expand All @@ -572,7 +613,7 @@
};

delete = async () => {
if (!this.editMode) {
if (!this.isEditDialogParams(this.params)) {
return;
}

Expand Down Expand Up @@ -620,14 +661,14 @@
this.dialogRef.close(result);
}

private noMasterPasswordConfirmationDialog() {
private noMasterPasswordConfirmationDialog(username: string) {
return this.dialogService.openSimpleDialog({
title: {
key: "removeOrgUserNoMasterPasswordTitle",
},
content: {
key: "removeOrgUserNoMasterPasswordDesc",
placeholders: [this.params.name],
placeholders: [username],
},
type: "warning",
});
Expand Down
Loading
Loading