From 7b55096edfe51c035e8bbe30658107d705a8c6c3 Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:31:24 -0500 Subject: [PATCH] [PS-1942] Add Provider Filters (#4147) * Add Helper to filter out Provider Orgs * Use filter where getAll used to be used * Change name to isNotProviderUser --- .../app/components/organization-switcher.component.ts | 2 ++ apps/web/src/app/layouts/navbar.component.ts | 4 +++- libs/angular/src/components/share.component.ts | 10 ++++++++-- .../vault-filter/services/vault-filter.service.ts | 9 +++++++-- .../organization/organization.service.abstraction.ts | 4 ++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/web/src/app/components/organization-switcher.component.ts b/apps/web/src/app/components/organization-switcher.component.ts index 70ea6385fe..a7aafa15da 100644 --- a/apps/web/src/app/components/organization-switcher.component.ts +++ b/apps/web/src/app/components/organization-switcher.component.ts @@ -4,6 +4,7 @@ import { map, Observable } from "rxjs"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { canAccessAdmin, + isNotProviderUser, OrganizationService, } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { Utils } from "@bitwarden/common/misc/utils"; @@ -23,6 +24,7 @@ export class OrganizationSwitcherComponent implements OnInit { async ngOnInit() { this.organizations$ = this.organizationService.organizations$.pipe( + map((orgs) => orgs.filter(isNotProviderUser)), canAccessAdmin(this.i18nService), map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))) ); diff --git a/apps/web/src/app/layouts/navbar.component.ts b/apps/web/src/app/layouts/navbar.component.ts index 8696f6eb32..aae5c516da 100644 --- a/apps/web/src/app/layouts/navbar.component.ts +++ b/apps/web/src/app/layouts/navbar.component.ts @@ -1,10 +1,11 @@ import { Component, OnInit } from "@angular/core"; -import { Observable } from "rxjs"; +import { map, Observable } from "rxjs"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { canAccessAdmin, + isNotProviderUser, OrganizationService, } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -54,6 +55,7 @@ export class NavbarComponent implements OnInit { this.providers = await this.providerService.getAll(); this.organizations$ = this.organizationService.organizations$.pipe( + map((orgs) => orgs.filter(isNotProviderUser)), canAccessAdmin(this.i18nService) ); } diff --git a/libs/angular/src/components/share.component.ts b/libs/angular/src/components/share.component.ts index c7520ed516..e12aeb0211 100644 --- a/libs/angular/src/components/share.component.ts +++ b/libs/angular/src/components/share.component.ts @@ -5,7 +5,10 @@ import { CipherService } from "@bitwarden/common/abstractions/cipher.service"; import { CollectionService } from "@bitwarden/common/abstractions/collection.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; -import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; +import { + isNotProviderUser, + OrganizationService, +} from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType"; import { Utils } from "@bitwarden/common/misc/utils"; @@ -54,7 +57,10 @@ export class ShareComponent implements OnInit, OnDestroy { this.organizations$ = this.organizationService.organizations$.pipe( map((orgs) => { return orgs - .filter((o) => o.enabled && o.status === OrganizationUserStatusType.Confirmed) + .filter( + (o) => + o.enabled && o.status === OrganizationUserStatusType.Confirmed && isNotProviderUser(o) + ) .sort(Utils.getSortFunction(this.i18nService, "name")); }) ); diff --git a/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts b/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts index 5f33a8b78a..eede037006 100644 --- a/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts +++ b/libs/angular/src/vault/vault-filter/services/vault-filter.service.ts @@ -4,7 +4,10 @@ import { firstValueFrom, from, mergeMap, Observable } from "rxjs"; import { CipherService } from "@bitwarden/common/abstractions/cipher.service"; import { CollectionService } from "@bitwarden/common/abstractions/collection.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; -import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; +import { + isNotProviderUser, + OrganizationService, +} from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; import { PolicyType } from "@bitwarden/common/enums/policyType"; @@ -40,7 +43,9 @@ export class VaultFilterService { async buildOrganizations(): Promise { let organizations = await this.organizationService.getAll(); if (organizations != null) { - organizations = organizations.sort((a, b) => a.name.localeCompare(b.name)); + organizations = organizations + .filter(isNotProviderUser) + .sort((a, b) => a.name.localeCompare(b.name)); } return organizations; diff --git a/libs/common/src/abstractions/organization/organization.service.abstraction.ts b/libs/common/src/abstractions/organization/organization.service.abstraction.ts index 68c64654d5..7a59455163 100644 --- a/libs/common/src/abstractions/organization/organization.service.abstraction.ts +++ b/libs/common/src/abstractions/organization/organization.service.abstraction.ts @@ -70,6 +70,10 @@ export function canAccessAdmin(i18nService: I18nService) { ); } +export function isNotProviderUser(org: Organization): boolean { + return !org.isProviderUser; +} + export abstract class OrganizationService { organizations$: Observable;