Skip to content

Commit

Permalink
Fix expiration date updated on patch (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso authored Oct 21, 2024
1 parent 277ab3c commit 07f9a8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions nio-server/app/models/ConsentFact.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ case class PartialConsentFact(
metaData = metaData.map(meta => lastConsentFact.metaData.map(m => m.combine(meta)).getOrElse(meta)).orElse(lastConsentFact.metaData),
sendToKafka = sendToKafka.orElse(lastConsentFact.sendToKafka)
)
println(s"Merged data : $this, \n $lastConsentFact, \n $finalConsent")
finalConsent
}
}
Expand Down Expand Up @@ -470,9 +469,9 @@ case class ConsentFact(
this.copy(groups = this.groups.map( group =>
group.copy(
consents = group.consents.map ( consent =>
consent.copy(expiredAt = indexed.get(KeyPermissionGroup(group.key, consent.key))
consent.copy(expiredAt = consent.expiredAt.orElse(indexed.get(KeyPermissionGroup(group.key, consent.key))
.flatMap(_.headOption)
.flatMap(_._2.getValidityPeriod)
.flatMap(_._2.getValidityPeriod))
)
)
)
Expand Down
11 changes: 5 additions & 6 deletions nio-server/app/service/ConsentManagerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ class ConsentManagerService(
author: String,
metadata: Option[Seq[(String, String)]],
organisation: Organisation,
consentFactInput: ConsentFact,
consentFact: ConsentFact,
maybeLastConsentFact: Option[ConsentFact] = None,
command: JsValue
): IO[AppErrorWithStatus, ConsentFact] =
for {
_ <- IO.fromEither(organisation.isValidWith(consentFactInput, maybeLastConsentFact)).mapError(m => AppErrorWithStatus(m))
consentFact: ConsentFact = consentFactInput.setUpValidityPeriods(organisation)
_ <- IO.fromEither(organisation.isValidWith(consentFact, maybeLastConsentFact)).mapError(m => AppErrorWithStatus(m))
organisationKey: String = organisation.key
userId: String = consentFact.userId
_ <- validateOffersStructures(tenant, organisationKey, userId, consentFact.offers).doOnError{ e => NioLogger.error(s"validate offers structure $e") }
Expand Down Expand Up @@ -302,7 +301,7 @@ class ConsentManagerService(
AppErrorWithStatus("error.specified.version.not.latest")
})
.flatMap { organisation =>
createOrReplace(tenant, author, metadata, organisation, consentFact, command = command)
createOrReplace(tenant, author, metadata, organisation, consentFact.setUpValidityPeriods(organisation), command = command)
}

// Update consent fact with the same organisation version
Expand All @@ -316,7 +315,7 @@ class ConsentManagerService(
}
)
.flatMap { organisation =>
createOrReplace(tenant, author, metadata, organisation, consentFact, Some(lastConsentFactStored), command = command)
createOrReplace(tenant, author, metadata, organisation, consentFact.setUpValidityPeriods(organisation), Some(lastConsentFactStored), command = command)
}

// Update consent fact with the new organisation version
Expand All @@ -333,7 +332,7 @@ class ConsentManagerService(
_ => AppErrorWithStatus("error.version.higher.than.release")
})
.flatMap { organisation =>
createOrReplace(tenant, author, metadata, organisation, consentFact, Option(lastConsentFactStored), command = command)
createOrReplace(tenant, author, metadata, organisation, consentFact.setUpValidityPeriods(organisation), Option(lastConsentFactStored), command = command)
}

// Cannot rollback and update a consent fact to an old organisation version
Expand Down

0 comments on commit 07f9a8e

Please sign in to comment.