Añadir endpoint de campos para Gestiona y adaptar login GlobalLeaks a DPoP
- Añade GET /api/denuncias/{id}/gestiona-fields para exponer los campos diarios requeridos por la integración con Gestiona.
- Devuelve un DTO cerrado con fecha, canal, resumen, datos de hechos, protección, sexo y preferencias de notificación.
- Adapta el login contra GlobalLeaks al nuevo flujo DPoP exigido desde la versión 5.0.94.
- Genera proof DPoP con clave EC P-256 efímera y lo envía en la cabecera DPoP junto a X-Token.
- Mejora el mensaje de error cuando GlobalLeaks rechaza el proof DPoP.
This commit is contained in:
@@ -262,6 +262,106 @@ public sealed class InboxTrackingService : IInboxTrackingService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MarkReportHandledInGestionaAsync(
|
||||
string username,
|
||||
int denunciaId,
|
||||
DateTime uploadedAtUtc,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _denunciaStore.EnsureSchemaAsync(cancellationToken);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(username) || denunciaId <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var handledAtUtc = uploadedAtUtc.Kind switch
|
||||
{
|
||||
DateTimeKind.Utc => uploadedAtUtc,
|
||||
DateTimeKind.Local => uploadedAtUtc.ToUniversalTime(),
|
||||
_ => DateTime.SpecifyKind(uploadedAtUtc, DateTimeKind.Utc)
|
||||
};
|
||||
|
||||
await using var connection = await OpenConnectionAsync(cancellationToken);
|
||||
var userId = await EnsureUserAsync(connection, username, cancellationToken);
|
||||
await using var transaction = await connection.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
const string updateInboxSql = """
|
||||
UPDATE inbox_reports
|
||||
SET
|
||||
last_downloaded_at_utc =
|
||||
CASE
|
||||
WHEN last_downloaded_at_utc IS NULL THEN @handledAtUtc
|
||||
WHEN @handledAtUtc > last_downloaded_at_utc THEN @handledAtUtc
|
||||
ELSE last_downloaded_at_utc
|
||||
END,
|
||||
last_downloaded_by_user_id = @userId,
|
||||
imported_complaint_report_id = COALESCE(imported_complaint_report_id, @denunciaId),
|
||||
imported_to_store_at_utc = COALESCE(imported_to_store_at_utc, @handledAtUtc),
|
||||
updated_at_utc = CURRENT_TIMESTAMP(6)
|
||||
WHERE progressive_id = @denunciaId
|
||||
OR imported_complaint_report_id = @denunciaId;
|
||||
""";
|
||||
|
||||
await using (var updateInbox = new MySqlCommand(updateInboxSql, connection, (MySqlTransaction)transaction))
|
||||
{
|
||||
updateInbox.Parameters.AddWithValue("@handledAtUtc", handledAtUtc);
|
||||
updateInbox.Parameters.AddWithValue("@userId", userId);
|
||||
updateInbox.Parameters.AddWithValue("@denunciaId", denunciaId);
|
||||
await updateInbox.ExecuteNonQueryAsync(cancellationToken);
|
||||
}
|
||||
|
||||
const string updateUserReportSql = """
|
||||
INSERT INTO user_inbox_reports (
|
||||
app_user_id,
|
||||
inbox_report_id,
|
||||
first_seen_at_utc,
|
||||
last_seen_at_utc,
|
||||
first_downloaded_at_utc,
|
||||
last_downloaded_at_utc,
|
||||
download_count
|
||||
)
|
||||
SELECT
|
||||
@userId,
|
||||
ir.id,
|
||||
CURRENT_TIMESTAMP(6),
|
||||
CURRENT_TIMESTAMP(6),
|
||||
@handledAtUtc,
|
||||
@handledAtUtc,
|
||||
1
|
||||
FROM inbox_reports ir
|
||||
WHERE ir.progressive_id = @denunciaId
|
||||
OR ir.imported_complaint_report_id = @denunciaId
|
||||
ON DUPLICATE KEY UPDATE
|
||||
last_seen_at_utc = CURRENT_TIMESTAMP(6),
|
||||
first_downloaded_at_utc = COALESCE(first_downloaded_at_utc, VALUES(first_downloaded_at_utc)),
|
||||
last_downloaded_at_utc =
|
||||
CASE
|
||||
WHEN last_downloaded_at_utc IS NULL THEN VALUES(last_downloaded_at_utc)
|
||||
WHEN VALUES(last_downloaded_at_utc) > last_downloaded_at_utc THEN VALUES(last_downloaded_at_utc)
|
||||
ELSE last_downloaded_at_utc
|
||||
END;
|
||||
""";
|
||||
|
||||
await using (var updateUserReport = new MySqlCommand(updateUserReportSql, connection, (MySqlTransaction)transaction))
|
||||
{
|
||||
updateUserReport.Parameters.AddWithValue("@userId", userId);
|
||||
updateUserReport.Parameters.AddWithValue("@handledAtUtc", handledAtUtc);
|
||||
updateUserReport.Parameters.AddWithValue("@denunciaId", denunciaId);
|
||||
await updateUserReport.ExecuteNonQueryAsync(cancellationToken);
|
||||
}
|
||||
|
||||
await transaction.CommitAsync(cancellationToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await SafeRollbackAsync(transaction, cancellationToken);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<long> EnsureUserAsync(MySqlConnection connection, string username, CancellationToken cancellationToken)
|
||||
{
|
||||
const string insertSql = """
|
||||
|
||||
Reference in New Issue
Block a user