mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
Add logic for fetching organization policies if the user has access through a provider (#519)
This commit is contained in:
parent
a20e935268
commit
14a60773cc
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user