Skip to content

Commit

Permalink
refactor(ontology)!: use patch instead of delete for deleting cardina…
Browse files Browse the repository at this point in the history
…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 91ef4ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
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
30 changes: 12 additions & 18 deletions webapi/src/test/scala/org/knora/webapi/e2e/CORSSupportE2ESpec.scala
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,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(
Expand All @@ -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(
Expand All @@ -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(
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

0 comments on commit 91ef4ec

Please sign in to comment.