1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-28 12:45:45 +01:00

[AC-1893] Removed logic to downgrade Manager roles and remove Edit/Delete any collection permissions for Flexible Collections (#7365)

This commit is contained in:
Rui Tomé 2024-01-11 21:54:11 +00:00 committed by GitHub
parent 0874df8b84
commit 48643e45ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 58 deletions

View File

@ -581,7 +581,6 @@ export default class MainBackground {
this.folderApiService, this.folderApiService,
this.organizationService, this.organizationService,
this.sendApiService, this.sendApiService,
this.configService,
logoutCallback, logoutCallback,
); );
this.eventUploadService = new EventUploadService( this.eventUploadService = new EventUploadService(

View File

@ -480,7 +480,6 @@ export class Main {
this.folderApiService, this.folderApiService,
this.organizationService, this.organizationService,
this.sendApiService, this.sendApiService,
this.configService,
async (expired: boolean) => await this.logout(), async (expired: boolean) => await this.logout(),
); );

View File

@ -9,8 +9,6 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
import { SecretsManagerSubscribeRequest } from "@bitwarden/common/billing/models/request/sm-subscribe.request"; import { SecretsManagerSubscribeRequest } from "@bitwarden/common/billing/models/request/sm-subscribe.request";
import { BillingCustomerDiscount } from "@bitwarden/common/billing/models/response/organization-subscription.response"; import { BillingCustomerDiscount } from "@bitwarden/common/billing/models/response/organization-subscription.response";
import { PlanResponse } from "@bitwarden/common/billing/models/response/plan.response"; import { PlanResponse } from "@bitwarden/common/billing/models/response/plan.response";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
@ -35,7 +33,6 @@ export class SecretsManagerSubscribeStandaloneComponent {
private i18nService: I18nService, private i18nService: I18nService,
private organizationApiService: OrganizationApiServiceAbstraction, private organizationApiService: OrganizationApiServiceAbstraction,
private organizationService: InternalOrganizationServiceAbstraction, private organizationService: InternalOrganizationServiceAbstraction,
private configService: ConfigServiceAbstraction,
) {} ) {}
submit = async () => { submit = async () => {
@ -55,11 +52,7 @@ export class SecretsManagerSubscribeStandaloneComponent {
isMember: this.organization.isMember, isMember: this.organization.isMember,
isProviderUser: this.organization.isProviderUser, isProviderUser: this.organization.isProviderUser,
}); });
const flexibleCollectionsEnabled = await this.configService.getFeatureFlag( await this.organizationService.upsert(organizationData);
FeatureFlag.FlexibleCollections,
false,
);
await this.organizationService.upsert(organizationData, flexibleCollectionsEnabled);
/* /*
Because subscribing to Secrets Manager automatically provides access to Secrets Manager for the Because subscribing to Secrets Manager automatically provides access to Secrets Manager for the

View File

@ -461,7 +461,6 @@ import { ModalService } from "./modal.service";
FolderApiServiceAbstraction, FolderApiServiceAbstraction,
OrganizationServiceAbstraction, OrganizationServiceAbstraction,
SendApiServiceAbstraction, SendApiServiceAbstraction,
ConfigServiceAbstraction,
LOGOUT_CALLBACK, LOGOUT_CALLBACK,
], ],
}, },

View File

@ -95,12 +95,6 @@ export abstract class OrganizationService {
} }
export abstract class InternalOrganizationServiceAbstraction extends OrganizationService { export abstract class InternalOrganizationServiceAbstraction extends OrganizationService {
replace: ( replace: (organizations: { [id: string]: OrganizationData }) => Promise<void>;
organizations: { [id: string]: OrganizationData }, upsert: (OrganizationData: OrganizationData | OrganizationData[]) => Promise<void>;
flexibleCollectionsEnabled: boolean,
) => Promise<void>;
upsert: (
OrganizationData: OrganizationData | OrganizationData[],
flexibleCollectionsEnabled: boolean,
) => Promise<void>;
} }

View File

@ -110,7 +110,7 @@ describe("Organization Service", () => {
}); });
it("upsert", async () => { it("upsert", async () => {
await organizationService.upsert(organizationData("2", "Test 2"), false); await organizationService.upsert(organizationData("2", "Test 2"));
expect(await firstValueFrom(organizationService.organizations$)).toEqual([ expect(await firstValueFrom(organizationService.organizations$)).toEqual([
{ {
@ -146,7 +146,7 @@ describe("Organization Service", () => {
describe("delete", () => { describe("delete", () => {
it("exists", async () => { it("exists", async () => {
await organizationService.delete("1", false); await organizationService.delete("1");
expect(stateService.getOrganizations).toHaveBeenCalledTimes(2); expect(stateService.getOrganizations).toHaveBeenCalledTimes(2);
@ -154,7 +154,7 @@ describe("Organization Service", () => {
}); });
it("does not exist", async () => { it("does not exist", async () => {
organizationService.delete("1", false); organizationService.delete("1");
expect(stateService.getOrganizations).toHaveBeenCalledTimes(2); expect(stateService.getOrganizations).toHaveBeenCalledTimes(2);
}); });

View File

@ -5,7 +5,6 @@ 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";
@ -52,7 +51,7 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
return organizations.length > 0; return organizations.length > 0;
} }
async upsert(organization: OrganizationData, flexibleCollectionsEnabled: boolean): Promise<void> { async upsert(organization: OrganizationData): Promise<void> {
let organizations = await this.stateService.getOrganizations(); let organizations = await this.stateService.getOrganizations();
if (organizations == null) { if (organizations == null) {
organizations = {}; organizations = {};
@ -60,10 +59,10 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
organizations[organization.id] = organization; organizations[organization.id] = organization;
await this.replace(organizations, flexibleCollectionsEnabled); await this.replace(organizations);
} }
async delete(id: string, flexibleCollectionsEnabled: boolean): Promise<void> { async delete(id: string): Promise<void> {
const organizations = await this.stateService.getOrganizations(); const organizations = await this.stateService.getOrganizations();
if (organizations == null) { if (organizations == null) {
return; return;
@ -74,7 +73,7 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
} }
delete organizations[id]; delete organizations[id];
await this.replace(organizations, flexibleCollectionsEnabled); await this.replace(organizations);
} }
get(id: string): Organization { get(id: string): Organization {
@ -103,24 +102,7 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
return organizations.find((organization) => organization.identifier === identifier); return organizations.find((organization) => organization.identifier === identifier);
} }
async replace( async replace(organizations: { [id: string]: OrganizationData }) {
organizations: { [id: string]: OrganizationData },
flexibleCollectionsEnabled: boolean,
) {
// If Flexible Collections is enabled, treat Managers as Users and ignore deprecated permissions
if (flexibleCollectionsEnabled) {
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,7 +10,6 @@ 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,
@ -18,7 +17,6 @@ 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";
@ -61,7 +59,6 @@ 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>,
) {} ) {}
@ -321,11 +318,7 @@ export class SyncService implements SyncServiceAbstraction {
await this.setForceSetPasswordReasonIfNeeded(response); await this.setForceSetPasswordReasonIfNeeded(response);
const flexibleCollectionsEnabled = await this.configService.getFeatureFlag( await this.syncProfileOrganizations(response);
FeatureFlag.FlexibleCollections,
false,
);
await this.syncProfileOrganizations(response, flexibleCollectionsEnabled);
const providers: { [id: string]: ProviderData } = {}; const providers: { [id: string]: ProviderData } = {};
response.providers.forEach((p) => { response.providers.forEach((p) => {
@ -393,10 +386,7 @@ export class SyncService implements SyncServiceAbstraction {
} }
} }
private async syncProfileOrganizations( private async syncProfileOrganizations(response: ProfileResponse) {
response: ProfileResponse,
flexibleCollectionsEnabled: boolean,
) {
const organizations: { [id: string]: OrganizationData } = {}; const organizations: { [id: string]: OrganizationData } = {};
response.organizations.forEach((o) => { response.organizations.forEach((o) => {
organizations[o.id] = new OrganizationData(o, { organizations[o.id] = new OrganizationData(o, {
@ -416,7 +406,7 @@ export class SyncService implements SyncServiceAbstraction {
} }
}); });
await this.organizationService.replace(organizations, flexibleCollectionsEnabled); await this.organizationService.replace(organizations);
} }
private async syncFolders(response: FolderResponse[]) { private async syncFolders(response: FolderResponse[]) {