mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 03:03:43 +00:00
[AC-2632] Device approvals ListCommand (#9389)
This commit is contained in:
@@ -1,9 +1,42 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { OrganizationAuthRequestService } from "@bitwarden/bit-common/admin-console/auth-requests";
|
||||
import { Response } from "@bitwarden/cli/models/response";
|
||||
import { ListResponse } from "@bitwarden/cli/models/response/list.response";
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
|
||||
import { PendingAuthRequestResponse } from "./pending-auth-request.response";
|
||||
|
||||
export class ListCommand {
|
||||
constructor() {}
|
||||
constructor(
|
||||
private organizationAuthRequestService: OrganizationAuthRequestService,
|
||||
private organizationService: OrganizationService,
|
||||
) {}
|
||||
|
||||
async run(organizationId: 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.");
|
||||
}
|
||||
|
||||
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 requests =
|
||||
await this.organizationAuthRequestService.listPendingRequests(organizationId);
|
||||
const res = new ListResponse(requests.map((r) => new PendingAuthRequestResponse(r)));
|
||||
return Response.success(res);
|
||||
} catch (e) {
|
||||
return Response.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user