Skip to content

Commit

Permalink
Ajoute un champ de commentaire pour le support (utilisateur et groupe) (
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic authored Jan 26, 2021
1 parent b559659 commit fd96932
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 38 deletions.
17 changes: 12 additions & 5 deletions app/controllers/CSVImportController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ case class CSVImportController @Inject() (
areaIds = group.group.areaIds,
organisation = group.group.organisation,
email = group.group.email,
publicNote = None
publicNote = None,
internalSupportComment = None
),
users = group.users.map(user =>
CSVUserFormData(
Expand Down Expand Up @@ -185,8 +186,12 @@ case class CSVImportController @Inject() (
},
Option.apply
),
"name" -> text(maxLength = 60),
"description" -> optional(text),
"name" -> text(maxLength = 60)
.transform[String](commonStringInputNormalization, commonStringInputNormalization),
"description" -> optional(text).transform[Option[String]](
_.map(commonStringInputNormalization).filter(_.nonEmpty),
_.map(commonStringInputNormalization).filter(_.nonEmpty)
),
"insee-code" -> list(text),
"creationDate" -> ignored(date),
"area-ids" -> list(uuid)
Expand All @@ -196,7 +201,8 @@ case class CSVImportController @Inject() (
_.exists(Organisation.isValidId)
),
"email" -> optional(email),
"publicNote" -> ignored(Option.empty[String])
"publicNote" -> ignored(Option.empty[String]),
"internalSupportComment" -> ignored(Option.empty[String])
)(UserGroup.apply)(UserGroup.unapply)

private def importUsersAfterReviewForm(date: ZonedDateTime): Form[List[CSVUserGroupFormData]] =
Expand Down Expand Up @@ -332,7 +338,8 @@ case class CSVImportController @Inject() (
newsletterAcceptationDate = None,
phoneNumber = userData.user.phoneNumber,
observableOrganisationIds = Nil,
sharedAccount = userData.user.name.nonEmpty
sharedAccount = userData.user.name.nonEmpty,
internalSupportComment = None
)
)
}
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/GroupController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ case class GroupController @Inject() (
"publicNote" -> optional(text).transform[Option[String]](
_.map(commonStringInputNormalization).filter(_.nonEmpty),
_.map(commonStringInputNormalization).filter(_.nonEmpty)
),
"internalSupportComment" -> optional(text).transform[Option[String]](
_.map(commonStringInputNormalization).filter(_.nonEmpty),
_.map(commonStringInputNormalization).filter(_.nonEmpty)
)
)(UserGroup.apply)(UserGroup.unapply)
)
Expand Down
15 changes: 11 additions & 4 deletions app/controllers/UserController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ case class UserController @Inject() (
groupIds = user.groupIds,
phoneNumber = user.phoneNumber,
observableOrganisationIds = user.observableOrganisationIds,
sharedAccount = user.sharedAccount
sharedAccount = user.sharedAccount,
internalSupportComment = user.internalSupportComment
)
)
val groups = groupService.allGroups
Expand Down Expand Up @@ -565,7 +566,8 @@ case class UserController @Inject() (
groupIds = updatedUserData.groupIds.distinct,
phoneNumber = updatedUserData.phoneNumber,
observableOrganisationIds = updatedUserData.observableOrganisationIds.distinct,
sharedAccount = updatedUserData.sharedAccount
sharedAccount = updatedUserData.sharedAccount,
internalSupportComment = updatedUserData.internalSupportComment
)
userService.update(userToUpdate).map { updateHasBeenDone =>
if (updateHasBeenDone) {
Expand Down Expand Up @@ -649,7 +651,8 @@ case class UserController @Inject() (
newsletterAcceptationDate = None,
phoneNumber = userToAdd.phoneNumber,
observableOrganisationIds = Nil,
sharedAccount = userToAdd.sharedAccount
sharedAccount = userToAdd.sharedAccount,
internalSupportComment = None
)
)
userService
Expand Down Expand Up @@ -922,7 +925,11 @@ case class UserController @Inject() (
"groupIds" -> default(list(uuid), Nil),
"phoneNumber" -> optional(text),
"observableOrganisationIds" -> list(of[Organisation.Id]),
Keys.User.sharedAccount -> boolean
Keys.User.sharedAccount -> boolean,
"internalSupportComment" -> optional(text).transform[Option[String]](
_.map(commonStringInputNormalization).filter(_.nonEmpty),
_.map(commonStringInputNormalization).filter(_.nonEmpty)
)
)(EditUserFormData.apply)(EditUserFormData.unapply)
)

Expand Down
17 changes: 15 additions & 2 deletions app/models/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ case class User(
// * can see all users,
// * can see one user but not edit it
observableOrganisationIds: List[Organisation.Id] = Nil,
sharedAccount: Boolean = false
sharedAccount: Boolean = false,
// This is a comment only visible by the admins
internalSupportComment: Option[String]
) extends AgeModel {
def nameWithQualite = s"$name ( $qualite )"

Expand Down Expand Up @@ -93,6 +95,9 @@ case class User(
lazy val observableOrganisationIdsLog: String = observableOrganisationIds.map(_.id).mkString(", ")
lazy val sharedAccountLog: String = sharedAccount.toString

lazy val internalSupportCommentLog: String =
internalSupportComment.map(withQuotes).getOrElse("<vide>")

lazy val toLogString: String =
"[" + List[(String, String)](
("Id", id.toString),
Expand All @@ -114,6 +119,7 @@ case class User(
("Date CGU", cguAcceptationDateLog),
("Newsletter", newsletterAcceptationDateLog),
("Observation des organismes", observableOrganisationIdsLog),
("Information Support", internalSupportCommentLog),
).map { case (fieldName, value) => s"$fieldName : $value" }.mkString(" | ") + "]"

def toDiffLogString(other: User): String = {
Expand Down Expand Up @@ -157,6 +163,12 @@ case class User(
observableOrganisationIdsLog,
other.observableOrganisationIdsLog
),
(
"Information Support",
internalSupportCommentLog =!= other.internalSupportCommentLog,
internalSupportCommentLog,
other.internalSupportCommentLog
),
).collect { case (name, true, thisValue, thatValue) => s"$name : $thisValue -> $thatValue" }
"[" + diffs.mkString(" | ") + "]"
}
Expand All @@ -180,7 +192,8 @@ object User {
ZonedDateTime.parse("2017-11-01T00:00+01:00"),
"75056",
groupAdmin = false,
disabled = true
disabled = true,
internalSupportComment = None
)

}
16 changes: 14 additions & 2 deletions app/models/UserGroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ case class UserGroup(
organisation: Option[Organisation.Id] = None,
email: Option[String] = None,
// This is a note displayed to users trying to select this group
publicNote: Option[String]
publicNote: Option[String],
// This is a comment only visible by the admins
internalSupportComment: Option[String]
) {

def canHaveUsersAddedBy(user: User): Boolean =
Expand All @@ -35,6 +37,9 @@ case class UserGroup(
lazy val areaIdsLog: String = areaIds.mkString(", ")
lazy val publicNoteLog: String = publicNote.map(withQuotes).getOrElse("<vide>")

lazy val internalSupportCommentLog: String =
internalSupportComment.map(withQuotes).getOrElse("<vide>")

lazy val toLogString: String =
"[" + List[(String, String)](
("Id", id.toString),
Expand All @@ -43,7 +48,8 @@ case class UserGroup(
("BAL", emailLog),
("Organisme", organisationLog),
("Territoires", areaIdsLog),
("Notice", publicNoteLog)
("Notice", publicNoteLog),
("Information Support", internalSupportCommentLog),
).map { case (fieldName, value) => s"$fieldName : $value" }.mkString(" | ") + "]"

def toDiffLogString(other: UserGroup): String = {
Expand All @@ -55,6 +61,12 @@ case class UserGroup(
("Organisme", organisation =!= other.organisation, organisationLog, other.organisationLog),
("Territoires", areaIds =!= other.areaIds, areaIdsLog, other.areaIdsLog),
("Notice", publicNote =!= other.publicNote, publicNoteLog, other.publicNoteLog),
(
"Information Support",
internalSupportCommentLog =!= other.internalSupportCommentLog,
internalSupportCommentLog,
other.internalSupportCommentLog
),
).collect { case (name, true, thisValue, thatValue) => s"$name : $thisValue -> $thatValue" }
"[" + diffs.mkString(" | ") + "]"
}
Expand Down
3 changes: 2 additions & 1 deletion app/models/formModels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ object formModels {
groupIds: List[UUID],
phoneNumber: Option[String],
observableOrganisationIds: List[Organisation.Id],
sharedAccount: Boolean
sharedAccount: Boolean,
internalSupportComment: Option[String]
)

case class CSVReviewUserFormData(
Expand Down
6 changes: 4 additions & 2 deletions app/services/UserGroupService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class UserGroupService @Inject() (
"area_ids",
"organisation",
"email",
"public_note"
"public_note",
"internal_support_comment"
)
.map(a => a.copy(creationDate = a.creationDate.withZoneSameInstant(Time.timeZoneParis)))

Expand Down Expand Up @@ -81,7 +82,8 @@ class UserGroupService @Inject() (
organisation = ${group.organisation.map(_.id)},
area_ids = array[${group.areaIds}]::uuid[],
email = ${group.email},
public_note = ${group.publicNote}
public_note = ${group.publicNote},
internal_support_comment = ${group.internalSupportComment}
WHERE id = ${group.id}::uuid
""".executeUpdate() === 1
//TODO: insee_code = array[${group.inseeCode}]::character varying(5)[], have been remove temporary
Expand Down
6 changes: 4 additions & 2 deletions app/services/UserService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class UserService @Inject() (
"newsletter_acceptation_date",
"phone_number",
"observable_organisation_ids",
"shared_account"
"shared_account",
"internal_support_comment"
)
.map(a => a.copy(creationDate = a.creationDate.withZoneSameInstant(Time.timeZoneParis)))

Expand Down Expand Up @@ -229,7 +230,8 @@ class UserService @Inject() (
phone_number = ${user.phoneNumber},
disabled = ${user.disabled},
observable_organisation_ids = array[${observableOrganisationIds.distinct}]::varchar[],
shared_account = ${user.sharedAccount}
shared_account = ${user.sharedAccount},
internal_support_comment = ${user.internalSupportComment}
WHERE id = ${user.id}::uuid
""".executeUpdate() === 1
})
Expand Down
16 changes: 16 additions & 0 deletions app/views/editGroup.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@
}
</select>
</div>


@if(currentUser.admin) {

<div class="mdl-cell mdl-cell--12-col mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<textarea class="mdl-textfield__input single--height-auto" type="text" rows="3" id="internalSupportComment" name="internalSupportComment">@userGroup.internalSupportComment</textarea>
<label class="mdl-textfield__label" for="internalSupportComment">Commentaire interne pour le support (visible uniquement par les administrateurs)</label>
</div>

} else {
<input type="hidden"
name="internalSupportComment"
id="internalSupportComment"
value="@userGroup.internalSupportComment">
}

@if(currentUser.admin) {
<div class="mdl-cell mdl-cell--12-col">
<button class="mdl-button mdl-js-button mdl-button--raised" type="submit">
Expand Down
17 changes: 17 additions & 0 deletions app/views/editUser.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@

</div>

@if(currentUser.admin) {
@helper.input(form("internalSupportComment"),
"label" -> "Commentaire interne pour le support (visible uniquement par les administrateurs)",
"class" -> "single--width-100pc") { (id, name, value, args) =>
<textarea class="mdl-textfield__input single--height-auto"
type="text"
rows="3"
id="@id"
name="@name">@value</textarea>
}
} else {
<input type="hidden"
name="internalSupportComment"
id="internalSupportComment"
value="@uneditedUser.internalSupportComment">
}

@if(unused && canEditUser) {
<button class="mdl-button mdl-js-button mdl-button--raised" type="button" onclick="showDialog(document.querySelector('#dialog-delete-user'))">Supprimer cet utilisateur inutilisé</button>
<br>
Expand Down
7 changes: 7 additions & 0 deletions conf/evolutions/default/47.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --- !Ups
ALTER TABLE "user" ADD internal_support_comment text NULL;
ALTER TABLE user_group ADD internal_support_comment text NULL;

# --- !Downs
ALTER TABLE user_group DROP internal_support_comment;
ALTER TABLE "user" DROP internal_support_comment;
4 changes: 0 additions & 4 deletions public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,6 @@ a {
height: auto !important;
}

.single--width-100pc {
width: 100%;
}

.single--width-unset {
width: unset;
}
Expand Down
6 changes: 4 additions & 2 deletions test/browser/AnswerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class AnswerSpec extends Specification with Tables with BaseSpec {
inseeCode = List("0"),
creationDate = Time.nowParis(),
areaIds = area :: Nil,
publicNote = None
publicNote = None,
internalSupportComment = None
)
groupService.add(group)
group
Expand Down Expand Up @@ -64,7 +65,8 @@ class AnswerSpec extends Specification with Tables with BaseSpec {
disabled = false,
expert = isExpert,
cguAcceptationDate = Some(Time.nowParis()),
groupIds = groups.map(_.id)
groupIds = groups.map(_.id),
internalSupportComment = None
)
val result = userService.add(List(user))
result.isRight must beTrue
Expand Down
Loading

0 comments on commit fd96932

Please sign in to comment.