Skip to content

Commit

Permalink
Merge pull request #1807 from betagouv/master
Browse files Browse the repository at this point in the history
MEP [TRELLO-2799] Remove Albert classification for RGPD deletion (#1806)
  • Loading branch information
charlescd authored Dec 17, 2024
2 parents 82d9ed0 + 40efa9c commit 1df48d1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
7 changes: 5 additions & 2 deletions app/loader/SignalConsoApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ class SignalConsoComponents(

val ipBlackListRepository = new IpBlackListRepository(dbConfig)

val albertClassificationRepository = new AlbertClassificationRepository(dbConfig)

val crypter = new JcaCrypter(applicationConfiguration.crypter)
val signer = new JcaSigner(applicationConfiguration.signer)

Expand Down Expand Up @@ -509,7 +511,8 @@ class SignalConsoComponents(
engagementOrchestrator,
reportRepository,
reportFileOrchestrator,
eventRepository
eventRepository,
albertClassificationRepository
)

val reportAdminActionOrchestrator = new ReportAdminActionOrchestrator(
Expand Down Expand Up @@ -720,7 +723,7 @@ class SignalConsoComponents(
companyRepository,
emailNotificationOrchestrator,
ipBlackListRepository,
new AlbertClassificationRepository(dbConfig),
albertClassificationRepository,
albertService,
frontRoute,
cookieAuthenticator,
Expand Down
6 changes: 6 additions & 0 deletions app/models/report/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ case class Report(
// /!\ Some reports don't have description
// in some subcategories, there is no description field (or it's called differently)
details.find(_.label == "Description :").map(_.value.trim).filterNot(_.isEmpty)

def getReponseConsoDescription: Option[String] =
details
.find(x => x.label == "Your question :" || x.label == "Votre question :")
.map(_.value.trim)
.filterNot(_.isEmpty)
}

object Report {
Expand Down
11 changes: 8 additions & 3 deletions app/orchestrators/RgpdOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import models.report.ReportStatus.SuppressionRGPD
import models.report._
import play.api.Logger
import play.api.libs.json.Json
import repositories.albert.AlbertClassificationRepositoryInterface
import repositories.event.EventFilter
import repositories.event.EventRepositoryInterface
import repositories.report.ReportRepositoryInterface
Expand All @@ -20,7 +21,8 @@ class RgpdOrchestrator(
engagementOrchestrator: EngagementOrchestrator,
reportRepository: ReportRepositoryInterface,
reportFileOrchestrator: ReportFileOrchestrator,
eventRepository: EventRepositoryInterface
eventRepository: EventRepositoryInterface,
albertClassificationRepository: AlbertClassificationRepositoryInterface
)(implicit val executionContext: ExecutionContext) {
val logger = Logger(this.getClass)

Expand Down Expand Up @@ -59,8 +61,11 @@ class RgpdOrchestrator(
_ <- reportConsumerReviewOrchestrator.deleteDetails(emptiedReport.id)
_ <- engagementOrchestrator.deleteDetails(emptiedReport.id)
_ <- reportFileOrchestrator.removeFromReportId(emptiedReport.id)
_ = logger.info(s"Report ${report.id} was emptied")
} yield emptiedReport
_ <- albertClassificationRepository.removeByReportId(emptiedReport.id)
} yield {
logger.info(s"Report ${report.id} was emptied")
emptiedReport
}
}

}
9 changes: 7 additions & 2 deletions app/repositories/albert/AlbertClassificationRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.concurrent.Future
trait AlbertClassificationRepositoryInterface {
def getByReportId(reportId: UUID): Future[Option[AlbertClassification]]
def createOrUpdate(element: AlbertClassification): Future[AlbertClassification]
def removeByReportId(reportId: UUID): Future[Int]
}

class AlbertClassificationRepository(dbConfig: DatabaseConfig[JdbcProfile])(implicit ec: ExecutionContext)
Expand All @@ -20,13 +21,17 @@ class AlbertClassificationRepository(dbConfig: DatabaseConfig[JdbcProfile])(impl

import dbConfig._

def getByReportId(reportId: UUID): Future[Option[AlbertClassification]] = db.run(
override def getByReportId(reportId: UUID): Future[Option[AlbertClassification]] = db.run(
table.filter(_.reportId === reportId).result.headOption
)

def createOrUpdate(element: AlbertClassification): Future[AlbertClassification] = db
override def createOrUpdate(element: AlbertClassification): Future[AlbertClassification] = db
.run(
table.insertOrUpdate(element)
)
.map(_ => element)

override def removeByReportId(reportId: UUID): Future[Int] = db.run(
table.filter(_.reportId === reportId).delete
)
}
19 changes: 16 additions & 3 deletions app/services/AlbertService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,25 @@ class AlbertService(albertConfiguration: AlbertConfiguration)(implicit ec: Execu
|""".stripMargin

def classifyReport(report: Report): Future[Option[String]] =
report.getDescription match {
case Some(description) =>
(report.getDescription, report.getReponseConsoDescription) match {
case (Some(description), Some(question)) =>
val text =
s"""$description
|
|Ma question :
|$question""".stripMargin
chatCompletion(chatPrompt(text))
.map(Some(_))
.recover(_ => None)
case (Some(description), None) =>
chatCompletion(chatPrompt(description))
.map(Some(_))
.recover(_ => None)
case None => Future.successful(None)
case (None, Some(question)) =>
chatCompletion(chatPrompt(question))
.map(Some(_))
.recover(_ => None)
case (None, None) => Future.successful(None)
}

def qualifyReportBasedOnCodeConso(report: Report): Future[Option[String]] =
Expand Down
5 changes: 5 additions & 0 deletions conf/db/migration/default/V47__albert_delete_cascade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE albert_classification
DROP CONSTRAINT fk_reportId;

ALTER TABLE albert_classification
ADD CONSTRAINT fk_reportId FOREIGN KEY (report_id) REFERENCES reports(id) ON DELETE CASCADE;

0 comments on commit 1df48d1

Please sign in to comment.