Skip to content

Commit

Permalink
Merge pull request #851 from AtlasOfLivingAustralia/feature/issue850
Browse files Browse the repository at this point in the history
devt.ala.org.au->localhost, delete unused role migration code #850
  • Loading branch information
salomon-j authored Jul 18, 2023
2 parents b3fb2fe + 93864b7 commit ed8cc9d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 88 deletions.
19 changes: 11 additions & 8 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ grails.cache.config = {
security {
cas {
enabled = false
appServerName = 'http://devt.ala.org.au:8080' // or similar, up to the request path part
// service = 'http://devt.ala.org.au:8080' // optional, if set it will always be used as the return path from CAS
appServerName = 'http://localhost:8080' // or similar, up to the request path part
casServerUrlPrefix = 'https://auth-test.ala.org.au/cas'
loginUrl = 'https://auth-test.ala.org.au/cas/login'
logoutUrl = 'https://auth-test.ala.org.au/cas/logout'
Expand Down Expand Up @@ -605,6 +604,10 @@ security {
readTimeoutMs = 20000
}
}
webservice.jwt = true
webservice['jwt-scopes'] = "ala/internal users/read ala/attrs users/read"
webservice['client-id']='changeMe'
webservice['client-secret'] = 'changeMe'

grails.gorm.graphql.browser = true

Expand All @@ -613,10 +616,10 @@ environments {
grails.logging.jul.usebridge = true
ecodata.use.uuids = false
app.external.model.dir = "/data/ecodata/models/" //"./models/"
grails.hostname = "devt.ala.org.au"
grails.hostname = "localhost"
app.elasticsearch.indexAllOnStartup = false
app.elasticsearch.indexOnGormEvents = true
grails.serverURL = "http://devt.ala.org.au:8080"
grails.serverURL = "http://${grails.hostname}:8080"
app.uploads.url = "/document/download/"
grails.mail.host="localhost"
grails.mail.port=1025
Expand All @@ -632,7 +635,7 @@ environments {
grails.logging.jul.usebridge = true
ecodata.use.uuids = false
app.external.model.dir = "./models/"
grails.hostname = "devt.ala.org.au"
grails.hostname = "localhost"
// Only for travis CI, they must be overriden by ecodata-config.properties
serverName = "http://${grails.hostname}:8080"
grails.app.context = "ecodata"
Expand All @@ -651,7 +654,7 @@ environments {

wiremock.port = 8018
security.cas.bypass = true
security.cas.casServerUrlPrefix="http://devt.ala.org.au:${wiremock.port}/cas"
security.cas.casServerUrlPrefix="http://localhost:${wiremock.port}/cas"
security.cas.loginUrl="${security.cas.casServerUrlPrefix}/login"
}
meritfunctionaltest {
Expand All @@ -664,7 +667,7 @@ environments {
grails.logging.jul.usebridge = true
ecodata.use.uuids = false
app.external.model.dir = "./models/"
grails.serverURL = "http://devt.ala.org.au:8080"
grails.serverURL = "http://localshot:8080"
app.uploads.url = "${grails.serverURL}/document/download?filename="

app.elasticsearch.indexOnGormEvents = true
Expand All @@ -675,7 +678,7 @@ environments {
wiremock.port = 8018
security.oidc.discoveryUri = "http://localhost:${wiremock.port}/cas/oidc/.well-known"
security.oidc.allowUnsignedIdTokens = true
def casBaseUrl = "http://devt.ala.org.au:${wiremock.port}"
def casBaseUrl = "http://localhost:${wiremock.port}"
security.cas.casServerName="${casBaseUrl}"
security.cas.contextPath=""
security.cas.casServerUrlPrefix="${casBaseUrl}/cas"
Expand Down
2 changes: 1 addition & 1 deletion grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ graphiql:


casUrl: https://auth-test.ala.org.au/cas/logout
appUrl: http://devt.ala.org.au:8080/admin
appUrl: http://localhost:8080/admin


openapi:
Expand Down
75 changes: 0 additions & 75 deletions grails-app/services/au/org/ala/ecodata/PermissionService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -643,53 +643,6 @@ class PermissionService {
return count > 0
}

/**
* This code snippet is based on ReportService.userSummary
* Produces a list of users containing roles below:
* (ROLE_FC_READ_ONLY,ROLE_FC_OFFICER,ROLE_FC_ADMIN)
*/
private def extractUserDetails() {
List roles = ['ROLE_FC_READ_ONLY', 'ROLE_FC_OFFICER', 'ROLE_FC_ADMIN']
def userDetailsSummary = [:]

int batchSize = 500

String url = grailsApplication.config.getProperty('userDetails.admin.url')
url += "/userRole/list?format=json&max=${batchSize}&role="
roles.each { role ->
int offset = 0
Map result = webService.getJson(url+role+'&offset='+offset)

while (offset < result?.count && !result?.error) {

List usersForRole = result?.users ?: []
usersForRole.each { user ->
if (userDetailsSummary[user.userId]) {
userDetailsSummary[user.userId].role = role
}
else {
user.projects = []
user.name = (user.firstName ?: "" + " " +user.lastName ?: "").trim()
user.role = role
userDetailsSummary[user.userId] = user
}


}

offset += batchSize
result = webService.getJson(url+role+'&offset='+offset)
}

if (!result || result.error) {
log.error("Error getting user details for role: "+role)
return
}
}

userDetailsSummary
}

/**
* This method finds the hubId of the entity specified in the supplied UserPermission.
* Currently only Project, Organisation, ManagementUnit, Program are supported.
Expand All @@ -709,34 +662,6 @@ class PermissionService {
hubId
}

def saveUserDetails() {
def map = [ROLE_FC_ADMIN: "admin", ROLE_FC_OFFICER: "caseManager", ROLE_FC_READ_ONLY: "readOnly"]
String urlPath = "merit"
String hubId = hubService.findByUrlPath(urlPath)?.hubId

//extracts from UserDetails
def userDetailsSummary = extractUserDetails()

//save to userPermission
userDetailsSummary.each { key, value ->
value.roles.each { role ->
if (map[role]) {
UserPermission userP = UserPermission.findByUserIdAndEntityIdAndEntityType(key, hubId, Hub.name)
try {
if (!userP) {
UserPermission up = new UserPermission(userId: key, entityId: hubId, entityType: Hub.name, accessLevel: AccessLevel.valueOf(map[role]))
up.save(flush: true, failOnError: true)
}
} catch (Exception e) {
def msg = "Failed to save UserPermission: ${e.message}"
return [status: 'error', error: msg]
}
}

}
}
}

private Map saveUserToHubEntity(Map params) {
UserPermission up = UserPermission.findByUserIdAndEntityIdAndEntityType(params.userId, params.entityId, Hub.name)
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"servers":[
{
"url":"http://devt.ala.org.au:8080"
"url":"http://localhost:8080"
}
],
"paths":{
Expand Down
6 changes: 3 additions & 3 deletions src/test/groovy/au/org/ala/ecodata/SchemaBuilderSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SchemaBuilderSpec extends Specification implements GrailsUnitTest {

then:
schema == [
id:"http://devt.ala.org.au:8080/ecodata/ws/documentation/draft/output/Test%20Output",
id:"http://localhost:8080/ecodata/ws/documentation/draft/output/Test%20Output",
$schema:"http://json-schema.org/draft-04/schema#",
type:"object",
properties:[
Expand All @@ -111,7 +111,7 @@ class SchemaBuilderSpec extends Specification implements GrailsUnitTest {

then:
schema == [
id:"http://devt.ala.org.au:8080/ecodata/ws/documentation/draft/output/Test%20Output",
id:"http://localhost:8080/ecodata/ws/documentation/draft/output/Test%20Output",
$schema:"http://json-schema.org/draft-04/schema#",
type:"object",
properties:[
Expand Down Expand Up @@ -140,7 +140,7 @@ class SchemaBuilderSpec extends Specification implements GrailsUnitTest {

then:
schema == [
id:"http://devt.ala.org.au:8080/ecodata/ws/documentation/draft/output/Test%20Output",
id:"http://localhost:8080/ecodata/ws/documentation/draft/output/Test%20Output",
$schema:"http://json-schema.org/draft-04/schema#",
type:"object",
properties:[
Expand Down

0 comments on commit ed8cc9d

Please sign in to comment.