From 0e4557fd164d2f78f7b0c48e21b3be39d2443913 Mon Sep 17 00:00:00 2001 From: Lucien Pereira Date: Wed, 29 Jan 2020 11:37:16 +0100 Subject: [PATCH] =?UTF-8?q?[277]=20En=20temps=20qu'instructeur,=20je=20vou?= =?UTF-8?q?drais=20savoir=20dans=20quel=20Structure=20l'aidant=20travail.?= =?UTF-8?q?=20En=20temps=20qu'aidant,=20quand=20je=20re=C3=A7ois=20une=20r?= =?UTF-8?q?=C3=A9ponse=20d'un=20instructeur,=20je=20ne=20sais=20pas=20pour?= =?UTF-8?q?=20quel=20organisme,=20il=20travaille.=20(#431)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ApplicationController.scala | 14 +++++++------- app/models/User.scala | 3 ++- app/services/EventService.scala | 2 +- app/services/UserGroupService.scala | 18 +++++++++++++++++- app/tasks/AutoAddExpertTask.scala | 9 +++++---- test/browser/ApplicationSpec.scala | 4 ++-- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/controllers/ApplicationController.scala b/app/controllers/ApplicationController.scala index a9993d4f2..3c69b7c1b 100644 --- a/app/controllers/ApplicationController.scala +++ b/app/controllers/ApplicationController.scala @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/app/models/User.scala b/app/models/User.scala index c09935ac8..9dd93f843 100644 --- a/app/models/User.scala +++ b/app/models/User.scala @@ -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 diff --git a/app/services/EventService.scala b/app/services/EventService.scala index dfe6cea8f..9ab1aae72 100644 --- a/app/services/EventService.scala +++ b/app/services/EventService.scala @@ -42,7 +42,7 @@ class EventService @Inject()(db: Database) { UUID.randomUUID(), level, code, - currentUser.nameWithQualite, + currentUser.name, currentUser.id, DateTime.now(Time.dateTimeZone), description, diff --git a/app/services/UserGroupService.scala b/app/services/UserGroupService.scala index 095b426b4..af48835da 100644 --- a/app/services/UserGroupService.scala +++ b/app/services/UserGroupService.scala @@ -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 @@ -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(",")}" + } } \ No newline at end of file diff --git a/app/tasks/AutoAddExpertTask.scala b/app/tasks/AutoAddExpertTask.scala index 234d89f1f..fcbbfad0e 100644 --- a/app/tasks/AutoAddExpertTask.scala +++ b/app/tasks/AutoAddExpertTask.scala @@ -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 @@ -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) @@ -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) => @@ -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, diff --git a/test/browser/ApplicationSpec.scala b/test/browser/ApplicationSpec.scala index 516fe69e0..23ea517f5 100644 --- a/test/browser/ApplicationSpec.scala +++ b/test/browser/ApplicationSpec.scala @@ -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)) } } } \ No newline at end of file