Skip to content

Commit

Permalink
feat: add default value of projectRestrictedViewSize (DEV-2626) (#2873)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 authored Oct 11, 2023
1 parent 82b715a commit ff4d3a1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
51 changes: 27 additions & 24 deletions docs/03-endpoints/api-admin/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@

# Projects Endpoint

| Scope | Route | Operations | Explanation |
| --------------- | -------------------------------------------------------------- |------------|-------------------------------------------------------------------------|
| projects | `/admin/projects` | `GET` | [get all projects](#get-all-projects) |
| projects | `/admin/projects` | `POST` | [create a project](#create-a-new-project) |
| projects | `/admin/projects/shortname/{shortname}` | `GET` | [get a single project](#get-project-by-id) |
| projects | `/admin/projects/shortcode/{shortcode}` | `GET` | [get a single project](#get-project-by-id) |
| projects | `/admin/projects/iri/{iri}` | `GET` | [get a single project](#get-project-by-id) |
| projects | `/admin/projects/iri/{iri}` | `PUT` | [update a project](#update-project-information) |
| projects | `/admin/projects/iri/{iri}` | `DELETE` | [delete a project](#delete-a-project) |
| projects | `/admin/projects/iri/{iri}/AllData` | `GET` | [get all data of a project](#get-all-data-of-a-project) |
| project members | `/admin/projects/shortname/{shortname}/members` | `GET` | [get all project members](#get-project-members-by-id) |
| project members | `/admin/projects/shortcode/{shortcode}/members` | `GET` | [get all project members](#get-project-members-by-id) |
| project members | `/admin/projects/iri/{iri}/members` | `GET` | [get all project members](#get-project-members-by-id) |
| project members | `/admin/projects/shortname/{shortname}/admin-members` | `GET` | [get all project admins](#get-project-admins-by-id) |
| project members | `/admin/projects/shortcode/{shortcode}/admin-members` | `GET` | [get all project admins](#get-project-admins-by-id) |
| project members | `/admin/projects/iri/{iri}/admin-members` | `GET` | [get all project admins](#get-project-admins-by-id) |
| keywords | `/admin/projects/Keywords` | `GET` | [get all project keywords](#get-all-keywords) |
| keywords | `/admin/projects/iri/{iri}/Keywords` | `GET` | [get project keywords of a single project](#get-keywords-of-a-project) |
| view settings | `/admin/projects/shortname/{shortname}/RestrictedViewSettings` | `GET` | [get restricted view settings for a project](#restricted-view-settings) |
| view settings | `/admin/projects/shortcode/{shortcode}/RestrictedViewSettings` | `GET` | [get restricted view settings for a project](#restricted-view-settings) |
| view settings | `/admin/projects/iri/{iri}/RestrictedViewSettings` | `GET` | [get restricted view settings for a project](#restricted-view-settings) |
| view settings | `/admin/projects/iri/{iri}/RestrictedViewSettings` | `POST` | [set restricted view settings for a project](#restricted-view-settings) |
| view settings | `/admin/projects/shortcode/{shortcode}/RestrictedViewSettings` | `POST` | [set restricted view settings for a project](#restricted-view-settings) |
| Scope | Route | Operations | Explanation |
| --------------- | -------------------------------------------------------------- |------------|-----------------------------------------------------------------------------|
| projects | `/admin/projects` | `GET` | [get all projects](#get-all-projects) |
| projects | `/admin/projects` | `POST` | [create a project](#create-a-new-project) |
| projects | `/admin/projects/shortname/{shortname}` | `GET` | [get a single project](#get-project-by-id) |
| projects | `/admin/projects/shortcode/{shortcode}` | `GET` | [get a single project](#get-project-by-id) |
| projects | `/admin/projects/iri/{iri}` | `GET` | [get a single project](#get-project-by-id) |
| projects | `/admin/projects/iri/{iri}` | `PUT` | [update a project](#update-project-information) |
| projects | `/admin/projects/iri/{iri}` | `DELETE` | [delete a project](#delete-a-project) |
| projects | `/admin/projects/iri/{iri}/AllData` | `GET` | [get all data of a project](#get-all-data-of-a-project) |
| project members | `/admin/projects/shortname/{shortname}/members` | `GET` | [get all project members](#get-project-members-by-id) |
| project members | `/admin/projects/shortcode/{shortcode}/members` | `GET` | [get all project members](#get-project-members-by-id) |
| project members | `/admin/projects/iri/{iri}/members` | `GET` | [get all project members](#get-project-members-by-id) |
| project members | `/admin/projects/shortname/{shortname}/admin-members` | `GET` | [get all project admins](#get-project-admins-by-id) |
| project members | `/admin/projects/shortcode/{shortcode}/admin-members` | `GET` | [get all project admins](#get-project-admins-by-id) |
| project members | `/admin/projects/iri/{iri}/admin-members` | `GET` | [get all project admins](#get-project-admins-by-id) |
| keywords | `/admin/projects/Keywords` | `GET` | [get all project keywords](#get-all-keywords) |
| keywords | `/admin/projects/iri/{iri}/Keywords` | `GET` | [get project keywords of a single project](#get-keywords-of-a-project) |
| view settings | `/admin/projects/shortname/{shortname}/RestrictedViewSettings` | `GET` | [get restricted view settings for a project](#get-restricted-view-settings) |
| view settings | `/admin/projects/shortcode/{shortcode}/RestrictedViewSettings` | `GET` | [get restricted view settings for a project](#get-restricted-view-settings) |
| view settings | `/admin/projects/iri/{iri}/RestrictedViewSettings` | `GET` | [get restricted view settings for a project](#get-restricted-view-settings) |
| view settings | `/admin/projects/iri/{iri}/RestrictedViewSettings` | `POST` | [set restricted view settings for a project](#set-restricted-view-settings) |
| view settings | `/admin/projects/shortcode/{shortcode}/RestrictedViewSettings` | `POST` | [set restricted view settings for a project](#set-restricted-view-settings) |

## Project Operations

Expand Down Expand Up @@ -161,7 +161,10 @@ Errors:

- `400 Bad Request` if the project already exists or any of the provided properties is invalid.
- `401 Unauthorized` if authorization failed.


### Default set of RestrictedViewSize
Starting from DSP 2023.10.02 release, the creation of new project will also set the `RestrictedViewSize` to default
value, which is: `!512,512`. It is possible to change the value using [dedicated routes](#set-restricted-view-settings).

#### Default set of permissions for a new project:
When a new project is created, following default permissions are added to its admins and members:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ object RestrictedViewSize {
def unsafeFrom(value: String): RestrictedViewSize =
make(value).fold(s => throw new IllegalArgumentException(s), identity)

def default: RestrictedViewSize = new RestrictedViewSize("!512,512") {}

implicit val codec: JsonCodec[RestrictedViewSize] =
JsonCodec[String].transformOrFail(RestrictedViewSize.make, _.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.util.UUID

import dsp.errors._
import dsp.valueobjects.Iri
import dsp.valueobjects.RestrictedViewSize
import dsp.valueobjects.V2
import org.knora.webapi._
import org.knora.webapi.config.AppConfig
Expand Down Expand Up @@ -807,17 +808,14 @@ final case class ProjectsResponderADMLive(

newProjectADM <- projectService
.findByProjectIdentifier(id)
.flatMap(ZIO.fromOption(_))
.orElseFail(
.someOrFail(
UpdateNotPerformedException(
s"Project $newProjectIRI was not created. Please report this as a possible bug."
)
)
// create permissions for admins and members of the new group
_ <- createPermissionsForAdminsAndMembersOfNewProject(newProjectIRI)
// TODO: DEV-2626 add default value here
// defaultSize = ""
// _ <- setProjectRestrictedViewSettings(id.value, requestingUser, defaultSize)
_ <- projectService.setProjectRestrictedViewSize(newProjectADM, RestrictedViewSize.default)

} yield ProjectOperationResponseADM(project = newProjectADM.unescape)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi.slice.admin.domain.service
import zio._

import dsp.valueobjects.Project.Shortcode
import dsp.valueobjects.RestrictedViewSize
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectADM
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM
Expand All @@ -25,6 +26,7 @@ trait ProjectADMService {
def findAllProjectsKeywords: Task[ProjectsKeywordsGetResponseADM]
def findProjectKeywordsBy(id: ProjectIdentifierADM): Task[Option[ProjectKeywordsGetResponseADM]]
def getNamedGraphsForProject(project: KnoraProject): Task[List[InternalIri]]
def setProjectRestrictedViewSize(project: ProjectADM, size: RestrictedViewSize): Task[Unit]
}

object ProjectADMService {
Expand Down Expand Up @@ -80,6 +82,20 @@ final case class ProjectADMServiceLive(
ontologies = ontologyIris.map(_.value)
).unescape

private def toKnoraProject(project: ProjectADM): KnoraProject =
KnoraProject(
id = InternalIri.apply(project.id),
shortname = project.shortname,
shortcode =
Shortcode.make(project.shortcode).getOrElse(throw new IllegalArgumentException("Should not happened.")),
longname = project.longname,
description = NonEmptyChunk.fromIterable(project.description.head, project.description.tail),
keywords = project.keywords.toList,
logo = project.logo,
status = project.status,
selfjoin = project.selfjoin
)

override def findAllProjectsKeywords: Task[ProjectsKeywordsGetResponseADM] =
for {
projects <- projectRepo.findAll()
Expand All @@ -100,6 +116,9 @@ final case class ProjectADMServiceLive(
.map(_.map(_.ontologyMetadata.ontologyIri.toInternalIri))
.map(_ :+ projectGraph)
}

override def setProjectRestrictedViewSize(project: ProjectADM, size: RestrictedViewSize): Task[Unit] =
projectRepo.setProjectRestrictedViewSize(toKnoraProject(project), size)
}

object ProjectADMServiceLive {
Expand Down

0 comments on commit ff4d3a1

Please sign in to comment.