Missed checking for non-optional relationship on DELETE a singular relationship. Now works as it's supposed to.
This commit is contained in:
@@ -1313,6 +1313,12 @@ public class RepositoryRestController
|
||||
return notFoundResponse(request);
|
||||
}
|
||||
|
||||
// Check if this is a @*ToOne relationship and is optional and if not, fail with a 405 Method Not Allowed
|
||||
if((attrMeta.hasAnnotation(ManyToOne.class) && !attrMeta.annotation(ManyToOne.class).optional())
|
||||
|| (attrMeta.hasAnnotation(OneToOne.class) && !attrMeta.annotation(OneToOne.class).optional())) {
|
||||
return negotiateResponse(request, HttpStatus.METHOD_NOT_ALLOWED, new HttpHeaders(), null);
|
||||
}
|
||||
|
||||
Object linked = attrMeta.get(entity);
|
||||
attrMeta.set(null, entity);
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ class RelationshipsSpec extends BaseSpec {
|
||||
def "cannot delete a required relationship"() {
|
||||
|
||||
when:
|
||||
def request = createRequest("DELETE", "address/$addrId/person/$persId", null)
|
||||
def response = controller.deleteLink(request, "address", "$addrId", "person", "$persId")
|
||||
def request = createRequest("DELETE", "address/$addrId/person", null)
|
||||
def response = controller.clearLinks(request, "address", "$addrId", "person")
|
||||
|
||||
then:
|
||||
response.statusCode == HttpStatus.METHOD_NOT_ALLOWED
|
||||
|
||||
Reference in New Issue
Block a user