mirror of
https://github.com/bitwarden/server
synced 2026-01-10 12:33:49 +00:00
[PM-23580] Security Task Metrics (#6164)
* add metrics endpoint for an organization to return completed and total security tasks * refactor metrics fetch to use sql sproc for efficiency rather than having to pull all security task data * add separate response model for security task metrics endpoint * Pascal Case to match existing implementations * refactor org to organization for consistency with other methods * alter security task endpoint: - remove "count" from variable naming - update sproc naming * remove enablement check * replace orgId with organizationId
This commit is contained in:
@@ -76,4 +76,24 @@ public class SecurityTaskRepository : Repository<Core.Vault.Entities.SecurityTas
|
||||
|
||||
return tasksList;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Core.Vault.Entities.SecurityTaskMetrics> GetTaskMetricsAsync(Guid organizationId)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var metrics = await (from st in dbContext.SecurityTasks
|
||||
join o in dbContext.Organizations on st.OrganizationId equals o.Id
|
||||
where st.OrganizationId == organizationId && o.Enabled
|
||||
select st)
|
||||
.GroupBy(x => 1)
|
||||
.Select(g => new Core.Vault.Entities.SecurityTaskMetrics(
|
||||
g.Count(x => x.Status == SecurityTaskStatus.Completed),
|
||||
g.Count()
|
||||
))
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return metrics ?? new Core.Vault.Entities.SecurityTaskMetrics(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user