Skip to content

Commit

Permalink
Incoherent behavior with template and expired consent
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso committed Oct 16, 2024
1 parent 0a50648 commit 112e5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions nio-server/app/models/ConsentFact.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ object DoneBy {
}

case class Consent(key: String, label: String, checked: Boolean, expiredAt: Option[LocalDateTime] = None) {

def isActive: Bool = {
val now = LocalDateTime.now(Clock.systemUTC())
c.expiredAt.isEmpty || c.expiredAt.exists(d => d.isAfter(now))
}

def isExpired: Bool = !isActive

def asXml(): Elem = <consent>
<key>
{key}
Expand Down Expand Up @@ -87,6 +95,9 @@ object Consent {
}

case class ConsentGroup(key: String, label: String, consents: Seq[Consent]) {

def activeConsents: Seq[Consent] = this.consents.filter(_.isActive)

def asXml(): Elem = <consentGroup>
<key>
{key}
Expand Down Expand Up @@ -424,7 +435,7 @@ case class ConsentFact(
{version}
</version>
<groups>
{groups.map(_.asXml())}
{groups.filter(cf => cf.consents).map(_.asXml())}
</groups>

{
Expand Down Expand Up @@ -472,12 +483,10 @@ case class ConsentFact(
if (showExpiredConsents) {
this
} else {
val now = LocalDateTime.now(Clock.systemUTC())
this.copy(groups = this.groups.map(group =>
group.copy(consents = group.consents.toList.filter(c =>
c.expiredAt.isEmpty || c.expiredAt.exists(d => d.isAfter(now))
))
))
this.copy(groups = this.groups
.map(group => group.copy(consents = group.activeConsents))
.filter(group => group.consents.nonEmpty)
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion nio-server/app/service/ConsentManagerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class ConsentManagerService(

val groupsUpdated: Seq[ConsentGroup] =
template.groups.map { group =>
val maybeGroup = consentFact.groups.find(cg => cg.key == group.key && cg.label == group.label)
val maybeGroup = consentFact.filterExpiredConsent(true).find(cg => cg.key == group.key && cg.label == group.label)

mergeConsentGroup(maybeGroup, group)
}
Expand Down

0 comments on commit 112e5e9

Please sign in to comment.