1
0
mirror of https://github.com/bitwarden/browser synced 2024-12-27 10:23:48 +01:00

Override deprecated values on sync

This commit is contained in:
Thomas Rittson 2023-11-23 14:04:42 +10:00
parent a6e3d4d244
commit f0c25a6996
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27
3 changed files with 34 additions and 2 deletions

View File

@ -616,7 +616,7 @@ import { AbstractThemingService } from "./theming/theming.service.abstraction";
{
provide: OrganizationServiceAbstraction,
useClass: OrganizationService,
deps: [StateServiceAbstraction],
deps: [StateServiceAbstraction, ConfigServiceAbstraction],
},
{
provide: InternalOrganizationServiceAbstraction,

View File

@ -184,14 +184,29 @@ export class Organization {
return this.canEditAnyCollection || this.canDeleteAnyCollection;
}
/**
* @deprecated
* This is deprecated with the introduction of Flexible Collections.
* This will always return false if FlexibleCollections flag is on.
*/
get canEditAssignedCollections() {
return this.isManager || this.permissions.editAssignedCollections;
}
/**
* @deprecated
* This is deprecated with the introduction of Flexible Collections.
* This will always return false if FlexibleCollections flag is on.
*/
get canDeleteAssignedCollections() {
return this.isManager || this.permissions.deleteAssignedCollections;
}
/**
* @deprecated
* This is deprecated with the introduction of Flexible Collections.
* This will always return false if FlexibleCollections flag is on.
*/
get canViewAssignedCollections() {
return this.canDeleteAssignedCollections || this.canEditAssignedCollections;
}

View File

@ -1,10 +1,13 @@
import { BehaviorSubject, concatMap, map, Observable } from "rxjs";
import { FeatureFlag } from "../../../enums/feature-flag.enum";
import { ConfigServiceAbstraction } from "../../../platform/abstractions/config/config.service.abstraction";
import { StateService } from "../../../platform/abstractions/state.service";
import {
InternalOrganizationServiceAbstraction,
isMember,
} from "../../abstractions/organization/organization.service.abstraction";
import { OrganizationUserType } from "../../enums";
import { OrganizationData } from "../../models/data/organization.data";
import { Organization } from "../../models/domain/organization";
@ -14,7 +17,7 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
organizations$ = this._organizations.asObservable();
memberOrganizations$ = this.organizations$.pipe(map((orgs) => orgs.filter(isMember)));
constructor(private stateService: StateService) {
constructor(private stateService: StateService, private configService: ConfigServiceAbstraction) {
this.stateService.activeAccountUnlocked$
.pipe(
concatMap(async (unlocked) => {
@ -103,6 +106,20 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
}
async replace(organizations: { [id: string]: OrganizationData }) {
// If Flexible Collections is enabled, treat Managers as Users and ignore deprecated permissions
if (await this.configService.getFeatureFlag(FeatureFlag.FlexibleCollections)) {
Object.values(organizations).forEach((o) => {
if (o.type === OrganizationUserType.Manager) {
o.type = OrganizationUserType.User;
}
if (o.permissions != null) {
o.permissions.editAssignedCollections = false;
o.permissions.deleteAssignedCollections = false;
}
});
}
await this.stateService.setOrganizations(organizations);
this.updateObservables(organizations);
}