Skip to content

Commit

Permalink
Add org authz service
Browse files Browse the repository at this point in the history
  • Loading branch information
eliykat committed Nov 20, 2024
1 parent 1c71e99 commit 0cf1f23
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { map, Observable } from "rxjs";

import { OrganizationUserType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

import { OrganizationAuthorizationService } from "./organization-authorization.service";

export class DefaultOrganizationAuthorizationService implements OrganizationAuthorizationService {
constructor(private configService: ConfigService) {}

canExport(org: Organization): Observable<boolean> {
return this.configService
.getFeatureFlag$(FeatureFlag.PM11360RemoveProviderExportPermission)
.pipe(
map((featureFlag) => {
if (!featureFlag && org.isProviderUser) {
return true;
}

return (
org.type === OrganizationUserType.Owner ||
org.type === OrganizationUserType.Admin ||
org.permissions.accessImportExport
);
}),
);
}

canImport(org: Organization) {
return (
org.isProviderUser ||
org.type === OrganizationUserType.Owner ||
org.type === OrganizationUserType.Admin ||
org.permissions.accessImportExport ||
org.canCreateNewCollections // To allow users to create collections and then import items into them
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Observable } from "rxjs";

import { Organization } from "../../models/domain/organization";

export abstract class OrganizationAuthorizationService {
canExport: (org: Organization) => Observable<boolean>;
canImport: (org: Organization) => boolean;
}

0 comments on commit 0cf1f23

Please sign in to comment.