mirror of
https://github.com/bitwarden/jslib
synced 2025-12-26 05:03:41 +00:00
Get collections from server if admin
This commit is contained in:
@@ -15,6 +15,8 @@ import { DynamicTreeNode } from "./models/dynamic-tree-node.model";
|
||||
|
||||
@Injectable()
|
||||
export class VaultFilterService {
|
||||
getAllCollectionsFromServer = false;
|
||||
|
||||
constructor(
|
||||
protected stateService: StateService,
|
||||
protected organizationService: OrganizationService,
|
||||
@@ -58,13 +60,10 @@ export class VaultFilterService {
|
||||
}
|
||||
|
||||
async buildCollections(organizationId?: string): Promise<DynamicTreeNode<CollectionView>> {
|
||||
const storedCollections = await this.collectionService.getAllDecrypted();
|
||||
let collections: CollectionView[];
|
||||
if (organizationId != null) {
|
||||
collections = storedCollections.filter((c) => c.organizationId === organizationId);
|
||||
} else {
|
||||
collections = storedCollections;
|
||||
}
|
||||
const collections = this.getAllCollectionsFromServer
|
||||
? await this.collectionService.getOrgCollectionsFromServer(organizationId)
|
||||
: await this.getUserCollections(organizationId);
|
||||
|
||||
const nestedCollections = await this.collectionService.getAllNested(collections);
|
||||
return new DynamicTreeNode<CollectionView>({
|
||||
fullList: collections,
|
||||
@@ -72,6 +71,13 @@ export class VaultFilterService {
|
||||
});
|
||||
}
|
||||
|
||||
private async getUserCollections(organizationId?: string): Promise<CollectionView[]> {
|
||||
const storedCollections = await this.collectionService.getAllDecrypted();
|
||||
return organizationId != null
|
||||
? storedCollections.filter((c) => c.organizationId === organizationId)
|
||||
: storedCollections;
|
||||
}
|
||||
|
||||
async checkForSingleOrganizationPolicy(): Promise<boolean> {
|
||||
return await this.policyService.policyAppliesToUser(PolicyType.SingleOrg);
|
||||
}
|
||||
|
||||
@@ -213,7 +213,12 @@ export const SYSTEM_LANGUAGE = new InjectionToken<string>("SYSTEM_LANGUAGE");
|
||||
{
|
||||
provide: CollectionServiceAbstraction,
|
||||
useClass: CollectionService,
|
||||
deps: [CryptoServiceAbstraction, I18nServiceAbstraction, StateServiceAbstraction],
|
||||
deps: [
|
||||
CryptoServiceAbstraction,
|
||||
I18nServiceAbstraction,
|
||||
StateServiceAbstraction,
|
||||
ApiServiceAbstraction,
|
||||
],
|
||||
},
|
||||
{
|
||||
provide: EnvironmentServiceAbstraction,
|
||||
|
||||
Reference in New Issue
Block a user