mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 15:23:33 +00:00
* User and Group collection dialogs - don't fetch additional associations from the api * Refactor to use user mini-details endpoint
378 lines
10 KiB
TypeScript
378 lines
10 KiB
TypeScript
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 {
|
|
OrganizationUserAcceptInitRequest,
|
|
OrganizationUserAcceptRequest,
|
|
OrganizationUserBulkConfirmRequest,
|
|
OrganizationUserConfirmRequest,
|
|
OrganizationUserInviteRequest,
|
|
OrganizationUserResetPasswordEnrollmentRequest,
|
|
OrganizationUserResetPasswordRequest,
|
|
OrganizationUserUpdateRequest,
|
|
OrganizationUserBulkRequest,
|
|
} from "../models/requests";
|
|
import {
|
|
OrganizationUserBulkPublicKeyResponse,
|
|
OrganizationUserBulkResponse,
|
|
OrganizationUserDetailsResponse,
|
|
OrganizationUserResetPasswordDetailsResponse,
|
|
OrganizationUserUserDetailsResponse,
|
|
OrganizationUserUserMiniResponse,
|
|
} from "../models/responses";
|
|
|
|
export class DefaultOrganizationUserApiService implements OrganizationUserApiService {
|
|
constructor(
|
|
private apiService: ApiService,
|
|
private configService: ConfigService,
|
|
) {}
|
|
|
|
async getOrganizationUser(
|
|
organizationId: string,
|
|
id: string,
|
|
options?: {
|
|
includeGroups?: boolean;
|
|
},
|
|
): Promise<OrganizationUserDetailsResponse> {
|
|
const params = new URLSearchParams();
|
|
|
|
if (options?.includeGroups) {
|
|
params.set("includeGroups", "true");
|
|
}
|
|
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
`/organizations/${organizationId}/users/${id}?${params.toString()}`,
|
|
null,
|
|
true,
|
|
true,
|
|
);
|
|
return new OrganizationUserDetailsResponse(r);
|
|
}
|
|
|
|
async getOrganizationUserGroups(organizationId: string, id: string): Promise<string[]> {
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
"/organizations/" + organizationId + "/users/" + id + "/groups",
|
|
null,
|
|
true,
|
|
true,
|
|
);
|
|
return r;
|
|
}
|
|
|
|
async getAllUsers(
|
|
organizationId: string,
|
|
options?: {
|
|
includeCollections?: boolean;
|
|
includeGroups?: boolean;
|
|
},
|
|
): Promise<ListResponse<OrganizationUserUserDetailsResponse>> {
|
|
const params = new URLSearchParams();
|
|
|
|
if (options?.includeCollections) {
|
|
params.set("includeCollections", "true");
|
|
}
|
|
if (options?.includeGroups) {
|
|
params.set("includeGroups", "true");
|
|
}
|
|
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
`/organizations/${organizationId}/users?${params.toString()}`,
|
|
null,
|
|
true,
|
|
true,
|
|
);
|
|
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,
|
|
): Promise<OrganizationUserResetPasswordDetailsResponse> {
|
|
const r = await this.apiService.send(
|
|
"GET",
|
|
"/organizations/" + organizationId + "/users/" + id + "/reset-password-details",
|
|
null,
|
|
true,
|
|
true,
|
|
);
|
|
return new OrganizationUserResetPasswordDetailsResponse(r);
|
|
}
|
|
|
|
async getManyOrganizationUserAccountRecoveryDetails(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<ListResponse<OrganizationUserResetPasswordDetailsResponse>> {
|
|
const r = await this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/account-recovery-details",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserResetPasswordDetailsResponse);
|
|
}
|
|
|
|
postOrganizationUserInvite(
|
|
organizationId: string,
|
|
request: OrganizationUserInviteRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/invite",
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
postOrganizationUserReinvite(organizationId: string, id: string): Promise<any> {
|
|
return this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/" + id + "/reinvite",
|
|
null,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
async postManyOrganizationUserReinvite(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
|
const r = await this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/reinvite",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserBulkResponse);
|
|
}
|
|
|
|
postOrganizationUserAcceptInit(
|
|
organizationId: string,
|
|
id: string,
|
|
request: OrganizationUserAcceptInitRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/" + id + "/accept-init",
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
postOrganizationUserAccept(
|
|
organizationId: string,
|
|
id: string,
|
|
request: OrganizationUserAcceptRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/" + id + "/accept",
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
postOrganizationUserConfirm(
|
|
organizationId: string,
|
|
id: string,
|
|
request: OrganizationUserConfirmRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/" + id + "/confirm",
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
async postOrganizationUsersPublicKey(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<ListResponse<OrganizationUserBulkPublicKeyResponse>> {
|
|
const r = await this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/public-keys",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserBulkPublicKeyResponse);
|
|
}
|
|
|
|
async postOrganizationUserBulkConfirm(
|
|
organizationId: string,
|
|
request: OrganizationUserBulkConfirmRequest,
|
|
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
|
const r = await this.apiService.send(
|
|
"POST",
|
|
"/organizations/" + organizationId + "/users/confirm",
|
|
request,
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserBulkResponse);
|
|
}
|
|
|
|
async putOrganizationUserBulkEnableSecretsManager(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<void> {
|
|
await this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/enable-secrets-manager",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
putOrganizationUser(
|
|
organizationId: string,
|
|
id: string,
|
|
request: OrganizationUserUpdateRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/" + id,
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
putOrganizationUserResetPasswordEnrollment(
|
|
organizationId: string,
|
|
userId: string,
|
|
request: OrganizationUserResetPasswordEnrollmentRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/" + userId + "/reset-password-enrollment",
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
putOrganizationUserResetPassword(
|
|
organizationId: string,
|
|
id: string,
|
|
request: OrganizationUserResetPasswordRequest,
|
|
): Promise<void> {
|
|
return this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/" + id + "/reset-password",
|
|
request,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
removeOrganizationUser(organizationId: string, id: string): Promise<any> {
|
|
return this.apiService.send(
|
|
"DELETE",
|
|
"/organizations/" + organizationId + "/users/" + id,
|
|
null,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
async removeManyOrganizationUsers(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
|
const r = await this.apiService.send(
|
|
"DELETE",
|
|
"/organizations/" + organizationId + "/users",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserBulkResponse);
|
|
}
|
|
|
|
revokeOrganizationUser(organizationId: string, id: string): Promise<void> {
|
|
return this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/" + id + "/revoke",
|
|
null,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
async revokeManyOrganizationUsers(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
|
const r = await this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/revoke",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserBulkResponse);
|
|
}
|
|
|
|
restoreOrganizationUser(organizationId: string, id: string): Promise<void> {
|
|
return this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/" + id + "/restore",
|
|
null,
|
|
true,
|
|
false,
|
|
);
|
|
}
|
|
|
|
async restoreManyOrganizationUsers(
|
|
organizationId: string,
|
|
ids: string[],
|
|
): Promise<ListResponse<OrganizationUserBulkResponse>> {
|
|
const r = await this.apiService.send(
|
|
"PUT",
|
|
"/organizations/" + organizationId + "/users/restore",
|
|
new OrganizationUserBulkRequest(ids),
|
|
true,
|
|
true,
|
|
);
|
|
return new ListResponse(r, OrganizationUserBulkResponse);
|
|
}
|
|
}
|