Skip to content

Commit

Permalink
Implemented /user-role endpoint #823
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Oct 10, 2023
1 parent c42e8b8 commit 9722e23
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion grails-app/views/paratoo/_projectRole.gson
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ model {
ParatooProject project
}

json([(project.id):project.paratooAccessLevel])
json([(project.id):[name:project.paratooAccessLevelName, type:project.paratooAccessLevelType]])
15 changes: 14 additions & 1 deletion src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProject.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,27 @@ class ParatooProject {
project.getMonitoringProtocolCategories()
}

String getParatooAccessLevel() {
String getParatooAccessLevelType() {
String paratooAccessLevel = READ_ONLY
switch (accessLevel) {
case AccessLevel.editor:
case AccessLevel.admin:
case AccessLevel.caseManager:
paratooAccessLevel = EDITABLE
break;
}
paratooAccessLevel
}

String getParatooAccessLevelName() {
String paratooAccessLevelName = 'Authenticated'
switch (accessLevel) {
case AccessLevel.editor:
case AccessLevel.admin:
case AccessLevel.caseManager:
paratooAccessLevelName = 'Project Admin'
break;
}
paratooAccessLevelName
}
}
7 changes: 4 additions & 3 deletions src/test/groovy/au/org/ala/ecodata/ParatooJsonViewSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ class ParatooJsonViewSpec extends Specification implements JsonViewTest {
when:
int[][] projectSpec = [[3, 1, 0], [0, 0, 1], [1, 0, 0]] as int[][]
List projects = buildProjectsForRendering(projectSpec)
projects[2].accessLevel = AccessLevel.readOnly

def result = render(view: "/paratoo/userRoles", model:[projects:projects])

then:"The json is correct"
result.json[0] == [(projects[0].id):'project_admin']
result.json[1] == [(projects[1].id):'project_admin']
result.json[2] == [(projects[2].id):'project_admin']
result.json[0] == [(projects[0].id):[name:"Project Admin", type:'project_admin']]
result.json[1] == [(projects[1].id):[name:"Project Admin", type:'project_admin']]
result.json[2] == [(projects[2].id):[name:"Authenticated", type:'authenticated']]

}

Expand Down

0 comments on commit 9722e23

Please sign in to comment.