Skip to content

Commit

Permalink
[277] En temps qu'instructeur, je voudrais savoir dans quel Structure…
Browse files Browse the repository at this point in the history
… l'aidant travail. En temps qu'aidant, quand je reçois une réponse d'un instructeur, je ne sais pas pour quel organisme, il travaille. (#431)
  • Loading branch information
Lucien Pereira authored Jan 29, 2020
1 parent cbed6df commit 0e4557f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
14 changes: 7 additions & 7 deletions app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ case class ApplicationController @Inject()(loginAction: LoginAction,
},
applicationData => {
val invitedUsers: Map[UUID, String] = applicationData.users.flatMap { id =>
userService.byId(id).map(id -> _.nameWithQualite)
userService.byId(id).map(user => id -> userGroupService.contextualizedUserName(user))
}.toMap

val application = Application(applicationId,
DateTime.now(timeZone),
request.currentUser.nameWithQualite,
userGroupService.contextualizedUserName(request.currentUser),
request.currentUser.id,
applicationData.subject,
applicationData.description,
Expand Down Expand Up @@ -401,7 +401,7 @@ case class ApplicationController @Inject()(loginAction: LoginAction,
applicationId, DateTime.now(timeZone),
answerData.message,
request.currentUser.id,
request.currentUser.nameWithQualite,
userGroupService.contextualizedUserName(request.currentUser),
Map(),
answerData.privateToHelpers == false,
answerData.applicationIsDeclaredIrrelevant,
Expand Down Expand Up @@ -440,14 +440,14 @@ case class ApplicationController @Inject()(loginAction: LoginAction,
val usersThatCanBeInvited = usersThatCanBeInvitedOn(application)
val invitedUsers: Map[UUID, String] = usersThatCanBeInvited
.filter(user => inviteData.invitedUsers.contains(user.id))
.map(user => (user.id,user.nameWithQualite)).toMap
.map(user => (user.id,userGroupService.contextualizedUserName(user))).toMap

val answer = Answer(UUID.randomUUID(),
applicationId,
DateTime.now(timeZone),
inviteData.message,
request.currentUser.id,
request.currentUser.nameWithQualite,
userGroupService.contextualizedUserName(request.currentUser),
invitedUsers,
not(inviteData.privateToHelpers),
false,
Expand All @@ -471,13 +471,13 @@ case class ApplicationController @Inject()(loginAction: LoginAction,
NotFound("Nous n'avons pas trouvé cette demande")
case Some(application) =>
if(application.canHaveExpertsInvitedBy(request.currentUser)) {
val experts: Map[UUID, String] = User.admins.filter(_.expert).map(user => user.id -> user.nameWithQualite).toMap
val experts: Map[UUID, String] = User.admins.filter(_.expert).map(user => user.id -> userGroupService.contextualizedUserName(user)).toMap
val answer = Answer(UUID.randomUUID(),
applicationId,
DateTime.now(timeZone),
"J'ajoute un expert",
request.currentUser.id,
request.currentUser.nameWithQualite,
userGroupService.contextualizedUserName(request.currentUser),
experts,
true,
false,
Expand Down
3 changes: 2 additions & 1 deletion app/models/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ case class User(id: UUID,
cguAcceptationDate: Option[DateTime] = None,
newsletterAcceptationDate: Option[DateTime] = None,
phoneNumber: Option[String] = None) extends AgeModel {

def nameWithQualite = s"$name ( $qualite )"

def canBeEditedBy(user: User): Boolean =
user.admin && user.areas.intersect(user.areas).nonEmpty

Expand Down
2 changes: 1 addition & 1 deletion app/services/EventService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EventService @Inject()(db: Database) {
UUID.randomUUID(),
level,
code,
currentUser.nameWithQualite,
currentUser.name,
currentUser.id,
DateTime.now(Time.dateTimeZone),
description,
Expand Down
18 changes: 17 additions & 1 deletion app/services/UserGroupService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.UUID
import anorm._
import extentions.{Hash, Time, UUIDHelper}
import javax.inject.Inject
import models.{User, UserGroup}
import models.{Area, User, UserGroup}
import play.api.db.Database
import anorm.JodaParameterMetaData._
import org.postgresql.util.PSQLException
Expand Down Expand Up @@ -109,4 +109,20 @@ class UserGroupService @Inject()(configuration: play.api.Configuration, db: Data
})
cardinality == 0
}

def contextualizedUserName(user: User): String = {
val groups = byIds(user.groupIds)
val contexts = groups.flatMap({ userGroup: UserGroup =>
for {
areaInseeCode <- userGroup.areaIds.flatMap(Area.fromId).map(_.inseeCode).headOption
organisation <- userGroup.organisation
} yield {
s"($organisation - $areaInseeCode)"
}
})
if (contexts.isEmpty)
s"${user.name} ( ${user.qualite} )"
else
s"${user.name} ${contexts.mkString(",")}"
}
}
9 changes: 5 additions & 4 deletions app/tasks/AutoAddExpertTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import extentions.Time
import javax.inject.Inject
import models._
import org.joda.time.{DateTime, Period}
import services.{ApplicationService, EventService, NotificationService}
import services.{ApplicationService, EventService, NotificationService, UserGroupService}

import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
Expand All @@ -16,7 +16,8 @@ import scala.concurrent.ExecutionContext
class AutoAddExpertTask @Inject()(actorSystem: ActorSystem,
applicationService: ApplicationService,
eventService: EventService,
notificationService: NotificationService)(implicit executionContext: ExecutionContext) {
notificationService: NotificationService,
userGroupService: UserGroupService)(implicit executionContext: ExecutionContext) {

val startAtHour = 8
val startDate = Time.now().withTimeAtStartOfDay().plusDays(1).withHourOfDay(startAtHour)
Expand All @@ -42,7 +43,7 @@ class AutoAddExpertTask @Inject()(actorSystem: ActorSystem,

private def inviteExpert(application: Application, days: Int): Unit = {
val expertUsers = User.admins.filter(_.expert)
val experts = expertUsers.map(user => user.id -> user.nameWithQualite).toMap
val experts = expertUsers.map(user => user.id -> userGroupService.contextualizedUserName(user)).toMap

expertUsers.headOption match {
case Some(expert) =>
Expand All @@ -51,7 +52,7 @@ class AutoAddExpertTask @Inject()(actorSystem: ActorSystem,
Time.now(),
s"Je rejoins la conversation automatiquement comme expert(e) car le dernier message a plus de $days jours",
expert.id,
expert.nameWithQualite,
userGroupService.contextualizedUserName(expert),
experts,
true,
false,
Expand Down
4 changes: 2 additions & 2 deletions test/browser/ApplicationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class ApplicationSpec extends Specification with Tables with BaseSpec {
application.userInfos("Date de naissance") mustEqual birthDate
application.description mustEqual description
application.creatorUserId mustEqual helperUser.id
application.creatorUserName mustEqual helperUser.nameWithQualite
application.invitedUsers mustEqual Map(instructorUser.id -> instructorUser.nameWithQualite)
application.creatorUserName mustEqual groupService.contextualizedUserName(helperUser)
application.invitedUsers mustEqual Map(instructorUser.id -> groupService.contextualizedUserName(instructorUser))
}
}
}

0 comments on commit 0e4557f

Please sign in to comment.