Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ontology)!: use patch instead of delete for deleting cardinalities (DSP-1700) #1903

4 changes: 2 additions & 2 deletions docs/03-apis/api-v2/ontology-information.md
Expand Up @@ -1598,7 +1598,7 @@ property a cardinality refers to, is not used inside the data. Also, the propert
isn't allowed to be used inside the data in any subclasses of this class.

```
HTTP DELETE to http://host/v2/ontologies/cardinalities
HTTP PATCH to http://host/v2/ontologies/cardinalities
```

```jsonld
Expand Down Expand Up @@ -1645,7 +1645,7 @@ definition (but not any of the other entities in the ontology).
To check whether a class's cardinality can be deleted:

```
HTTP POST to http://host/v2/ontologies/candeletedinalities
HTTP POST to http://host/v2/ontologies/candeletecardinalities
```

The response will look like this:
Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/resources/application.conf
Expand Up @@ -250,7 +250,7 @@ akka-http-cors {
#
# The preflight request will be rejected if the `Access-Control-Request-Method`
# header's method is not part of the list.
allowed-methods = ["GET", "PUT", "POST", "DELETE", "HEAD", "OPTIONS"]
allowed-methods = ["GET", "PUT", "POST", "DELETE", "PATCH", "HEAD", "OPTIONS"]

# List of headers (other than simple response headers) that browsers are allowed to access.
# If not empty, this list is returned as part of the `Access-Control-Expose-Headers`
Expand Down
Expand Up @@ -526,7 +526,7 @@ class OntologiesRouteV2(routeData: KnoraRouteData) extends KnoraRoute(routeData)
// not used in resources.
private def deleteCardinalitiesFromClass(featureFactoryConfig: FeatureFactoryConfig): Route =
path(OntologiesBasePath / "cardinalities") {
delete {
patch {
entity(as[String]) { jsonRequest => requestContext =>
{
val requestMessageFuture: Future[DeleteCardinalitiesFromClassRequestV2] = for {
Expand Down
Expand Up @@ -36,8 +36,8 @@ object CORSSupportE2ESpec {
}

/**
* End-to-end test specification for testing [[CORSSupport]].
*/
* End-to-end test specification for testing [[CORSSupport]].
*/
class CORSSupportE2ESpec extends E2ESpec(CORSSupportE2ESpec.config) {

implicit def default(implicit system: ActorSystem) = RouteTestTimeout(settings.defaultTimeout)
Expand All @@ -51,30 +51,31 @@ class CORSSupportE2ESpec extends E2ESpec(CORSSupportE2ESpec.config) {
"A Route with enabled CORS support" should {

"accept valid pre-flight requests" in {
val request = Options(baseApiUrl + s"/admin/projects") ~> Origin(exampleOrigin) ~> `Access-Control-Request-Method`(
GET)
val request =
Options(baseApiUrl + s"/admin/projects") ~> Origin(exampleOrigin) ~> `Access-Control-Request-Method`(GET)
val response: HttpResponse = singleAwaitingRequest(request)
response.status shouldBe StatusCodes.OK
response.headers should contain allElementsOf Seq(
`Access-Control-Allow-Origin`(exampleOrigin),
`Access-Control-Allow-Methods`(List(GET, PUT, POST, DELETE, HEAD, OPTIONS)),
`Access-Control-Allow-Methods`(List(GET, PUT, POST, DELETE, PATCH, HEAD, OPTIONS)),
`Access-Control-Max-Age`(1800),
`Access-Control-Allow-Credentials`(true)
)
}

"reject requests with invalid method" in {
val request = Options(baseApiUrl + s"/admin/projects") ~> Origin(exampleOrigin) ~> `Access-Control-Request-Method`(
PATCH)
val response: HttpResponse = singleAwaitingRequest(request)
responseToString(response) shouldEqual "CORS: invalid method 'PATCH'"
response.status shouldBe StatusCodes.BadRequest
}
// "reject requests with invalid method" in {
// val request = Options(baseApiUrl + s"/admin/projects") ~> Origin(exampleOrigin) ~> `Access-Control-Request-Method`(
// PATCH)
// val response: HttpResponse = singleAwaitingRequest(request)
// responseToString(response) shouldEqual "CORS: invalid method 'PATCH'"
// response.status shouldBe StatusCodes.BadRequest
// }
irinaschubert marked this conversation as resolved.
Show resolved Hide resolved

"send `Access-Control-Allow-Origin` header when the Knora resource is found " in {
val request = Get(
baseApiUrl + "/v1/resources/" + java.net.URLEncoder.encode("http://rdfh.ch/0001/55UrkgTKR2SEQgnsLWI9mg",
"utf-8")) ~> Origin(exampleOrigin)
baseApiUrl + "/v1/resources/" + java.net.URLEncoder
.encode("http://rdfh.ch/0001/55UrkgTKR2SEQgnsLWI9mg", "utf-8")
) ~> Origin(exampleOrigin)
val response = singleAwaitingRequest(request)
response.status should equal(StatusCodes.OK)
response.headers should contain allElementsOf Seq(
Expand All @@ -83,8 +84,9 @@ class CORSSupportE2ESpec extends E2ESpec(CORSSupportE2ESpec.config) {
}

"send `Access-Control-Allow-Origin` header when the Knora resource is NOT found " in {
val request = Get(baseApiUrl + "/v1/resources/" + java.net.URLEncoder.encode("http://rdfh.ch/0803/nonexistent",
"utf-8")) ~> Origin(exampleOrigin)
val request = Get(
baseApiUrl + "/v1/resources/" + java.net.URLEncoder.encode("http://rdfh.ch/0803/nonexistent", "utf-8")
) ~> Origin(exampleOrigin)
val response = singleAwaitingRequest(request)
response.status should equal(StatusCodes.NotFound)
response.headers should contain allElementsOf Seq(
Expand All @@ -93,7 +95,7 @@ class CORSSupportE2ESpec extends E2ESpec(CORSSupportE2ESpec.config) {
}

"send `Access-Control-Allow-Origin` header when the api endpoint route is NOT found " in {
val request = Get(baseApiUrl + "/NotFound") ~> Origin(exampleOrigin)
val request = Get(baseApiUrl + "/NotFound") ~> Origin(exampleOrigin)
val response = singleAwaitingRequest(request)
response.status should equal(StatusCodes.NotFound)
response.headers should contain allElementsOf Seq(
Expand Down
Expand Up @@ -2911,7 +2911,7 @@ class OntologyV2R2RSpec extends R2RSpec {
}

// Successfully remove the (unused) text value cardinality from the class.
Delete("/v2/ontologies/cardinalities", HttpEntity(RdfMediaTypes.`application/ld+json`, params)) ~> addCredentials(
Patch("/v2/ontologies/cardinalities", HttpEntity(RdfMediaTypes.`application/ld+json`, params)) ~> addCredentials(
BasicHttpCredentials(anythingUsername, password)
) ~> ontologiesPath ~> check {
val responseStr = responseAs[String]
Expand Down