Skip to content
Permalink
Browse files
refactor(ontology)!: use patch instead of delete for deleting cardina…
…lities (DSP-1700) (#1903)

* use put instead of delete for deleting cardinalities

* use patch instead of put for deleting cardinalities

* update r2r test

* add PATCH to list of allowed actions

* Update CORSSupportE2ESpec.scala

* Update ontology-information.md

* Remove unused code
  • Loading branch information
irinaschubert committed Sep 14, 2021
1 parent 719cd0d commit 91ef4ec0a810ed347702bbe49b470505eb3c3067
@@ -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
@@ -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:
@@ -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`
@@ -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 {
@@ -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)
@@ -51,30 +51,23 @@ 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
}

"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(
@@ -83,8 +76,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(
@@ -93,7 +87,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(
@@ -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]

0 comments on commit 91ef4ec

Please sign in to comment.