Skip to content

Commit

Permalink
Merge pull request #1315 from libris/feature/lxl-4209-non-deletion-bl…
Browse files Browse the repository at this point in the history
…ocking-relations

Allow some relations to link to deleted resources
  • Loading branch information
kwahlin authored Oct 9, 2023
2 parents 938b0e6 + b15fead commit 7b3f844
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rest/src/main/groovy/whelk/rest/api/Crud.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ class Crud extends HttpServlet {
throw new OtherStatusException("You do not have sufficient privileges to perform this operation.", HttpServletResponse.SC_FORBIDDEN)
} else if (doc && doc.deleted) {
throw new OtherStatusException("Document has been deleted.", HttpServletResponse.SC_GONE)
} else if(!whelk.storage.followDependers(doc.getShortId()).isEmpty()) {
} else if(!whelk.storage.followDependers(doc.getShortId(), JsonLd.ALLOW_LINK_TO_DELETED).isEmpty()) {
throw new OtherStatusException("This record may not be deleted, because it is referenced by other records.", HttpServletResponse.SC_FORBIDDEN)
} else {
log.debug("Removing resource at ${doc.getShortId()}")
Expand Down
12 changes: 6 additions & 6 deletions rest/src/test/groovy/whelk/rest/api/CrudSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ class CrudSpec extends Specification {
storage.remove(_, _) >> {
return true
}
storage.followDependers(_) >> {
storage.followDependers(_, _) >> {
[]
}
when:
Expand Down Expand Up @@ -3667,7 +3667,7 @@ class CrudSpec extends Specification {
storage.remove(_, _) >> {
return true
}
storage.followDependers(_) >> {
storage.followDependers(_, _) >> {
[]
}
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
Expand Down Expand Up @@ -3712,7 +3712,7 @@ class CrudSpec extends Specification {
storage.remove(_, _) >> {
return true
}
storage.followDependers(_) >> {
storage.followDependers(_, _) >> {
[]
}
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
Expand Down Expand Up @@ -3757,7 +3757,7 @@ class CrudSpec extends Specification {
storage.remove(_, _) >> {
return true
}
storage.followDependers(_) >> {
storage.followDependers(_, _) >> {
[]
}
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
Expand Down Expand Up @@ -3895,7 +3895,7 @@ class CrudSpec extends Specification {
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
return "bib"
}
storage.followDependers(_) >> {
storage.followDependers(_, _) >> {
[]
}
when:
Expand Down Expand Up @@ -3976,7 +3976,7 @@ class CrudSpec extends Specification {
storage.remove(_, _) >> {
return true
}
storage.followDependers(_) >> {
storage.followDependers(_, _) >> {
[]
}
LegacyIntegrationTools.determineLegacyCollection(_, _) >> {
Expand Down
4 changes: 4 additions & 0 deletions whelk-core/src/main/groovy/whelk/JsonLd.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class JsonLd {
static final List<String> NS_SEPARATORS = ['#', '/', ':']

static final List<String> NON_DEPENDANT_RELATIONS = ['narrower', 'broader', 'expressionOf', 'related', 'derivedFrom']
static final List<String> ALLOW_LINK_TO_DELETED = [
'meta.derivedFrom', 'hasTitle.source',
/* following are combinations only needed while there are local unlinked works */
'translationOf.hasTitle.source', 'instanceOf.hasTitle.source', 'instanceOf.translationOf.hasTitle.source']

static final Set<String> LD_KEYS

Expand Down

0 comments on commit 7b3f844

Please sign in to comment.