Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige les opérateurs invités ne pouvant pas voir les fichiers #1037

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ object Application {
def now(userId: UUID) = SeenByUser(userId, Instant.now())
}

def filesAvailabilityLeftInDays(filesExpirationInDays: Int)(application: Application) =
def filesAvailabilityLeftInDays(filesExpirationInDays: Int)(
application: Application
): Option[Int] =
application.ageInDays.some.map(filesExpirationInDays - _).filter(_ >= 0)

sealed trait MandatType
Expand Down
25 changes: 20 additions & 5 deletions app/models/Authorization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,26 @@ object Authorization {
application: Application,
answerId: UUID
)(userId: UUID, rights: UserRights): Boolean =
application.answers
.find(_.id === answerId)
.flatMap(Answer.filesAvailabilityLeftInDays(filesExpirationInDays)) match {
case Some(_) => applicationFileCanBeShowed(filesExpirationInDays)(application)(userId, rights)
case _ => false
application.answers.find(_.id === answerId) match {
case None => false
case Some(answer) =>
val hasNotExpired =
Answer.filesAvailabilityLeftInDays(filesExpirationInDays)(answer).nonEmpty
val validCase1 =
hasNotExpired &&
isHelper(rights) &&
answer.visibleByHelpers &&
userId === application.creatorUserId
val invitedUsersInAnswers: Set[UUID] =
(application.answers.takeWhile(_.id =!= answerId) :+ answer)
.flatMap(_.invitedUsers.keys)
.toSet
val validCase2 =
hasNotExpired &&
isInstructor(rights) &&
(application.invitedUsers.keys.toSet ++ invitedUsersInAnswers).contains(userId)

validCase1 || validCase2
}

def applicationFileCanBeShowed(filesExpirationInDays: Int)(
Expand Down