mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
[EC-243] Grant premium status when member accepts org invite (#2870)
* Rename setCanAccessPremium to setHasPremiumPersonally * Add hasPremiumFromOrganization * Refactor stateService methods * Add getHasPremiumPersonally, deprecate tokenService.getPremium
This commit is contained in:
@@ -337,13 +337,41 @@ export class StateService<
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
(await this.getHasPremiumPersonally(options)) ||
|
||||
(await this.getHasPremiumFromOrganization(options))
|
||||
);
|
||||
}
|
||||
|
||||
async getHasPremiumPersonally(options?: StorageOptions): Promise<boolean> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
if (account.profile.hasPremiumPersonally) {
|
||||
return account?.profile?.hasPremiumPersonally;
|
||||
}
|
||||
|
||||
async setHasPremiumPersonally(value: boolean, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
account.profile.hasPremiumPersonally = value;
|
||||
await this.saveAccount(
|
||||
account,
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
}
|
||||
|
||||
async getHasPremiumFromOrganization(options?: StorageOptions): Promise<boolean> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
|
||||
if (account.profile?.hasPremiumFromOrganization) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: older server versions won't send the hasPremiumFromOrganization flag, so we're keeping the old logic
|
||||
// for backwards compatibility. It can be removed after everyone has upgraded.
|
||||
const organizations = await this.getOrganizations(options);
|
||||
if (organizations == null) {
|
||||
return false;
|
||||
@@ -359,11 +387,11 @@ export class StateService<
|
||||
return false;
|
||||
}
|
||||
|
||||
async setCanAccessPremium(value: boolean, options?: StorageOptions): Promise<void> {
|
||||
async setHasPremiumFromOrganization(value: boolean, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
account.profile.hasPremiumPersonally = value;
|
||||
account.profile.hasPremiumFromOrganization = value;
|
||||
await this.saveAccount(
|
||||
account,
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
|
||||
@@ -304,7 +304,8 @@ export class SyncService implements SyncServiceAbstraction {
|
||||
await this.cryptoService.setOrgKeys(response.organizations, response.providerOrganizations);
|
||||
await this.stateService.setSecurityStamp(response.securityStamp);
|
||||
await this.stateService.setEmailVerified(response.emailVerified);
|
||||
await this.stateService.setCanAccessPremium(response.premium);
|
||||
await this.stateService.setHasPremiumPersonally(response.premiumPersonally);
|
||||
await this.stateService.setHasPremiumFromOrganization(response.premiumFromOrganization);
|
||||
await this.stateService.setForcePasswordReset(response.forcePasswordReset);
|
||||
await this.keyConnectorService.setUsesKeyConnector(response.usesKeyConnector);
|
||||
|
||||
|
||||
@@ -169,15 +169,6 @@ export class TokenService implements TokenServiceAbstraction {
|
||||
return decoded.name as string;
|
||||
}
|
||||
|
||||
async getPremium(): Promise<boolean> {
|
||||
const decoded = await this.decodeToken();
|
||||
if (typeof decoded.premium === "undefined") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return decoded.premium as boolean;
|
||||
}
|
||||
|
||||
async getIssuer(): Promise<string> {
|
||||
const decoded = await this.decodeToken();
|
||||
if (typeof decoded.iss === "undefined") {
|
||||
|
||||
Reference in New Issue
Block a user