Skip to content

Commit

Permalink
feat: Add 'keepAssets' query param to erase project endpoint (#3294)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Jun 25, 2024
1 parent b8f9d80 commit 23292ff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ final case class ProjectsEndpoints(

val deleteAdminProjectsByProjectShortcodeErase = baseEndpoints.securedEndpoint.delete
.in(projectsByShortcode / "erase")
.in(
query[Boolean]("keepAssets")
.default(false)
.description("If set to true the assets in ingest will not be removed."),
)
.out(jsonBody[ProjectOperationResponseADM])
.description(
"""|!ATTENTION! Erase a project with the given shortcode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ final case class ProjectsEndpointsHandler(
val deleteAdminProjectsByProjectShortcodeEraseHandler =
SecuredEndpointHandler(
projectsEndpoints.Secured.deleteAdminProjectsByProjectShortcodeErase,
user => (id: Shortcode) => restService.eraseProject(id, user),
user => (id: Shortcode, keepAssets: Boolean) => restService.eraseProject(id, user, keepAssets),
)

val getAdminProjectsExportsHandler =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final case class ProjectRestService(
external <- format.toExternal(internal)
} yield external

def eraseProject(shortcode: Shortcode, user: User): Task[ProjectOperationResponseADM] =
def eraseProject(shortcode: Shortcode, user: User, keepAssets: Boolean): Task[ProjectOperationResponseADM] =
for {
_ <- auth.ensureSystemAdmin(user)
_ <- ZIO.unless(features.allowEraseProjects)(
Expand All @@ -142,7 +142,7 @@ final case class ProjectRestService(
.findByShortcode(shortcode)
.someOrFail(NotFoundException(s"$shortcode not found"))
_ <- ZIO.logInfo(s"${user.userIri} erases project $shortcode")
_ <- projectEraseService.eraseProject(project)
_ <- projectEraseService.eraseProject(project, keepAssets)
external <- format.toExternal(ProjectOperationResponseADM(internal))
} yield external

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ final case class ProjectEraseService(
private def logPrefix(project: KnoraProject): String = s"ERASE Project ${project.shortcode.value}:"
private def mkString(values: Seq[StringValue]): String = s"'${values.map(_.value).mkString(",")}'"

def eraseProject(project: KnoraProject): Task[Unit] = for {
def eraseProject(project: KnoraProject, keepAssets: Boolean): Task[Unit] = for {
groupsToDelete <- groupService.findByProject(project)
_ <- cleanUpUsersAndGroups(project, groupsToDelete)
_ <- cleanUpPermissions(project)
_ <- removeOntologyAndDataGraphs(project)
_ <- projectService.erase(project)
_ <- ingestClient.eraseProject(project.shortcode).logError.ignore
_ <- ingestClient.eraseProject(project.shortcode).logError.ignore.unless(keepAssets)
} yield ()

private def cleanUpUsersAndGroups(project: KnoraProject, groups: Chunk[KnoraGroup]): UIO[Unit] = for {
Expand Down

0 comments on commit 23292ff

Please sign in to comment.