Skip to content

Commit 892a910

Browse files
authored
Merge pull request #3475 from AtlasOfLivingAustralia/feature/issue3470
Feature/issue3470
2 parents 841e2b9 + 986a32a commit 892a910

File tree

8 files changed

+161
-19
lines changed

8 files changed

+161
-19
lines changed

grails-app/controllers/au/org/ala/merit/ProjectController.groovy

+7-7
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ class ProjectController {
986986
render results as JSON
987987
}
988988

989-
@PreAuthorise
989+
@PreAuthorise(accessLevel = 'readOnly')
990990
def scoresForReport(String id) {
991991
List scoreIds = params.getList('scoreIds')
992992
String reportId = params.get('reportId')
@@ -996,7 +996,7 @@ class ProjectController {
996996
render result as JSON
997997
}
998998

999-
@PreAuthorise(accessLevel = 'editor')
999+
@PreAuthorise(accessLevel = 'readOnly')
10001000
def projectTargetsAndScores(String id) {
10011001
boolean approvedDataOnly = params.getBoolean("approvedDataOnly", true)
10021002
Map result = projectService.getServiceDashboardData(id, approvedDataOnly)
@@ -1026,7 +1026,7 @@ class ProjectController {
10261026
render response as JSON
10271027
}
10281028

1029-
@PreAuthorise(accessLevel = 'editor')
1029+
@PreAuthorise(accessLevel = 'readOnly')
10301030
def targetsAndScoresForActivity(String id, String activityId) {
10311031
if (!id || !activityId || !projectService.doesActivityBelongToProject(id, activityId)) {
10321032
error('An invalid activity was selected', id)
@@ -1128,19 +1128,19 @@ class ProjectController {
11281128
* @param id the project id of the project of interest
11291129
* @return a List of outcomes selected in the project MERI plan
11301130
*/
1131-
@PreAuthorise(accessLevel = 'editor')
1131+
@PreAuthorise(accessLevel = 'readOnly')
11321132
def listProjectInvestmentPriorities(String id) {
11331133
List investmentPriorities = projectService.listProjectInvestmentPriorities(id)
11341134
investmentPriorities << "Other"
11351135
render investmentPriorities as JSON
11361136
}
11371137

1138-
@PreAuthorise(accessLevel = 'editor')
1138+
@PreAuthorise(accessLevel = 'readOnly')
11391139
def projectPrioritiesByOutcomeType(String id) {
11401140
render projectService.projectPrioritiesByOutcomeType(id) as JSON
11411141
}
11421142

1143-
@PreAuthorise(accessLevel = 'editor')
1143+
@PreAuthorise(accessLevel = 'readOnly')
11441144
def monitoringProtocolFormCategories() {
11451145
String MONITORING_TAG = 'survey'
11461146
List<Map> forms = activityService.monitoringProtocolForms()
@@ -1150,7 +1150,7 @@ class ProjectController {
11501150
render categories as JSON
11511151
}
11521152

1153-
@PreAuthorise(accessLevel = 'editor')
1153+
@PreAuthorise(accessLevel = 'readOnly')
11541154
def outcomesByScores(String id) {
11551155
List scoreIds = params.getList('scoreIds')
11561156
if (!scoreIds) {

grails-app/services/au/org/ala/merit/ImageService.groovy

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.drew.metadata.exif.GpsDirectory
99
import groovy.util.logging.Slf4j
1010
import groovyx.net.http.HttpResponseDecorator
1111
import grails.core.GrailsApplication
12+
import org.apache.http.HttpStatus
1213

1314
@Slf4j
1415
class ImageService {
@@ -23,14 +24,14 @@ class ImageService {
2324
* @return true if the thumbail was generated.
2425
*/
2526
boolean createThumbnail(InputStream imageIn, File thumbnailFile, String contentType, int size = 300) {
26-
Closure saveThumbnail = { HttpResponseDecorator resp, Object parsedData ->
27-
if (parsedData instanceof InputStream) {
28-
new FileOutputStream(thumbnailFile).withStream { it << parsedData }
27+
28+
Map resp = webService.postMultipart(grailsApplication.config.getProperty('ecodata.baseUrl') + "document/createThumbnail", [size: size], imageIn, contentType, thumbnailFile.name, 'image')
29+
if (resp.statusCode == HttpStatus.SC_OK) {
30+
def thumbnailData = resp.resp
31+
if (thumbnailData instanceof byte[]) {
32+
new FileOutputStream(thumbnailFile).withStream { it << new ByteArrayInputStream(thumbnailData) }
2933
}
3034
}
31-
32-
webService.postMultipart(grailsApplication.config.getProperty('ecodata.baseUrl') + "document/createThumbnail", [size: size], imageIn, contentType, thumbnailFile.name, 'image', saveThumbnail)
33-
3435
return thumbnailFile.exists()
3536

3637
}

src/integration-test/groovy/au/org/ala/fieldcapture/ConfigurableMeriPlanSpec.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class ConfigurableMeriPlanSpec extends StubbedCasSpec {
1616
loginAsAlaAdmin(browser)
1717
to AdminClearCachePage
1818
clearProgramListCache()
19+
at AdminClearCachePage // reset at check time.
1920
clearServiceListCache()
21+
at AdminClearCachePage // reset at check time.
2022
clearProtocolListCache()
2123
}
2224

src/integration-test/groovy/au/org/ala/fieldcapture/HelpLinksSpec.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HelpLinksSpec extends StubbedCasSpec {
2020

2121
when: "Clear the help links cache as other specs will have run caching zero links"
2222
to AdminClearCachePage
23-
homePageDocuments.click()
23+
clearHomePageDocuments()
2424
logout(browser)
2525

2626
then:

src/integration-test/groovy/au/org/ala/fieldcapture/OrganisationDocumentSpec.groovy

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ class OrganisationDocumentsSpec extends StubbedCasSpec {
1313
loginAsAlaAdmin(browser)
1414
to AdminClearCachePage
1515
clearProgramListCache()
16+
at AdminClearCachePage // reset at check time
1617
clearServiceListCache()
1718
}
1819

19-
def cleanup() {
20-
logout(browser)
21-
}
22-
23-
2420
def "documents can be attached to a organisation"() {
2521

2622
setup:

src/integration-test/groovy/pages/AdminClearCachePage.groovy

+8
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@ class AdminClearCachePage extends ReloadablePage {
5252
waitFor { hasBeenReloaded() }
5353
}
5454
}
55+
56+
void clearHomePageDocuments() {
57+
if (homePageDocuments.displayed) {
58+
homePageDocuments.click()
59+
60+
waitFor { hasBeenReloaded() }
61+
}
62+
}
5563
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
load('../../../utils/audit.js');
2+
load('../../../utils/reports.js');
3+
const adminUserId = 'system';
4+
let project=db.project.findOne({projectId:'f4a0642b-49b7-4ec3-9be5-e7e65a25cb78'});
5+
let dataSets=project.custom.dataSets;
6+
print(project.custom.dataSets.length);
7+
let deleteCount =0;
8+
function removeDataSet(dataSets, badSurveyUuid, goodDataSetId, deleteStarted) {
9+
for (let i=0; i<dataSets.length; i++) {
10+
let dataSet=dataSets[i];
11+
if (dataSet.surveyId) {
12+
if (dataSet.surveyId.survey_metadata.survey_details.uuid == badSurveyUuid) {
13+
14+
if (dataSet.progress != 'planned') {
15+
if (deleteStarted && dataSet.progress == 'started') {
16+
if (dataSet.dataSetId != goodDataSetId) {
17+
print("Deleting dataset: " + dataSet.dataSetId + " for survey: " + badSurveyUuid+ " with name: " + dataSet.name + " in started state");
18+
deleteActivity(dataSet.activityId, adminUserId);
19+
// remove the dataset from the array
20+
dataSets.splice(i, 1);
21+
deleteCount++;
22+
return dataSets;
23+
}
24+
}
25+
else {
26+
print("Warning dataset is not in planned state: " + dataSet.dataSetId + ", "+dataSet.name);
27+
}
28+
29+
30+
} else {
31+
print("Deleting dataset: " + dataSet.dataSetId + " for survey: " + badSurveyUuid+ " with name: " + dataSet.name+ " in planned state");
32+
33+
// remove the dataset from the array
34+
dataSets.splice(i, 1);
35+
deleteCount++;
36+
return dataSets;
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
function deleteAndUpdate(badSurveyId, goodDatasetId, deleteStarted) {
44+
deleteCount = 0;
45+
let dataSets = project.custom.dataSets;
46+
47+
while (dataSets) {
48+
dataSets = removeDataSet(dataSets, badSurveyUuid, goodDatasetId, deleteStarted);
49+
}
50+
print("Deleted " + deleteCount+ " datasets with survey uuid " + badSurveyUuid);
51+
print(project.custom.dataSets.length);
52+
53+
db.project.replaceOne({projectId:project.projectId}, project);
54+
audit(project, project.projectId, 'au.org.ala.ecodata.Project', 'system', project.projectId);
55+
}
56+
57+
// Cover - enhanced
58+
let badSurveyUuid = '3d4940ef-2eca-4a87-b2d2-4b228dbd499e';
59+
deleteAndUpdate(badSurveyUuid);
60+
61+
// Photopoints
62+
badSurveyUuid = '9b5360ce-5b4e-478f-b006-0292e22870ba';
63+
goodDataSetId = '40982ac4-8464-4d1a-a1da-9dc7c1ae979d';
64+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
65+
66+
// FLoristics
67+
badSurveyUuid = '7a635ab4-c871-4a4b-8b69-94c5d83a56d2';
68+
goodDataSetId = 'f57b2b34-bdc7-4e91-b28f-5e231f63cad5';
69+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
70+
71+
// Floristics
72+
badSurveyUuid = '955ebed3-bc05-4353-abcb-bf1c3e1c98db';
73+
goodDataSetId = 'a941dbe7-9a0f-4f84-a3ce-f51d0c39f8f9';
74+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
75+
76+
// Floristics
77+
badSurveyUuid = '6a970b22-4521-469c-ac79-a83ef7c2d0d1';
78+
goodDataSetId = 'c4bdd5ad-6f92-494a-99d6-bb3dc887b733';
79+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
80+
81+
// Floristics
82+
badSurveyUuid = '1ed22901-469a-4ee6-985e-dbec17780cb1';
83+
goodDataSetId = '582afd5a-567e-4616-b658-29f5a597f1e9';
84+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
85+
86+
// Floristics
87+
badSurveyUuid = '852382f0-1526-4c7e-bb02-7edf6c369840';
88+
goodDataSetId = 'f4b6b130-fa9a-4a38-8408-14f3b934c496';
89+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
90+
91+
// Floristics
92+
badSurveyUuid = 'b6f3f4db-9e83-44db-aac1-859b7dae06d6';
93+
goodDataSetId = '04a6397b-1443-49fe-83d6-354f51fe7021';
94+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
95+
96+
// Floristics
97+
badSurveyUuid = '5ddc8adf-ecbb-4221-ac52-d75ca20e7442';
98+
goodDataSetId = '6b3ab834-4037-4ab8-9dd4-b376682144f4';
99+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
100+
101+
badSurveyUuid = '9d4defe3-c1fb-43b9-9594-06c00ecb6729';
102+
deleteAndUpdate(badSurveyUuid);
103+
104+
badSurveyUuid = 'be49fe0d-8d97-4a62-9ec5-c45f171d7c8e';
105+
deleteAndUpdate(badSurveyUuid);
106+
107+
// Floristics
108+
badSurveyUuid = 'd1ab3343-761d-4a6e-b47e-0c3001d72f5a';
109+
goodDataSetId = 'c0d1bc94-f965-4f3e-977f-c671fbcbe1f1';
110+
deleteAndUpdate(badSurveyUuid, goodDataSetId, true);
111+

src/main/scripts/utils/reports.js

+24
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,28 @@ function createReportForProject(reportDetails, project, adminUserId) {
282282
let savedActivity = db.activity.findOne({activityId:activity.activityId});
283283
audit(savedActivity, savedActivity.activityId, 'au.org.ala.ecodata.Activity', adminUserId, project.projectId);
284284

285+
}
286+
287+
288+
function deleteActivity(activityId, adminUserId) {
289+
290+
291+
let activity = db.activity.findOne({activityId: activityId});
292+
print("deleting activity: "+activityId+" "+activity.description);
293+
if (activity) {
294+
activity.status = 'deleted';
295+
296+
db.activity.replaceOne({activityId: activityId}, activity);
297+
audit(activity, activity.activityId, 'au.org.ala.ecodata.Activity', adminUserId, activity.projectId);
298+
299+
let outputs = db.output.find({activityId: activityId});
300+
while (outputs.hasNext()) {
301+
let output = outputs.next();
302+
output.status = 'deleted';
303+
print("deleting output: "+output.outputId+" "+output.name);
304+
db.output.replaceOne({outputId: output.outputId}, output);
305+
audit(output, output.outputId, 'au.org.ala.ecodata.Output', adminUserId, activity.projectId);
306+
}
307+
}
308+
285309
}

0 commit comments

Comments
 (0)