Skip to content

Commit

Permalink
Corrige le status des demandes des nouveaux instructeurs (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic authored Feb 5, 2024
1 parent ee5f023 commit 046c4a6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
20 changes: 6 additions & 14 deletions app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,16 @@ case class ApplicationController @Inject() (
): Future[List[Application]] =
(user.admin, areaOption) match {
case (true, None) =>
applicationService.allForAreas(user.areas, numOfMonthsDisplayed.some)
applicationService.allForAreas(user.areas, numOfMonthsDisplayed.some, false)
case (true, Some(area)) =>
applicationService.allForAreas(List(area.id), numOfMonthsDisplayed.some)
applicationService.allForAreas(List(area.id), numOfMonthsDisplayed.some, false)
case (false, None) if user.groupAdmin =>
val userIds = userService.byGroupIds(user.groupIds, includeDisabled = true).map(_.id)
applicationService.allForUserIds(userIds, numOfMonthsDisplayed.some)
applicationService.allForUserIds(userIds, numOfMonthsDisplayed.some, false)
case (false, Some(area)) if user.groupAdmin =>
val userIds = userService.byGroupIds(user.groupIds, includeDisabled = true).map(_.id)
applicationService
.allForUserIds(userIds, numOfMonthsDisplayed.some)
.allForUserIds(userIds, numOfMonthsDisplayed.some, false)
.map(_.filter(application => application.area === area.id))
case _ =>
Future.successful(Nil)
Expand Down Expand Up @@ -509,13 +509,8 @@ case class ApplicationController @Inject() (
private def applicationIsLate(application: Application): Boolean =
!application.closed &&
application.status =!= Application.Status.Processed && (
application.answers
application.userAnswers
.filter(_.creatorUserID =!= application.creatorUserId)
.filter(answer =>
!answer.message.contains("rejoins la conversation automatiquement comme expert") &&
!answer.message
.contains("Les nouveaux instructeurs rejoignent automatiquement la demande")
)
.lastOption match {
case None =>
businessDaysService
Expand Down Expand Up @@ -598,10 +593,7 @@ case class ApplicationController @Inject() (

val interactedApplications = openFilteredByGroups.filter { application =>
application.creatorUserId === user.id ||
application.answers.exists(answer =>
answer.creatorUserID === user.id && !answer.message
.contains("Les nouveaux instructeurs rejoignent automatiquement la demande")
)
application.userAnswers.exists(answer => answer.creatorUserID === user.id)
}
val interactedApplicationsCount = interactedApplications.length

Expand Down
9 changes: 8 additions & 1 deletion app/models/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ case class Application(
answersStripped
}

private def isProcessed = answers.lastOption.exists(_.answerType === ApplicationProcessed)
def userAnswers = answers.filter(answer =>
!answer.message.contains("rejoins la conversation automatiquement comme expert") &&
!answer.message
.contains("Les nouveaux instructeurs rejoignent automatiquement la demande") &&
!answer.message.contains("Les nouveaux instructeurs ont automatiquement accès à la demande")
)

private def isProcessed = userAnswers.lastOption.exists(_.answerType === ApplicationProcessed)
private def isCreator(userId: UUID) = userId === creatorUserId

def hasBeenDisplayedFor(userId: UUID) =
Expand Down
27 changes: 21 additions & 6 deletions app/services/ApplicationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,15 @@ class ApplicationService @Inject() (
)
.orEmpty

def allForUserIds(userIds: List[UUID], numOfMonths: Option[Int]): Future[List[Application]] =
def allForUserIds(
userIds: List[UUID],
numOfMonths: Option[Int],
anonymous: Boolean = true
): Future[List[Application]] =
Future {
db.withConnection { implicit connection =>
val additionalFilter = monthsFilter(numOfMonths)
SQL(
val result = SQL(
s"""SELECT $fieldsInSelect
FROM application
WHERE
Expand All @@ -240,7 +244,10 @@ class ApplicationService @Inject() (
ORDER BY creation_date DESC"""
).on("userIds" -> userIds)
.as(simpleApplication.*)
.map(_.anonymousApplication)
if (anonymous)
result.map(_.anonymousApplication)
else
result
}
}

Expand All @@ -261,18 +268,26 @@ class ApplicationService @Inject() (
}
}

def allForAreas(areaIds: List[UUID], numOfMonths: Option[Int]): Future[List[Application]] =
def allForAreas(
areaIds: List[UUID],
numOfMonths: Option[Int],
anonymous: Boolean = true
): Future[List[Application]] =
Future {
db.withConnection { implicit connection =>
val additionalFilter = monthsFilter(numOfMonths)
SQL(s"""SELECT $fieldsInSelect
val result = SQL(s"""SELECT $fieldsInSelect
FROM application
WHERE ARRAY[{areaIds}]::uuid[] @> ARRAY[area]::uuid[]
$additionalFilter
ORDER BY creation_date DESC""")
.on("areaIds" -> areaIds)
.as(simpleApplication.*)
.map(_.anonymousApplication)
if (anonymous) {
result.map(_.anonymousApplication)
} else {
result
}
}
}

Expand Down

0 comments on commit 046c4a6

Please sign in to comment.