Skip to content

Commit

Permalink
APIS-7342 Update validation on DeleteApplicationByCollaboratorCommand…
Browse files Browse the repository at this point in the history
… to include delete restriction (#537)
  • Loading branch information
petekirby-ee authored Jan 21, 2025
1 parent 09e56b0 commit 6c632d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import cats.data.{NonEmptyList, Validated}
import uk.gov.hmrc.http.HeaderCarrier

import uk.gov.hmrc.apiplatform.modules.common.domain.models.Actors
import uk.gov.hmrc.apiplatform.modules.applications.core.domain.models.{Collaborator, State, StateHistory}
import uk.gov.hmrc.apiplatform.modules.applications.core.domain.models.{Collaborator, DeleteRestriction, State, StateHistory}
import uk.gov.hmrc.apiplatform.modules.approvals.repositories.ResponsibleIndividualVerificationRepository
import uk.gov.hmrc.apiplatform.modules.commands.applications.domain.models.ApplicationCommands.DeleteApplicationByCollaborator
import uk.gov.hmrc.apiplatform.modules.events.applications.domain.models._
Expand Down Expand Up @@ -53,12 +53,16 @@ class DeleteApplicationByCollaboratorCommandHandler @Inject() (
private def canDeleteApplicationsOrNotProductionApp(app: StoredApplication) =
cond(authControlConfig.canDeleteApplications || !app.isInPreProductionOrProduction, "Cannot delete this applicaton")

private def canDeleteApplication(app: StoredApplication) =
cond(app.deleteRestriction == DeleteRestriction.NoRestriction, "This application is delete restricted")

private def validate(app: StoredApplication, cmd: DeleteApplicationByCollaborator): Validated[Failures, Collaborator] = {
Apply[Validated[Failures, *]].map3(
Apply[Validated[Failures, *]].map4(
isAdminOnApp(cmd.instigator, app),
ensureStandardAccess(app),
canDeleteApplicationsOrNotProductionApp(app)
) { case (admin, _, _) => admin }
canDeleteApplicationsOrNotProductionApp(app),
canDeleteApplication(app)
) { case (admin, _, _, _) => admin }
}

private def asEvents(app: StoredApplication, cmd: DeleteApplicationByCollaborator, instigator: Collaborator, stateHistory: StateHistory): NonEmptyList[ApplicationEvent] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import uk.gov.hmrc.http.HeaderCarrier

import uk.gov.hmrc.apiplatform.modules.common.domain.models.{Actors, UserId}
import uk.gov.hmrc.apiplatform.modules.applications.access.domain.models.Access
import uk.gov.hmrc.apiplatform.modules.applications.core.domain.models.State
import uk.gov.hmrc.apiplatform.modules.applications.core.domain.models.{DeleteRestriction, State}
import uk.gov.hmrc.apiplatform.modules.commands.applications.domain.models.ApplicationCommands.DeleteApplicationByCollaborator
import uk.gov.hmrc.apiplatform.modules.events.applications.domain.models._
import uk.gov.hmrc.thirdpartyapplication.config.AuthControlConfig
Expand Down Expand Up @@ -118,6 +118,12 @@ class DeleteApplicationByCollaboratorCommandHandlerSpec extends CommandHandlerBa
}
}

}
"return an error when app is delete restricted" in new Setup {
val deleteRestrictedApp = app.copy(deleteRestriction = DeleteRestriction.DoNotDelete("reason", Actors.GatekeeperUser("gkuser"), instant))

checkFailsWith("This application is delete restricted") {
underTest.process(deleteRestrictedApp, cmd)
}
}
}
}

0 comments on commit 6c632d4

Please sign in to comment.