1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

[AC-1139] Moved overriding of deprecated values to syncService

This commit is contained in:
Rui Tome
2023-11-27 15:27:54 +00:00
parent 6484420976
commit c6d80670ae
3 changed files with 19 additions and 18 deletions

View File

@@ -450,6 +450,7 @@ import { AbstractThemingService } from "./theming/theming.service.abstraction";
FolderApiServiceAbstraction, FolderApiServiceAbstraction,
OrganizationServiceAbstraction, OrganizationServiceAbstraction,
SendApiServiceAbstraction, SendApiServiceAbstraction,
ConfigServiceAbstraction,
LOGOUT_CALLBACK, LOGOUT_CALLBACK,
], ],
}, },

View File

@@ -1,13 +1,10 @@
import { BehaviorSubject, concatMap, map, Observable } from "rxjs"; 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 { StateService } from "../../../platform/abstractions/state.service";
import { import {
InternalOrganizationServiceAbstraction, InternalOrganizationServiceAbstraction,
isMember, isMember,
} from "../../abstractions/organization/organization.service.abstraction"; } from "../../abstractions/organization/organization.service.abstraction";
import { OrganizationUserType } from "../../enums";
import { OrganizationData } from "../../models/data/organization.data"; import { OrganizationData } from "../../models/data/organization.data";
import { Organization } from "../../models/domain/organization"; import { Organization } from "../../models/domain/organization";
@@ -17,7 +14,7 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
organizations$ = this._organizations.asObservable(); organizations$ = this._organizations.asObservable();
memberOrganizations$ = this.organizations$.pipe(map((orgs) => orgs.filter(isMember))); memberOrganizations$ = this.organizations$.pipe(map((orgs) => orgs.filter(isMember)));
constructor(private stateService: StateService, private configService: ConfigServiceAbstraction) { constructor(private stateService: StateService) {
this.stateService.activeAccountUnlocked$ this.stateService.activeAccountUnlocked$
.pipe( .pipe(
concatMap(async (unlocked) => { concatMap(async (unlocked) => {
@@ -106,20 +103,6 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
} }
async replace(organizations: { [id: string]: OrganizationData }) { 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); await this.stateService.setOrganizations(organizations);
this.updateObservables(organizations); this.updateObservables(organizations);
} }

View File

@@ -10,6 +10,7 @@ import { ProviderData } from "../../../admin-console/models/data/provider.data";
import { PolicyResponse } from "../../../admin-console/models/response/policy.response"; import { PolicyResponse } from "../../../admin-console/models/response/policy.response";
import { KeyConnectorService } from "../../../auth/abstractions/key-connector.service"; import { KeyConnectorService } from "../../../auth/abstractions/key-connector.service";
import { ForceSetPasswordReason } from "../../../auth/models/domain/force-set-password-reason"; import { ForceSetPasswordReason } from "../../../auth/models/domain/force-set-password-reason";
import { FeatureFlag } from "../../../enums/feature-flag.enum";
import { DomainsResponse } from "../../../models/response/domains.response"; import { DomainsResponse } from "../../../models/response/domains.response";
import { import {
SyncCipherNotification, SyncCipherNotification,
@@ -17,6 +18,7 @@ import {
SyncSendNotification, SyncSendNotification,
} from "../../../models/response/notification.response"; } from "../../../models/response/notification.response";
import { ProfileResponse } from "../../../models/response/profile.response"; import { ProfileResponse } from "../../../models/response/profile.response";
import { ConfigServiceAbstraction } from "../../../platform/abstractions/config/config.service.abstraction";
import { CryptoService } from "../../../platform/abstractions/crypto.service"; import { CryptoService } from "../../../platform/abstractions/crypto.service";
import { LogService } from "../../../platform/abstractions/log.service"; import { LogService } from "../../../platform/abstractions/log.service";
import { MessagingService } from "../../../platform/abstractions/messaging.service"; import { MessagingService } from "../../../platform/abstractions/messaging.service";
@@ -59,6 +61,7 @@ export class SyncService implements SyncServiceAbstraction {
private folderApiService: FolderApiServiceAbstraction, private folderApiService: FolderApiServiceAbstraction,
private organizationService: InternalOrganizationServiceAbstraction, private organizationService: InternalOrganizationServiceAbstraction,
private sendApiService: SendApiService, private sendApiService: SendApiService,
private configService: ConfigServiceAbstraction,
private logoutCallback: (expired: boolean) => Promise<void> private logoutCallback: (expired: boolean) => Promise<void>
) {} ) {}
@@ -394,6 +397,20 @@ export class SyncService implements SyncServiceAbstraction {
} }
}); });
// 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.organizationService.replace(organizations); await this.organizationService.replace(organizations);
} }