diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eb95678..c59910c6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Added +- Space api routes now return users and creator. + ## 1.22.1 - 2023-11-10 ### Fixed diff --git a/app/api/Spaces.scala b/app/api/Spaces.scala index e48de645b..119655667 100644 --- a/app/api/Spaces.scala +++ b/app/api/Spaces.scala @@ -90,6 +90,16 @@ class Spaces @Inject()(spaces: SpaceService, case None => NotFound("Space not found") } } + def getUsers(id: UUID) = PermissionAction(Permission.ViewSpace, Some(ResourceRef(ResourceRef.space, id))) { implicit request => + spaces.get(id) match { + case Some(space) => + val usersInSpace = spaces.getUsersInSpace(space.id, None) + Ok(toJson(usersInSpace.map(userToJson))) + case None => { + NotFound("Space not found") + } + } + } def list(when: Option[String], title: Option[String], date: Option[String], limit: Int) = UserAction(needActive=false) { implicit request => Ok(toJson(listSpaces(when, title, date, limit, Set[Permission](Permission.ViewSpace), false, request.user, request.user.fold(false)(_.superAdminMode), true).map(spaceToJson))) @@ -167,9 +177,17 @@ class Spaces @Inject()(spaces: SpaceService, toJson(Map("id" -> space.id.stringify, "name" -> space.name, "description" -> space.description, + "creator" -> space.creator.stringify, "created" -> space.created.toString)) } + def userToJson(user: User) = { + toJson(Map("id" -> user.id.stringify, + "email" -> user.email.get + )) + } + + def addCollectionToSpace(spaceId: UUID, collectionId: UUID) = PermissionAction(Permission.AddResourceToSpace, Some(ResourceRef(ResourceRef.space, spaceId))) { implicit request => (spaces.get(spaceId), collectionService.get(collectionId)) match { diff --git a/conf/routes b/conf/routes index 786757f97..916f716ba 100644 --- a/conf/routes +++ b/conf/routes @@ -488,6 +488,7 @@ GET /api/files/:three_d_file_id/:filename GET /api/spaces @api.Spaces.list(when: Option[String] ?= None, title: Option[String] ?= None, date: Option[String] ?= None, limit: Int ?= 12) GET /api/spaces/canEdit @api.Spaces.listCanEdit(when: Option[String] ?= None, title: Option[String] ?= None, date: Option[String] ?= None, limit: Int ?= 12) GET /api/spaces/:id @api.Spaces.get(id: UUID) +GET /api/spaces/:id/users @api.Spaces.getUsers(id: UUID) POST /api/spaces @api.Spaces.createSpace() DELETE /api/spaces/:id @api.Spaces.removeSpace(id: UUID) POST /api/spaces/:spaceId/removeCollection/:collectionId @api.Spaces.removeCollection(spaceId: UUID, collectionId: UUID, removeDatasets : Boolean)