1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00
Files
browser/bitwarden_license/bit-web/src/app/dirt/access-intelligence/shared/security-tasks.service.ts
Leslie Tilton ec07a5391a [PM-27762] Activity Tab - Password Change Progress - Assign tasks for new passwords (#17268)
* Update type guard for cipher ids on reports

* Update report model cipher id type and mock data

* Update security tasks api service to have copied getAllTasks function from the vault team

* Expose critical application at risk cipher ids

* Update cipher id type in report service. Update all activities service to move task function to task service

* Update module

* Update organization id sharing through components instead of multiple route fetchings

* Update view type of password change widget. Update variables to be signals. Refactor logic for calculations based on individual tasks

* Update usage of request password change function

* Update security tasks service to manage tasks

* Remove unused variable

* Alphabetized functions, added documentation. Removed injectable decorator

* Alphabetize constructor params for password health service

* Update providers

* Address NaN case on percentage. Address obsolete type casting to CipherID and any other claude comments

* Fix dependency array in test case
2025-11-07 12:04:05 -06:00

64 lines
2.3 KiB
TypeScript

import { BehaviorSubject } from "rxjs";
import { SecurityTasksApiService } from "@bitwarden/bit-common/dirt/reports/risk-insights";
import { CipherId, OrganizationId } from "@bitwarden/common/types/guid";
import { SecurityTask, SecurityTaskType } from "@bitwarden/common/vault/tasks";
import { CreateTasksRequest } from "../../../vault/services/abstractions/admin-task.abstraction";
import { DefaultAdminTaskService } from "../../../vault/services/default-admin-task.service";
/**
* Service for managing security tasks related to Access Intelligence features
*/
export class AccessIntelligenceSecurityTasksService {
private _tasksSubject$ = new BehaviorSubject<SecurityTask[]>([]);
tasks$ = this._tasksSubject$.asObservable();
constructor(
private adminTaskService: DefaultAdminTaskService,
private securityTasksApiService: SecurityTasksApiService,
) {}
/**
* Gets security task metrics for the given organization
*
* @param organizationId The organization ID
* @returns Metrics about security tasks such as a count of completed and total tasks
*/
getTaskMetrics(organizationId: OrganizationId) {
return this.securityTasksApiService.getTaskMetrics(organizationId);
}
/**
* Loads security tasks for the given organization and updates the internal tasks subject
*
* @param organizationId The organization ID
*/
async loadTasks(organizationId: OrganizationId): Promise<void> {
// Loads the tasks to update the service
const tasks = await this.securityTasksApiService.getAllTasks(organizationId);
this._tasksSubject$.next(tasks);
}
/**
* Bulk assigns password change tasks for critical applications with at-risk passwords
*
* @param organizationId The organization ID
* @param criticalApplicationIds IDs of critical applications with at-risk passwords
*/
async requestPasswordChangeForCriticalApplications(
organizationId: OrganizationId,
criticalApplicationIds: CipherId[],
) {
const distinctCipherIds = Array.from(new Set(criticalApplicationIds));
const tasks: CreateTasksRequest[] = distinctCipherIds.map((cipherId) => ({
cipherId,
type: SecurityTaskType.UpdateAtRiskCredential,
}));
await this.adminTaskService.bulkCreateTasks(organizationId, tasks);
// Reload tasks after creation
await this.loadTasks(organizationId);
}
}