mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
[PM-3478] Refactor OrganizationUser api (#10949)
* User and Group collection dialogs - don't fetch additional associations from the api * Refactor to use user mini-details endpoint
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
OrganizationUserDetailsResponse,
|
||||
OrganizationUserResetPasswordDetailsResponse,
|
||||
OrganizationUserUserDetailsResponse,
|
||||
OrganizationUserUserMiniResponse,
|
||||
} from "../models/responses";
|
||||
|
||||
/**
|
||||
@@ -44,7 +45,9 @@ export abstract class OrganizationUserApiService {
|
||||
abstract getOrganizationUserGroups(organizationId: string, id: string): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* Retrieve a list of all users that belong to the specified organization
|
||||
* Retrieve full details of all users that belong to the specified organization.
|
||||
* This is only accessible to privileged users, if you need a simple listing of basic details, use
|
||||
* {@link getAllMiniUserDetails}.
|
||||
* @param organizationId - Identifier for the organization
|
||||
* @param options - Options for the request
|
||||
*/
|
||||
@@ -56,6 +59,16 @@ export abstract class OrganizationUserApiService {
|
||||
},
|
||||
): Promise<ListResponse<OrganizationUserUserDetailsResponse>>;
|
||||
|
||||
/**
|
||||
* Retrieve a list of all users that belong to the specified organization, with basic information only.
|
||||
* This is suitable for lists of names/emails etc. throughout the app and can be accessed by most users.
|
||||
* @param organizationId - Identifier for the organization
|
||||
* @param options - Options for the request
|
||||
*/
|
||||
abstract getAllMiniUserDetails(
|
||||
organizationId: string,
|
||||
): Promise<ListResponse<OrganizationUserUserMiniResponse>>;
|
||||
|
||||
/**
|
||||
* Retrieve reset password details for the specified organization user
|
||||
* @param organizationId - Identifier for the user's organization
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./organization-user.response";
|
||||
export * from "./organization-user-bulk.response";
|
||||
export * from "./organization-user-bulk-public-key.response";
|
||||
export * from "./organization-user-mini.response";
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
OrganizationUserStatusType,
|
||||
OrganizationUserType,
|
||||
} from "@bitwarden/common/admin-console/enums";
|
||||
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
|
||||
|
||||
export class OrganizationUserUserMiniResponse extends BaseResponse {
|
||||
id: string;
|
||||
userId: string;
|
||||
email: string;
|
||||
name: string;
|
||||
type: OrganizationUserType;
|
||||
status: OrganizationUserStatusType;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.id = this.getResponseProperty("Id");
|
||||
this.userId = this.getResponseProperty("UserId");
|
||||
this.email = this.getResponseProperty("Email");
|
||||
this.name = this.getResponseProperty("Name");
|
||||
this.type = this.getResponseProperty("Type");
|
||||
this.status = this.getResponseProperty("Status");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
|
||||
import { OrganizationUserApiService } from "../abstractions";
|
||||
import {
|
||||
@@ -19,10 +23,14 @@ import {
|
||||
OrganizationUserDetailsResponse,
|
||||
OrganizationUserResetPasswordDetailsResponse,
|
||||
OrganizationUserUserDetailsResponse,
|
||||
OrganizationUserUserMiniResponse,
|
||||
} from "../models/responses";
|
||||
|
||||
export class DefaultOrganizationUserApiService implements OrganizationUserApiService {
|
||||
constructor(private apiService: ApiService) {}
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async getOrganizationUser(
|
||||
organizationId: string,
|
||||
@@ -84,6 +92,27 @@ export class DefaultOrganizationUserApiService implements OrganizationUserApiSer
|
||||
return new ListResponse(r, OrganizationUserUserDetailsResponse);
|
||||
}
|
||||
|
||||
async getAllMiniUserDetails(
|
||||
organizationId: string,
|
||||
): Promise<ListResponse<OrganizationUserUserMiniResponse>> {
|
||||
const apiEnabled = await firstValueFrom(
|
||||
this.configService.getFeatureFlag$(FeatureFlag.Pm3478RefactorOrganizationUserApi),
|
||||
);
|
||||
if (!apiEnabled) {
|
||||
// Keep using the old api until this feature flag is enabled
|
||||
return this.getAllUsers(organizationId);
|
||||
}
|
||||
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
`/organizations/${organizationId}/users/mini-details`,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
return new ListResponse(r, OrganizationUserUserMiniResponse);
|
||||
}
|
||||
|
||||
async getOrganizationUserResetPasswordDetails(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
|
||||
@@ -952,7 +952,7 @@ const safeProviders: SafeProvider[] = [
|
||||
safeProvider({
|
||||
provide: OrganizationUserApiService,
|
||||
useClass: DefaultOrganizationUserApiService,
|
||||
deps: [ApiServiceAbstraction],
|
||||
deps: [ApiServiceAbstraction, ConfigService],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: PasswordResetEnrollmentServiceAbstraction,
|
||||
|
||||
@@ -34,6 +34,7 @@ export enum FeatureFlag {
|
||||
AC2476_DeprecateStripeSourcesAPI = "AC-2476-deprecate-stripe-sources-api",
|
||||
CipherKeyEncryption = "cipher-key-encryption",
|
||||
PM11901_RefactorSelfHostingLicenseUploader = "PM-11901-refactor-self-hosting-license-uploader",
|
||||
Pm3478RefactorOrganizationUserApi = "pm-3478-refactor-organizationuser-api",
|
||||
}
|
||||
|
||||
export type AllowedFeatureFlagTypes = boolean | number | string;
|
||||
@@ -78,6 +79,7 @@ export const DefaultFeatureFlagValue = {
|
||||
[FeatureFlag.AC2476_DeprecateStripeSourcesAPI]: FALSE,
|
||||
[FeatureFlag.CipherKeyEncryption]: FALSE,
|
||||
[FeatureFlag.PM11901_RefactorSelfHostingLicenseUploader]: FALSE,
|
||||
[FeatureFlag.Pm3478RefactorOrganizationUserApi]: FALSE,
|
||||
} satisfies Record<FeatureFlag, AllowedFeatureFlagTypes>;
|
||||
|
||||
export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;
|
||||
|
||||
Reference in New Issue
Block a user