Skip to content

Commit

Permalink
[WG][APB-8964][APB-8949] Fix remove authorization (#311)
Browse files Browse the repository at this point in the history
Co-authored-by: wojciech.gradzki <gitwojciech@users.noreply.github.com>
  • Loading branch information
gitwojciech and gitwojciech authored Dec 18, 2024
1 parent 17e2191 commit 0cd3b5e
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class RemoveAuthorisationController @Inject() (
): Future[Either[InvitationFailureResponse, Result]] =
validRequest.service match {

// TODO WG - do audit for PersonalIncome
case Service.PersonalIncomeRecord =>
agentFiRelationshipConnector
.deleteRelationship(arn, validRequest.service.id, validRequest.suppliedClientId.value)
Expand All @@ -111,7 +112,8 @@ class RemoveAuthorisationController @Inject() (
)
}

case None => getEnrolmentAndDeleteRelationship(arn, validRequest)
case None =>
getEnrolmentAndDeleteRelationship(arn, validRequest)

}

Expand Down Expand Up @@ -152,7 +154,7 @@ class RemoveAuthorisationController @Inject() (
suppliedEnrolmentKey <- EitherT(
validationService.validateForEnrolmentKey(
validRequest.service.id,
validRequest.suppliedClientId.typeId,
validRequest.suppliedClientId.enrolmentId,
validRequest.suppliedClientId.value
)
).leftMap(_ => EnrolmentKeyNotFound)
Expand All @@ -162,7 +164,6 @@ class RemoveAuthorisationController @Inject() (
deauthorisationService
.replaceEnrolmentKeyForItsa(validRequest.suppliedClientId, suppliedEnrolmentKey, validRequest.service)
)

} yield enrolmentKey
resultT.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RemoveAuthorisationService @Inject() (
case (MtdIt | MtdItSupp, NinoType.id) =>
ifConnector
.getMtdIdFor(Nino(suppliedClientId.value))
.map(_.map(EnrolmentKey(Service.MtdIt, _)))
.map(_.map(EnrolmentKey(service, _)))
.map(_.toRight(ClientRegistrationNotFound))
.recover { case NonFatal(_) =>
Left[InvitationFailureResponse, EnrolmentKey](ClientRegistrationNotFound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ class ValidationService @Inject() (
): Future[Either[String, EnrolmentKey]] =
(serviceKey, clientType) match {
// "special" cases
case ("IR-SA", "ni" | "NI") if Nino.isValid(clientId) =>
case ("IR-SA", "ni" | "NI" | "NINO") if Nino.isValid(clientId) =>
Future.successful(Right(EnrolmentKey("IR-SA", Nino(clientId))))
case (Service.MtdIt.id | Service.MtdItSupp.id, "ni" | "NI") if Nino.isValid(clientId) =>
case (Service.MtdIt.id | Service.MtdItSupp.id, "ni" | "NI" | "NINO") if Nino.isValid(clientId) =>
Future.successful(Right(EnrolmentKey(serviceKey, Nino(clientId))))
case ("HMCE-VATDEC-ORG", "vrn") if Vrn.isValid(clientId) =>
Future.successful(Right(EnrolmentKey("HMCE-VATDEC-ORG", Vrn(clientId))))
case (Service.Cbc.id, CbcIdType.enrolmentId) =>
makeSanitisedCbcEnrolmentKey(CbcId(clientId))
// "normal" cases
case (serviceKey, _) =>
if (appConfig.supportedServices.exists(_.id == serviceKey)) {
if (appConfig.supportedServices.exists(_.id == serviceKey))
validateSupportedServiceForEnrolmentKey(serviceKey, clientType, clientId)
} else Future.successful(Left(s"Unknown service $serviceKey"))
else
Future.successful(Left(s"Unknown service $serviceKey"))
}

/** This is needed because sometimes we call the ACR endpoints specifying HMRC-CBC-ORG but it could actually be
Expand Down
Loading

0 comments on commit 0cd3b5e

Please sign in to comment.