Skip to content

Commit

Permalink
Incoherent behavior with template and expired consent (#198)
Browse files Browse the repository at this point in the history
* Incoherent behavior with template and expired consent

* Swagger + IHM label
  • Loading branch information
larousso authored Oct 17, 2024
1 parent 0a50648 commit 277ab3c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- nio_zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181
KAFKA_ZOOKEEPER_CONNECT: nio_zookeeper:32181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_DELETE_TOPIC_ENABLE: "true"
Expand Down
2 changes: 1 addition & 1 deletion nio-server/app/controllers/ConsentController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ConsentController(
key = pg.key,
label = pg.label,
consents = pg.permissions.map { p =>
Consent(key = p.key, label = p.label, checked = p.checkDefault(), expiredAt = p.getValidityPeriod)
Consent(key = p.key, label = p.label, checked = p.checkDefault(), expiredAt = None)
}
)

Expand Down
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: Boolean = {
val now = LocalDateTime.now(Clock.systemUTC())
this.expiredAt.isEmpty || this.expiredAt.exists(d => d.isAfter(now))
}

def isExpired: Boolean = !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.nonEmpty).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/models/Permission.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import play.api.libs.json.*
import play.api.libs.json.Reads.*
import utils.Result.AppErrors

import java.time.{Clock, LocalDateTime, ZoneId}
import java.time.{Clock, LocalDateTime}
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.util.{Failure, Success, Try}
import scala.xml.{Elem, NodeBuffer, NodeSeq}
Expand Down
5 changes: 4 additions & 1 deletion nio-server/app/service/ConsentManagerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,12 @@ class ConsentManagerService(
}
.getOrElse(group)

val consentFactFiltered = consentFact.filterExpiredConsent(false)

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

mergeConsentGroup(maybeGroup, group)
}
Expand Down
7 changes: 7 additions & 0 deletions nio-server/conf/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,13 @@
"description": "L'identifiant utilisateur",
"required": true,
"type": "string"
},
{
"name": "showExpiredConsents",
"in": "query",
"description": "Consentement expiré oui / non",
"required": false,
"type": "boolean"
}
],
"responses": {
Expand Down
2 changes: 1 addition & 1 deletion nio-server/javascript/src/nio/pages/GroupPermissionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Permission extends Component {
possibleValues={["OptIn", "OptOut"]}
errorKey={`${this.props.prefixe}permissions.${this.props.index}.type.required`}/>

<TextInput label={"Validité de la permission"}
<TextInput label={"Durée de validité de la permission"}
value={this.state.permission.validityPeriod}
onChange={(e) => this.onChange(e, "validityPeriod")}
disabled={this.props.readOnlyMode}
Expand Down

0 comments on commit 277ab3c

Please sign in to comment.