From 00801f95cec7b5dca8cbee0f0b59752f5d5021ff Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 26 Jun 2024 05:54:38 +1000 Subject: [PATCH] CLI device approvals - Use single deny endpoint (#9763) --- .../admin-console/device-approval/approve.command.ts | 2 +- .../admin-console/device-approval/deny.command.ts | 12 +++++++++--- .../organization-auth-request-api.service.ts | 10 ++++++++++ .../organization-auth-request.service.ts | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bitwarden_license/bit-cli/src/admin-console/device-approval/approve.command.ts b/bitwarden_license/bit-cli/src/admin-console/device-approval/approve.command.ts index 918bd077b05..dc6a6d8e906 100644 --- a/bitwarden_license/bit-cli/src/admin-console/device-approval/approve.command.ts +++ b/bitwarden_license/bit-cli/src/admin-console/device-approval/approve.command.ts @@ -43,7 +43,7 @@ export class ApproveCommand { const request = pendingRequests.find((r) => r.id == id); if (request == null) { - return Response.error("Invalid request id"); + return Response.error("The request id is invalid."); } await this.organizationAuthRequestService.approvePendingRequest(organizationId, request); diff --git a/bitwarden_license/bit-cli/src/admin-console/device-approval/deny.command.ts b/bitwarden_license/bit-cli/src/admin-console/device-approval/deny.command.ts index 3470baaa25e..cf2356b1950 100644 --- a/bitwarden_license/bit-cli/src/admin-console/device-approval/deny.command.ts +++ b/bitwarden_license/bit-cli/src/admin-console/device-approval/deny.command.ts @@ -38,10 +38,16 @@ export class DenyCommand { } try { - await this.organizationAuthRequestService.denyPendingRequests(organizationId, id); + await this.organizationAuthRequestService.denyPendingRequest(organizationId, id); return Response.success(); - } catch (e) { - return Response.error(e); + } catch (error) { + if (error?.statusCode === 404) { + return Response.error( + "The request id is invalid or you do not have permission to update it.", + ); + } + + return Response.error(error); } } diff --git a/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request-api.service.ts b/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request-api.service.ts index 3387b7d54ed..4995df79922 100644 --- a/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request-api.service.ts +++ b/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request-api.service.ts @@ -61,4 +61,14 @@ export class OrganizationAuthRequestApiService { false, ); } + + async denyPendingRequest(organizationId: string, requestId: string): Promise { + await this.apiService.send( + "POST", + `/organizations/${organizationId}/auth-requests/${requestId}`, + new AdminAuthRequestUpdateRequest(false), + true, + false, + ); + } } diff --git a/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request.service.ts b/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request.service.ts index c35b91396d0..245baf7e722 100644 --- a/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request.service.ts +++ b/bitwarden_license/bit-common/src/admin-console/auth-requests/organization-auth-request.service.ts @@ -85,6 +85,10 @@ export class OrganizationAuthRequestService { ); } + async denyPendingRequest(organizationId: string, requestId: string) { + await this.organizationAuthRequestApiService.denyPendingRequest(organizationId, requestId); + } + /** * Creates a copy of the user key that has been encrypted with the provided device's public key. * @param organizationId