mirror of
https://github.com/bitwarden/browser
synced 2025-12-23 11:43:46 +00:00
* feat: update service container for required service injection, refs AC-1679 * feat: complete approve all command, refs AC-1679 * fix: cast service container to access bit services, refs AC-1679 * fix: override service container from base program, refs AC-1679 * fix: prettier, refs AC-1679 * feat: replace hardcoded strings with i18n translations (future-proofing), refs AC-1679 * chore: remove i18n references, refs AC-1679 * fix: update approve-all and deny-all commands to match desired input, refs AC-1679
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { firstValueFrom } from "rxjs";
|
|
|
|
import { OrganizationAuthRequestService } from "@bitwarden/bit-common/admin-console/auth-requests";
|
|
import { Response } from "@bitwarden/cli/models/response";
|
|
import { MessageResponse } from "@bitwarden/cli/models/response/message.response";
|
|
import { OrganizationService } from "@bitwarden/common/admin-console/services/organization/organization.service";
|
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
|
|
|
export class ApproveAllCommand {
|
|
constructor(
|
|
private organizationAuthRequestService: OrganizationAuthRequestService,
|
|
private organizationService: OrganizationService,
|
|
) {}
|
|
|
|
async run(organizationId: string): Promise<Response> {
|
|
if (organizationId != null) {
|
|
organizationId = organizationId.toLowerCase();
|
|
}
|
|
|
|
if (!Utils.isGuid(organizationId)) {
|
|
return Response.badRequest("`" + organizationId + "` is not a GUID.");
|
|
}
|
|
|
|
const organization = await firstValueFrom(this.organizationService.get$(organizationId));
|
|
if (!organization?.canManageUsersPassword) {
|
|
return Response.error(
|
|
"You do not have permission to approve pending device authorization requests.",
|
|
);
|
|
}
|
|
|
|
try {
|
|
const pendingApprovals =
|
|
await this.organizationAuthRequestService.listPendingRequests(organizationId);
|
|
if (pendingApprovals.length == 0) {
|
|
const res = new MessageResponse(
|
|
"No pending device authorization requests to approve.",
|
|
null,
|
|
);
|
|
return Response.success(res);
|
|
}
|
|
|
|
await this.organizationAuthRequestService.approvePendingRequests(
|
|
organizationId,
|
|
pendingApprovals,
|
|
);
|
|
|
|
return Response.success();
|
|
} catch (e) {
|
|
return Response.error(e);
|
|
}
|
|
}
|
|
}
|