Skip to content

Commit

Permalink
TRELLO-2726 : reopen report in mass (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssedoudbgouv authored Jan 6, 2025
1 parent e340517 commit b1b3055
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
9 changes: 5 additions & 4 deletions app/controllers/ReportController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ class ReportController(
} yield Ok(Json.toJson(deleted))
}

def reopenReport(uuid: UUID) =
SecuredAction.andThen(WithRole(UserRole.Admins)).async(parse.empty) { request =>
def reopenReport() =
SecuredAction.andThen(WithRole(UserRole.Admins)).async(parse.json) { request =>
for {
_ <- reportAdminActionOrchestrator.reportReOpening(
uuid,
reportsIds <- request.parseBody[List[UUID]]()
_ <- reportAdminActionOrchestrator.reportsReOpening(
reportsIds,
request.identity
)
} yield NoContent
Expand Down
17 changes: 12 additions & 5 deletions app/orchestrators/ReportAdminActionOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,23 @@ class ReportAdminActionOrchestrator(
private def fetchStrict(reportId: UUID): Future[Report] =
reportRepository.get(reportId).flatMap(_.liftTo[Future](AppError.ReportNotFound(reportId)))

def reportReOpening(reportId: UUID, user: User): Future[Unit] =
def reportsReOpening(reportIds: List[UUID], user: User): Future[Unit] =
for {
reports <- reportRepository.getReportsByIds(reportIds.toSet.toList)
isReopenable = reports.filterNot(report =>
report.status === ReportStatus.NonConsulte || report.status === ReportStatus.ConsulteIgnore
)
_ <- if (isReopenable.isEmpty) Future.unit else throw CannotReopenReport
_ <- reports.traverse(reportsReOpening(_, user))
} yield ()

private def reportsReOpening(report: Report, user: User): Future[Unit] =
for {
report <- fetchStrict(reportId)
isReopenable = report.status === ReportStatus.NonConsulte || report.status === ReportStatus.ConsulteIgnore
_ <- if (isReopenable) Future.unit else throw CannotReopenReport
updatedReport <- reOpenReport(report)
_ <- eventRepository.create(
Event(
UUID.randomUUID(),
Some(reportId),
Some(updatedReport.id),
report.companyId,
Some(user.id),
OffsetDateTime.now(),
Expand Down
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ POST /api/reports/files/list controller
GET /api/reports/download controllers.ReportController.reportsAsPDF()
GET /api/reports/download-with-attachments/:reportId controllers.ReportController.reportAsZip(reportId: java.util.UUID)
GET /api/reports/cloudword/:companyId controllers.ReportController.cloudWord(companyId: java.util.UUID)
POST /api/reports/:uuid/reopen controllers.ReportController.reopenReport(uuid: java.util.UUID)
POST /api/reports/reopen controllers.ReportController.reopenReport()
GET /api/reports/:uuid controllers.ReportController.getReport(uuid: java.util.UUID)
DELETE /api/reports/:uuid controllers.ReportController.deleteReport(uuid: java.util.UUID)
DELETE /api/reports controllers.ReportController.deleteSpamReport()
Expand Down

0 comments on commit b1b3055

Please sign in to comment.