-
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-1679] Approve all pending device authorizations (#9407)
* 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
- Loading branch information
1 parent
3835a9d
commit 2358443
Showing
5 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
47 changes: 45 additions & 2 deletions
47
bitwarden_license/bit-cli/src/admin-console/device-approval/approve-all.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,52 @@ | ||
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() {} | ||
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 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); | ||
} | ||
} | ||
} |
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
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,7 +1,24 @@ | ||
import { | ||
OrganizationAuthRequestService, | ||
OrganizationAuthRequestApiService, | ||
} from "@bitwarden/bit-common/admin-console/auth-requests"; | ||
import { ServiceContainer as OssServiceContainer } from "@bitwarden/cli/service-container"; | ||
|
||
/** | ||
* Instantiates services and makes them available for dependency injection. | ||
* Any Bitwarden-licensed services should be registered here. | ||
*/ | ||
export class ServiceContainer extends OssServiceContainer {} | ||
export class ServiceContainer extends OssServiceContainer { | ||
organizationAuthRequestApiService: OrganizationAuthRequestApiService; | ||
organizationAuthRequestService: OrganizationAuthRequestService; | ||
|
||
constructor() { | ||
super(); | ||
this.organizationAuthRequestApiService = new OrganizationAuthRequestApiService(this.apiService); | ||
this.organizationAuthRequestService = new OrganizationAuthRequestService( | ||
this.organizationAuthRequestApiService, | ||
this.cryptoService, | ||
this.organizationUserService, | ||
); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
bitwarden_license/bit-common/src/admin-console/auth-requests/index.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,2 +1,4 @@ | ||
export * from "./pending-organization-auth-request.response"; | ||
export * from "./organization-auth-request.service"; | ||
export * from "./organization-auth-request-api.service"; | ||
export * from "./pending-auth-request.view"; |