Skip to content

Commit

Permalink
[PM-13346] Email notification impacts (#11967)
Browse files Browse the repository at this point in the history
* Changes error notification for disabled offer

* Add the feature to the change

* Add the missing dot

* Remove the authenicated endpoint

* Add the changes for error toast

* Resolve the lint issue

* rename file a correctly

* Remove the floating promise comments

* Delete unwanted comments
  • Loading branch information
cyprain-okeke authored Nov 14, 2024
1 parent 450d337 commit 4c194e6
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Component } from "@angular/core";
import { Component, inject } from "@angular/core";
import { Params } from "@angular/router";
import { firstValueFrom } from "rxjs";

import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
import { OrganizationSponsorshipResponse } from "@bitwarden/common/admin-console/models/response/organization-sponsorship.response";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { ToastService } from "@bitwarden/components";

import { BaseAcceptComponent } from "../../../common/base.accept.component";

/*
Expand All @@ -19,17 +24,18 @@ export class AcceptFamilySponsorshipComponent extends BaseAcceptComponent {

requiredParameters = ["email", "token"];

policyResponse!: OrganizationSponsorshipResponse;
policyApiService = inject(PolicyApiServiceAbstraction);
configService = inject(ConfigService);
toastService = inject(ToastService);

Check warning on line 30 in apps/web/src/app/admin-console/organizations/sponsorships/accept-family-sponsorship.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/sponsorships/accept-family-sponsorship.component.ts#L28-L30

Added lines #L28 - L30 were not covered by tests

async authedHandler(qParams: Params) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/setup/families-for-enterprise"], { queryParams: qParams });
await this.router.navigate(["/setup/families-for-enterprise"], { queryParams: qParams });

Check warning on line 33 in apps/web/src/app/admin-console/organizations/sponsorships/accept-family-sponsorship.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/sponsorships/accept-family-sponsorship.component.ts#L33

Added line #L33 was not covered by tests
}

async unauthedHandler(qParams: Params) {
if (!qParams.register) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/login"], { queryParams: { email: qParams.email } });
await this.router.navigate(["/login"], { queryParams: { email: qParams.email } });

Check warning on line 38 in apps/web/src/app/admin-console/organizations/sponsorships/accept-family-sponsorship.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/sponsorships/accept-family-sponsorship.component.ts#L38

Added line #L38 was not covered by tests
} else {
// TODO: update logic when email verification flag is removed
let queryParams: Params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
import { OrganizationUserType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { OrganizationSponsorshipRedeemRequest } from "@bitwarden/common/admin-console/models/request/organization/organization-sponsorship-redeem.request";
import { PreValidateSponsorshipResponse } from "@bitwarden/common/admin-console/models/response/pre-validate-sponsorship.response";
import { PlanSponsorshipType, PlanType, ProductTierType } from "@bitwarden/common/billing/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
Expand Down Expand Up @@ -51,6 +52,7 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {

showNewOrganization = false;
_organizationPlansComponent: OrganizationPlansComponent;
preValidateSponsorshipResponse: PreValidateSponsorshipResponse;
_selectedFamilyOrganizationId = "";

private _destroy = new Subject<void>();
Expand Down Expand Up @@ -92,7 +94,20 @@ export class FamiliesForEnterpriseSetupComponent implements OnInit, OnDestroy {
this.token = qParams.token;

await this.syncService.fullSync(true);
this.badToken = !(await this.apiService.postPreValidateSponsorshipToken(this.token));

this.preValidateSponsorshipResponse = await this.apiService.postPreValidateSponsorshipToken(

Check warning on line 98 in apps/web/src/app/admin-console/organizations/sponsorships/families-for-enterprise-setup.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/sponsorships/families-for-enterprise-setup.component.ts#L98

Added line #L98 was not covered by tests
this.token,
);
if (this.preValidateSponsorshipResponse.isFreeFamilyPolicyEnabled) {
this.toastService.showToast({

Check warning on line 102 in apps/web/src/app/admin-console/organizations/sponsorships/families-for-enterprise-setup.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/sponsorships/families-for-enterprise-setup.component.ts#L102

Added line #L102 was not covered by tests
variant: "error",
title: this.i18nService.t("errorOccured"),
message: this.i18nService.t("offerNoLongerValid"),
});
} else {
this.badToken = !this.preValidateSponsorshipResponse.isTokenValid;

Check warning on line 108 in apps/web/src/app/admin-console/organizations/sponsorships/families-for-enterprise-setup.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/sponsorships/families-for-enterprise-setup.component.ts#L108

Added line #L108 was not covered by tests
}

this.loading = false;
});

Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6373,6 +6373,9 @@
"idpSingleSignOnServiceUrlRequired": {
"message": "Required if Entity ID is not a URL."
},
"offerNoLongerValid": {
"message": "This offer is no longer valid. Contact your organization administrators for more information."
},
"openIdOptionalCustomizations": {
"message": "Optional customizations"
},
Expand Down
5 changes: 4 additions & 1 deletion libs/common/src/abstractions/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from "../admin-console/models/response/organization-connection.response";
import { OrganizationExportResponse } from "../admin-console/models/response/organization-export.response";
import { OrganizationSponsorshipSyncStatusResponse } from "../admin-console/models/response/organization-sponsorship-sync-status.response";
import { PreValidateSponsorshipResponse } from "../admin-console/models/response/pre-validate-sponsorship.response";
import {
ProviderOrganizationOrganizationDetailsResponse,
ProviderOrganizationResponse,
Expand Down Expand Up @@ -490,7 +491,9 @@ export abstract class ApiService {
) => Promise<OrganizationSponsorshipSyncStatusResponse>;
deleteRevokeSponsorship: (sponsoringOrganizationId: string) => Promise<void>;
deleteRemoveSponsorship: (sponsoringOrgId: string) => Promise<void>;
postPreValidateSponsorshipToken: (sponsorshipToken: string) => Promise<boolean>;
postPreValidateSponsorshipToken: (
sponsorshipToken: string,
) => Promise<PreValidateSponsorshipResponse>;
postRedeemSponsorship: (
sponsorshipToken: string,
request: OrganizationSponsorshipRedeemRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BaseResponse } from "../../../models/response/base.response";

Check warning on line 1 in libs/common/src/admin-console/models/response/organization-sponsorship.response.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/response/organization-sponsorship.response.ts#L1

Added line #L1 was not covered by tests

export class OrganizationSponsorshipResponse extends BaseResponse {

Check warning on line 3 in libs/common/src/admin-console/models/response/organization-sponsorship.response.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/response/organization-sponsorship.response.ts#L3

Added line #L3 was not covered by tests
isPolicyEnabled: string;

constructor(response: any) {
super(response);
this.isPolicyEnabled = this.getResponseProperty("IsPolicyEnabled");

Check warning on line 8 in libs/common/src/admin-console/models/response/organization-sponsorship.response.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/response/organization-sponsorship.response.ts#L7-L8

Added lines #L7 - L8 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BaseResponse } from "../../../models/response/base.response";

Check warning on line 1 in libs/common/src/admin-console/models/response/pre-validate-sponsorship.response.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/response/pre-validate-sponsorship.response.ts#L1

Added line #L1 was not covered by tests

export class PreValidateSponsorshipResponse extends BaseResponse {

Check warning on line 3 in libs/common/src/admin-console/models/response/pre-validate-sponsorship.response.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/response/pre-validate-sponsorship.response.ts#L3

Added line #L3 was not covered by tests
isTokenValid: boolean;
isFreeFamilyPolicyEnabled: boolean;

constructor(response: any) {
super(response);
this.isTokenValid = this.getResponseProperty("IsTokenValid");
this.isFreeFamilyPolicyEnabled = this.getResponseProperty("IsFreeFamilyPolicyEnabled");

Check warning on line 10 in libs/common/src/admin-console/models/response/pre-validate-sponsorship.response.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/admin-console/models/response/pre-validate-sponsorship.response.ts#L8-L10

Added lines #L8 - L10 were not covered by tests
}
}
10 changes: 7 additions & 3 deletions libs/common/src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from "../admin-console/models/response/organization-connection.response";
import { OrganizationExportResponse } from "../admin-console/models/response/organization-export.response";
import { OrganizationSponsorshipSyncStatusResponse } from "../admin-console/models/response/organization-sponsorship-sync-status.response";
import { PreValidateSponsorshipResponse } from "../admin-console/models/response/pre-validate-sponsorship.response";

Check warning on line 32 in libs/common/src/services/api.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/services/api.service.ts#L32

Added line #L32 was not covered by tests
import {
ProviderOrganizationOrganizationDetailsResponse,
ProviderOrganizationResponse,
Expand Down Expand Up @@ -1680,16 +1681,19 @@ export class ApiService implements ApiServiceAbstraction {
);
}

async postPreValidateSponsorshipToken(sponsorshipToken: string): Promise<boolean> {
const r = await this.send(
async postPreValidateSponsorshipToken(
sponsorshipToken: string,
): Promise<PreValidateSponsorshipResponse> {
const response = await this.send(

Check warning on line 1687 in libs/common/src/services/api.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/services/api.service.ts#L1687

Added line #L1687 was not covered by tests
"POST",
"/organization/sponsorship/validate-token?sponsorshipToken=" +
encodeURIComponent(sponsorshipToken),
null,
true,
true,
);
return r as boolean;

return new PreValidateSponsorshipResponse(response);

Check warning on line 1696 in libs/common/src/services/api.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/services/api.service.ts#L1696

Added line #L1696 was not covered by tests
}

async postRedeemSponsorship(
Expand Down

0 comments on commit 4c194e6

Please sign in to comment.