Missed checking for non-optional relationship on DELETE a singular relationship. Now works as it's supposed to.

This commit is contained in:
Jon Brisbin
2012-08-17 15:07:45 -05:00
committed by Jon Brisbin
parent 023ab6b885
commit 349c3b9777
2 changed files with 8 additions and 2 deletions

View File

@@ -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);

View File

@@ -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