Skip to content

Commit 4d61de0

Browse files
committed
adding new route for getting users in space
1 parent 17c5da2 commit 4d61de0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

app/api/Spaces.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ class Spaces @Inject()(spaces: SpaceService,
9090
case None => NotFound("Space not found")
9191
}
9292
}
93+
def getUsers(id: UUID) = PermissionAction(Permission.ViewSpace, Some(ResourceRef(ResourceRef.space, id))) { implicit request =>
94+
spaces.get(id) match {
95+
case Some(space) =>
96+
97+
val usersInSpace = spaces.getUsersInSpace(space.id, None)
98+
99+
Ok(toJson(usersInSpace.map(userToJson)))
100+
case None => {
101+
NotFound("Space not found")
102+
}
103+
}
104+
}
93105

94106
def list(when: Option[String], title: Option[String], date: Option[String], limit: Int) = UserAction(needActive=false) { implicit request =>
95107
Ok(toJson(listSpaces(when, title, date, limit, Set[Permission](Permission.ViewSpace), false, request.user, request.user.fold(false)(_.superAdminMode), true).map(spaceToJson)))
@@ -171,6 +183,13 @@ class Spaces @Inject()(spaces: SpaceService,
171183
"created" -> space.created.toString))
172184
}
173185

186+
def userToJson(user: User) = {
187+
toJson(Map("id" -> user.id.stringify,
188+
"email" -> user.email.get
189+
))
190+
}
191+
192+
174193
def addCollectionToSpace(spaceId: UUID, collectionId: UUID) = PermissionAction(Permission.AddResourceToSpace, Some(ResourceRef(ResourceRef.space, spaceId))) {
175194
implicit request =>
176195
(spaces.get(spaceId), collectionService.get(collectionId)) match {

conf/routes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ GET /api/files/:three_d_file_id/:filename
488488
GET /api/spaces @api.Spaces.list(when: Option[String] ?= None, title: Option[String] ?= None, date: Option[String] ?= None, limit: Int ?= 12)
489489
GET /api/spaces/canEdit @api.Spaces.listCanEdit(when: Option[String] ?= None, title: Option[String] ?= None, date: Option[String] ?= None, limit: Int ?= 12)
490490
GET /api/spaces/:id @api.Spaces.get(id: UUID)
491+
GET /api/spaces/:id/users @api.Spaces.getUsers(id: UUID)
491492
POST /api/spaces @api.Spaces.createSpace()
492493
DELETE /api/spaces/:id @api.Spaces.removeSpace(id: UUID)
493494
POST /api/spaces/:spaceId/removeCollection/:collectionId @api.Spaces.removeCollection(spaceId: UUID, collectionId: UUID, removeDatasets : Boolean)

0 commit comments

Comments
 (0)