1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 07:13:32 +00:00

Wire up key definitions for OrganizationService (#7781)

* Wire up key definitions for OrganizationService

[`AC-2009`: Transition OrganizationService to use StateProvider](
https://bitwarden.atlassian.net/browse/AC-2009)

In order to support the new `StateProvider` APIs for managing
application state this commit modifies `OrganizationService` in the following
ways:

1. Adding a `KeyDefinition` object to `OrganizationService` to store the
   `organization` record in `StateProvider`.
1. Injecting `StateProvider` and wiring up `OrganizationService` to read
   from the `organizations` key definition for the active user account.
1. Expanding the capabilities of `OrganizationData` to be able to read
   itself from a JSON string. Previously this was handled directly by
   `StateService`.
1. Updating tests to include requirements for testing against
   `StateProvider`.
1. Marking the existing `StateService`-backed `organizations`
   `Observable` and `BehaviorSubject` as deprecated.

This is largely unimplemented code with no intended visible effects to
the system. Implementing getting & updating the `organizations` value
from `StateProvider` will the next step in this work.

* Rework null check on OrganizationData

* Remove deprecation signals for the time being

* Move key definition inline with its service

* Create date objects when deserialzing json from state
This commit is contained in:
Addison Beck
2024-02-06 18:48:34 -06:00
committed by GitHub
parent fb17cb7b99
commit b3135403e8
8 changed files with 152 additions and 14 deletions

View File

@@ -0,0 +1,62 @@
import { ProductType } from "../../../enums/product-type.enum";
import { OrganizationUserStatusType, OrganizationUserType } from "../../enums";
import { ORGANIZATIONS } from "../../services/organization/organization.service";
import { OrganizationData } from "./organization.data";
describe("ORGANIZATIONS state", () => {
const sut = ORGANIZATIONS;
it("should deserialize JSON string to proper object", async () => {
const expectedResult: Record<string, OrganizationData> = {
"1": {
id: "id",
name: "name",
status: OrganizationUserStatusType.Invited,
type: OrganizationUserType.Owner,
enabled: false,
usePolicies: false,
useGroups: false,
useDirectory: false,
useEvents: false,
useTotp: false,
use2fa: false,
useApi: false,
useSso: false,
useKeyConnector: false,
useScim: false,
useCustomPermissions: false,
useResetPassword: false,
useSecretsManager: false,
usePasswordManager: false,
useActivateAutofillPolicy: false,
selfHost: false,
usersGetPremium: false,
seats: 0,
maxCollections: 0,
ssoBound: false,
identifier: "identifier",
permissions: undefined,
resetPasswordEnrolled: false,
userId: "userId",
hasPublicAndPrivateKeys: false,
providerId: "providerId",
providerName: "providerName",
isProviderUser: false,
isMember: false,
familySponsorshipFriendlyName: "fsfn",
familySponsorshipAvailable: false,
planProductType: ProductType.Free,
keyConnectorEnabled: false,
keyConnectorUrl: "kcu",
accessSecretsManager: false,
limitCollectionCreationDeletion: false,
allowAdminAccessToAllCollectionItems: false,
flexibleCollections: false,
familySponsorshipLastSyncDate: new Date(),
},
};
const result = sut.deserializer(JSON.parse(JSON.stringify(expectedResult)));
expect(result).toEqual(expectedResult);
});
});

View File

@@ -1,3 +1,5 @@
import { Jsonify } from "type-fest";
import { ProductType } from "../../../enums";
import { OrganizationUserStatusType, OrganizationUserType, ProviderType } from "../../enums";
import { PermissionsApi } from "../api/permissions.api";
@@ -54,12 +56,16 @@ export class OrganizationData {
flexibleCollections: boolean;
constructor(
response: ProfileOrganizationResponse,
options: {
response?: ProfileOrganizationResponse,
options?: {
isMember: boolean;
isProviderUser: boolean;
},
) {
if (response == null) {
return;
}
this.id = response.id;
this.name = response.name;
this.status = response.status;
@@ -110,4 +116,17 @@ export class OrganizationData {
this.isMember = options.isMember;
this.isProviderUser = options.isProviderUser;
}
static fromJSON(obj: Jsonify<OrganizationData>) {
return Object.assign(new OrganizationData(), obj, {
familySponsorshipLastSyncDate:
obj.familySponsorshipLastSyncDate != null
? new Date(obj.familySponsorshipLastSyncDate)
: obj.familySponsorshipLastSyncDate,
familySponsorshipValidUntil:
obj.familySponsorshipValidUntil != null
? new Date(obj.familySponsorshipValidUntil)
: obj.familySponsorshipValidUntil,
});
}
}