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

Add logic for fetching organization policies if the user has access through a provider (#519)

This commit is contained in:
Oscar Hinton 2021-10-14 09:33:46 +02:00 committed by GitHub
parent a20e935268
commit 14a60773cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import { OrganizationUserStatusType } from '../enums/organizationUserStatusType'
import { OrganizationUserType } from '../enums/organizationUserType'; import { OrganizationUserType } from '../enums/organizationUserType';
import { PolicyType } from '../enums/policyType'; import { PolicyType } from '../enums/policyType';
import { ApiService } from '../abstractions/api.service';
import { ListResponse } from '../models/response/listResponse'; import { ListResponse } from '../models/response/listResponse';
import { PolicyResponse } from '../models/response/policyResponse'; import { PolicyResponse } from '../models/response/policyResponse';
@ -23,7 +24,8 @@ const Keys = {
export class PolicyService implements PolicyServiceAbstraction { export class PolicyService implements PolicyServiceAbstraction {
policyCache: Policy[]; policyCache: Policy[];
constructor(private userService: UserService, private storageService: StorageService) { constructor(private userService: UserService, private storageService: StorageService,
private apiService: ApiService) {
} }
clearCache(): void { clearCache(): void {
@ -51,6 +53,18 @@ export class PolicyService implements PolicyServiceAbstraction {
} }
async getPolicyForOrganization(policyType: PolicyType, organizationId: string): Promise<Policy> { async getPolicyForOrganization(policyType: PolicyType, organizationId: string): Promise<Policy> {
const org = await this.userService.getOrganization(organizationId);
if (org?.isProviderUser) {
const orgPolicies = await this.apiService.getPolicies(organizationId);
const policy = orgPolicies.data.find(p => p.organizationId === organizationId);
if (policy == null) {
return null;
}
return new Policy(new PolicyData(policy));
}
const policies = await this.getAll(policyType); const policies = await this.getAll(policyType);
return policies.find(p => p.organizationId === organizationId); return policies.find(p => p.organizationId === organizationId);
} }