-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AC-2632] Device approvals ListCommand (#9389)
- Loading branch information
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 35 additions & 2 deletions
37
bitwarden_license/bit-cli/src/admin-console/device-approval/list.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
bitwarden_license/bit-cli/src/admin-console/device-approval/pending-auth-request.response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PendingAuthRequestView } from "@bitwarden/bit-common/admin-console/auth-requests/"; | ||
import { BaseResponse } from "@bitwarden/cli/models/response/base.response"; | ||
|
||
export class PendingAuthRequestResponse implements BaseResponse { | ||
object = "auth-request"; | ||
|
||
id: string; | ||
userId: string; | ||
organizationUserId: string; | ||
email: string; | ||
requestDeviceIdentifier: string; | ||
requestDeviceType: string; | ||
requestIpAddress: string; | ||
creationDate: Date; | ||
|
||
constructor(authRequest: PendingAuthRequestView) { | ||
this.id = authRequest.id; | ||
this.userId = authRequest.userId; | ||
this.organizationUserId = authRequest.organizationUserId; | ||
this.email = authRequest.email; | ||
this.requestDeviceIdentifier = authRequest.requestDeviceIdentifier; | ||
this.requestDeviceType = authRequest.requestDeviceType; | ||
this.requestIpAddress = authRequest.requestIpAddress; | ||
this.creationDate = authRequest.creationDate; | ||
} | ||
} |