[AC-2634] Add device-approvals approve command (#9476)
This commit is contained in:
parent
edecec56de
commit
e99fd44eed
|
@ -1,9 +1,54 @@
|
||||||
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { Response } from "@bitwarden/cli/models/response";
|
import { Response } from "@bitwarden/cli/models/response";
|
||||||
|
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||||
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
|
|
||||||
|
import { OrganizationAuthRequestService } from "../../../../bit-common/src/admin-console/auth-requests";
|
||||||
|
|
||||||
export class ApproveCommand {
|
export class ApproveCommand {
|
||||||
constructor() {}
|
constructor(
|
||||||
|
private organizationService: OrganizationService,
|
||||||
|
private organizationAuthRequestService: OrganizationAuthRequestService,
|
||||||
|
) {}
|
||||||
|
|
||||||
async run(id: string): Promise<Response> {
|
async run(organizationId: string, id: string): Promise<Response> {
|
||||||
throw new Error("Not implemented");
|
if (organizationId != null) {
|
||||||
|
organizationId = organizationId.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils.isGuid(organizationId)) {
|
||||||
|
return Response.badRequest("`" + organizationId + "` is not a GUID.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != null) {
|
||||||
|
id = id.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utils.isGuid(id)) {
|
||||||
|
return Response.badRequest("`" + id + "` 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 pendingRequests =
|
||||||
|
await this.organizationAuthRequestService.listPendingRequests(organizationId);
|
||||||
|
|
||||||
|
const request = pendingRequests.find((r) => r.id == id);
|
||||||
|
if (request == null) {
|
||||||
|
return Response.error("Invalid request id");
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.organizationAuthRequestService.approvePendingRequest(organizationId, request);
|
||||||
|
return Response.success();
|
||||||
|
} catch (e) {
|
||||||
|
return Response.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,14 +49,18 @@ export class DeviceApprovalProgram extends BaseProgram {
|
||||||
|
|
||||||
private approveCommand(): Command {
|
private approveCommand(): Command {
|
||||||
return new Command("approve")
|
return new Command("approve")
|
||||||
.argument("<id>")
|
.argument("<organizationId>", "The id of the organization")
|
||||||
|
.argument("<requestId>", "The id of the request to approve")
|
||||||
.description("Approve a pending request")
|
.description("Approve a pending request")
|
||||||
.action(async (id: string) => {
|
.action(async (organizationId: string, id: string) => {
|
||||||
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
await this.exitIfFeatureFlagDisabled(FeatureFlag.BulkDeviceApproval);
|
||||||
await this.exitIfLocked();
|
await this.exitIfLocked();
|
||||||
|
|
||||||
const cmd = new ApproveCommand();
|
const cmd = new ApproveCommand(
|
||||||
const response = await cmd.run(id);
|
this.serviceContainer.organizationService,
|
||||||
|
this.serviceContainer.organizationAuthRequestService,
|
||||||
|
);
|
||||||
|
const response = await cmd.run(organizationId, id);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue