From 8dbdf0348c386cd6921c9395ddc4a0b85672b062 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 22 Oct 2023 09:30:46 +1100 Subject: [PATCH 1/2] Support publicationStatus for sites #3011 --- grails-app/assets/javascripts/common-bs4.js | 10 ++++++ grails-app/assets/javascripts/sites.js | 1 + .../au/org/ala/merit/ProjectService.groovy | 3 +- .../au/org/ala/merit/ReportService.groovy | 11 ++----- .../au/org/ala/merit/SiteService.groovy | 4 +++ grails-app/views/site/_sitesList.gsp | 6 ++-- grails-app/views/site/index.gsp | 2 +- .../au/org/ala/merit/PublicationStatus.groovy | 22 +++++++++++++ .../Reef2050PlanActionReportCommand.groovy | 3 +- ...f2050PlanActionReportSummaryCommand.groovy | 5 ++- .../ala/merit/reports/ReportGenerator.groovy | 6 ++-- .../org/ala/merit/ProjectServiceSpec.groovy | 28 ++++++++-------- .../au/org/ala/merit/ReportServiceSpec.groovy | 27 +++++++-------- ...0PlanActionReportSummaryCommandSpec.groovy | 8 ++--- .../command/SaveReportDataCommandSpec.groovy | 33 ++++++++++--------- 15 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 src/main/groovy/au/org/ala/merit/PublicationStatus.groovy diff --git a/grails-app/assets/javascripts/common-bs4.js b/grails-app/assets/javascripts/common-bs4.js index 7ee7ee8a3..5e7254d05 100644 --- a/grails-app/assets/javascripts/common-bs4.js +++ b/grails-app/assets/javascripts/common-bs4.js @@ -56,3 +56,13 @@ ReportStatus = { return status && status.toLowerCase() == this.CANCELLED; } } + +PublicationStatus = { + PUBLISHED: 'published', + SUBMITTED: 'pendingApproval', + UNPUBLISHED: '', + + isReadOnly: function(status) { + return status && status != this.UNPUBLISHED; + } +} diff --git a/grails-app/assets/javascripts/sites.js b/grails-app/assets/javascripts/sites.js index fa9e979e9..ebac69591 100644 --- a/grails-app/assets/javascripts/sites.js +++ b/grails-app/assets/javascripts/sites.js @@ -994,6 +994,7 @@ var SitesViewModel = function(sites, map, mapFeatures, isUserEditor, projectId) if (!site.type) { site.type = 'worksArea'; } + site.readOnly = site.type == 'compound' || PublicationStatus.isReadOnly(site.publicationStatus); return site; }); self.selectedSiteIds = ko.computed(function() { diff --git a/grails-app/services/au/org/ala/merit/ProjectService.groovy b/grails-app/services/au/org/ala/merit/ProjectService.groovy index 72ac395dd..f02dcada8 100644 --- a/grails-app/services/au/org/ala/merit/ProjectService.groovy +++ b/grails-app/services/au/org/ala/merit/ProjectService.groovy @@ -1,6 +1,7 @@ package au.org.ala.merit import au.org.ala.merit.config.EmailTemplate +import au.org.ala.merit.PublicationStatus import au.org.ala.merit.config.ProgramConfig import au.org.ala.merit.config.ReportConfig import au.org.ala.merit.reports.ReportGenerationOptions @@ -606,7 +607,7 @@ class ProjectService { // Some projects have extra stage reports after the end date due to legacy data so this checks we've got the last stage within the project dates List validReports = project.reports?.findAll{it.fromDate < project.plannedEndDate ? it.fromDate : project.plannedStartDate} - List incompleteReports = (validReports?.findAll{it.publicationStatus != ReportService.REPORT_APPROVED && it.publicationStatus != ReportService.REPORT_CANCELLED})?:[] + List incompleteReports = (validReports?.findAll{PublicationStatus.requiresAction(it.publicationStatus)})?:[] return incompleteReports.size() ==1 && incompleteReports[0].reportId == approvedReportId } diff --git a/grails-app/services/au/org/ala/merit/ReportService.groovy b/grails-app/services/au/org/ala/merit/ReportService.groovy index 83d7e0b7f..0a06c4274 100644 --- a/grails-app/services/au/org/ala/merit/ReportService.groovy +++ b/grails-app/services/au/org/ala/merit/ReportService.groovy @@ -14,11 +14,6 @@ import org.joda.time.Period @Slf4j class ReportService { - public static final String REPORT_APPROVED = 'published' - public static final String REPORT_SUBMITTED = 'pendingApproval' - public static final String REPORT_NOT_APPROVED = 'unpublished' - public static final String REPORT_CANCELLED = 'cancelled' - public static final int HOME_PAGE_IMAGE_SIZE = 500 public static final String REPORT_TYPE_SINGLE_ACTIVITY = 'Single' @@ -168,11 +163,11 @@ class ReportService { } boolean excludesNotApproved(Map report) { - return report.publicationStatus == REPORT_SUBMITTED || report.publicationStatus == REPORT_APPROVED || report.publicationStatus == REPORT_CANCELLED + return PublicationStatus.isReadOnly(report.publicationStatus) } boolean isApproved(Map report) { - return report.publicationStatus == REPORT_APPROVED + return PublicationStatus.isApproved(report.publicationStatus) } List search(Map criteria) { @@ -887,7 +882,7 @@ class ReportService { Map filter = state?[type:'DISCRETE', property:'data.state']:[:] Map config = [groups:filter, childAggregations: aggregations, label:'Performance assessment by state'] - Map searchCriteria = [type:['Performance Management Framework - Self Assessment', 'Performance Management Framework - Self Assessment v2'], publicationStatus:REPORT_APPROVED, dateProperty:'toDate', 'startDate':(year-1)+'-07-01T10:00:00Z', 'endDate':year+'-07-01T10:00:00Z'] + Map searchCriteria = [type:['Performance Management Framework - Self Assessment', 'Performance Management Framework - Self Assessment v2'], publicationStatus:PublicationStatus.APPROVED, dateProperty:'toDate', 'startDate':(year-1)+'-07-01T10:00:00Z', 'endDate':year+'-07-01T10:00:00Z'] String url = grailsApplication.config.getProperty('ecodata.baseUrl')+"report/runReport" diff --git a/grails-app/services/au/org/ala/merit/SiteService.groovy b/grails-app/services/au/org/ala/merit/SiteService.groovy index a7f60c513..7397c5fff 100644 --- a/grails-app/services/au/org/ala/merit/SiteService.groovy +++ b/grails-app/services/au/org/ala/merit/SiteService.groovy @@ -26,6 +26,10 @@ class SiteService { /** A site with the extent derived from the convex hull of a set of geojson features */ public static final String SITE_TYPE_COMPOUND = 'compound' + static isReadOnly(Map site) { + site?.type == SITE_TYPE_COMPOUND || PublicationStatus.isReadOnly(site.publicationStatus) + } + def projectsForSite(siteId) { get(siteId)?.projects } diff --git a/grails-app/views/site/_sitesList.gsp b/grails-app/views/site/_sitesList.gsp index 49ec5335d..b31bec499 100644 --- a/grails-app/views/site/_sitesList.gsp +++ b/grails-app/views/site/_sitesList.gsp @@ -42,13 +42,13 @@ - + - + - + diff --git a/grails-app/views/site/index.gsp b/grails-app/views/site/index.gsp index b27c9e4fb..f9cd73861 100644 --- a/grails-app/views/site/index.gsp +++ b/grails-app/views/site/index.gsp @@ -59,7 +59,7 @@ Site Actions:
- + diff --git a/src/main/groovy/au/org/ala/merit/PublicationStatus.groovy b/src/main/groovy/au/org/ala/merit/PublicationStatus.groovy new file mode 100644 index 000000000..e5782ab4b --- /dev/null +++ b/src/main/groovy/au/org/ala/merit/PublicationStatus.groovy @@ -0,0 +1,22 @@ +package au.org.ala.merit + +class PublicationStatus { + public static final String APPROVED = 'published' + public static final String SUBMITTED = 'pendingApproval' + public static final String NOT_APPROVED = 'unpublished' + public static final String CANCELLED = 'cancelled' + + static boolean isReadOnly(publicationStatus) { + // A null/blank publication status is treated the same as a NOT_APPROVED status + publicationStatus == APPROVED || publicationStatus == SUBMITTED || publicationStatus == CANCELLED + } + + static boolean isApproved(publicationStatus) { + publicationStatus == APPROVED + } + + /** A status indicates the item requires further action when it is not yet approved or cancelled */ + static boolean requiresAction(publicationStatus) { + publicationStatus != APPROVED && publicationStatus != CANCELLED + } +} diff --git a/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportCommand.groovy b/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportCommand.groovy index cc6eb7260..297c25e1f 100644 --- a/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportCommand.groovy +++ b/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportCommand.groovy @@ -3,6 +3,7 @@ package au.org.ala.merit.command import au.org.ala.merit.ActivityService import au.org.ala.merit.DateUtils import au.org.ala.merit.ProjectService +import au.org.ala.merit.PublicationStatus import au.org.ala.merit.ReportService import au.org.ala.merit.SettingPageType import au.org.ala.merit.SettingService @@ -109,7 +110,7 @@ class Reef2050PlanActionReportCommand extends Reef2050PlanActionReportConfig imp progress:ActivityService.PROGRESS_FINISHED] if (approvedActivitiesOnly) { - searchCriteria.publicationStatus = ReportService.REPORT_APPROVED + searchCriteria.publicationStatus = PublicationStatus.APPROVED } Map resp diff --git a/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommand.groovy b/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommand.groovy index 16fef5e68..ddb403597 100644 --- a/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommand.groovy +++ b/src/main/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommand.groovy @@ -1,8 +1,7 @@ package au.org.ala.merit.command import au.org.ala.merit.ActivityService -import au.org.ala.merit.DateUtils -import au.org.ala.merit.ReportService +import au.org.ala.merit.PublicationStatus import au.org.ala.merit.reports.Reef2050PlanActionReportConfig import grails.converters.JSON import grails.validation.Validateable @@ -41,7 +40,7 @@ class Reef2050PlanActionReportSummaryCommand implements Validateable{ [type : Reef2050PlanActionReportConfig.REEF_2050_PLAN_ACTION_REPORTING_2018_ACTIVITY_TYPE, progress: ActivityService.PROGRESS_FINISHED] if (approvedActivitiesOnly) { - searchCriteria.publicationStatus = ReportService.REPORT_APPROVED + searchCriteria.publicationStatus = PublicationStatus.APPROVED } List availableReports = [] diff --git a/src/main/groovy/au/org/ala/merit/reports/ReportGenerator.groovy b/src/main/groovy/au/org/ala/merit/reports/ReportGenerator.groovy index 50e86c1eb..41140affd 100644 --- a/src/main/groovy/au/org/ala/merit/reports/ReportGenerator.groovy +++ b/src/main/groovy/au/org/ala/merit/reports/ReportGenerator.groovy @@ -2,10 +2,10 @@ package au.org.ala.merit.reports import au.org.ala.merit.DateUtils import au.org.ala.merit.config.ReportConfig +import au.org.ala.merit.PublicationStatus import org.apache.commons.logging.LogFactory import org.joda.time.DateTime import org.joda.time.DateTimeZone -import org.joda.time.Duration import org.joda.time.Interval import org.joda.time.Period import org.joda.time.PeriodType @@ -28,8 +28,6 @@ class ReportGenerator { */ private int DATE_FUDGE_FACTOR = 1 - private static final String REPORT_NOT_APPROVED = 'unpublished' - /** * Generates a list of reports according to the supplied configuration. * @param reportConfig Describes the frequency and properties of generated reports. @@ -122,7 +120,7 @@ class ReportGenerator { if (end >= start) { //validates the latest approved report to avoid creation of duplicate report - if (existingReports && existingReports[0].publicationStatus != REPORT_NOT_APPROVED) { + if (existingReports && existingReports[0].publicationStatus != PublicationStatus.NOT_APPROVED) { log.info("Not regenerating report " + reportConfig.category + " to avoid creating duplicate reports") } else { Interval reportInterval = new Interval(start, end) diff --git a/src/test/groovy/au/org/ala/merit/ProjectServiceSpec.groovy b/src/test/groovy/au/org/ala/merit/ProjectServiceSpec.groovy index 1d09a2dd4..6bcbe3901 100644 --- a/src/test/groovy/au/org/ala/merit/ProjectServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/ProjectServiceSpec.groovy @@ -479,7 +479,7 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest> true - reportService.getReportsForProject(_) >> [[publicationStatus:ReportService.REPORT_APPROVED]] + reportService.getReportsForProject(_) >> [[publicationStatus:PublicationStatus.APPROVED]] Map project = [projectId:projectId, planStatus:ProjectService.PLAN_NOT_APPROVED, plannedStartDate: '2015-07-01T00:00Z', plannedEndDate:'2016-12-31T00:00Z'] webService.getJson(_) >> project @@ -497,9 +497,9 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest>[ - [reportId:'r1', publicationStatus:ReportService.REPORT_APPROVED, name:'Stage 1', fromDate: '2015-07-01T00:00Z', toDate: '2016-01-01T00:00Z'], - [reportId:'r2', publicationStatus:ReportService.REPORT_NOT_APPROVED, name:'Stage 2', fromDate: '2016-01-01T00:00Z', toDate: '2017-01-01T00:00Z'], - [reportId:'r3', publicationStatus:ReportService.REPORT_CANCELLED, name:'Stage 3', fromDate: '2016-01-01T00:00Z', toDate: '2017-01-01T00:00Z']] + [reportId:'r1', publicationStatus:PublicationStatus.APPROVED, name:'Stage 1', fromDate: '2015-07-01T00:00Z', toDate: '2016-01-01T00:00Z'], + [reportId:'r2', publicationStatus:PublicationStatus.NOT_APPROVED, name:'Stage 2', fromDate: '2016-01-01T00:00Z', toDate: '2017-01-01T00:00Z'], + [reportId:'r3', publicationStatus:PublicationStatus.CANCELLED, name:'Stage 3', fromDate: '2016-01-01T00:00Z', toDate: '2017-01-01T00:00Z']] webService.getJson(_) >> [projectId:projectId, planStatus:ProjectService.PLAN_NOT_APPROVED, plannedStartDate: '2015-07-01T00:00Z', plannedEndDate:'2016-12-31T00:00Z'] when: @@ -797,7 +797,7 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest> project - reportService.getReportsForProject(project.projectId) >> [[reportId:'r1', publicationStatus:ReportService.REPORT_NOT_APPROVED, fromDate:project.plannedStartDate, toDate:project.plannedEndDate]] + reportService.getReportsForProject(project.projectId) >> [[reportId:'r1', publicationStatus:PublicationStatus.NOT_APPROVED, fromDate:project.plannedStartDate, toDate:project.plannedEndDate]] reportService.firstReportWithDataByCriteria(_, _) >> null when: @@ -814,7 +814,7 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest> r1 - boolean submittedOrApproved = (reportStatus == ReportService.REPORT_SUBMITTED || reportStatus == ReportService.REPORT_APPROVED) + boolean submittedOrApproved = (reportStatus == PublicationStatus.SUBMITTED || reportStatus == PublicationStatus.APPROVED) webService.getJson(_) >> project reportService.getReportsForProject(project.projectId) >> [r1] reportService.excludesNotApproved(_) >> submittedOrApproved @@ -827,14 +827,14 @@ class ProjectServiceSpec extends Specification implements ServiceUnitTest> project when: @@ -184,10 +185,10 @@ class ReportServiceSpec extends Specification implements ServiceUnitTest> project @@ -203,10 +204,10 @@ class ReportServiceSpec extends Specification implements ServiceUnitTest> project @@ -225,9 +226,9 @@ class ReportServiceSpec extends Specification implements ServiceUnitTest> project @@ -248,7 +249,7 @@ class ReportServiceSpec extends Specification implements ServiceUnitTest> project diff --git a/src/test/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommandSpec.groovy b/src/test/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommandSpec.groovy index 4deb7b26a..81f540765 100644 --- a/src/test/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommandSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/command/Reef2050PlanActionReportSummaryCommandSpec.groovy @@ -1,7 +1,7 @@ package au.org.ala.merit.command import au.org.ala.merit.ActivityService -import au.org.ala.merit.ReportService +import au.org.ala.merit.PublicationStatus import au.org.ala.merit.reports.Reef2050PlanActionReportConfig import grails.converters.JSON import grails.testing.spring.AutowiredTest @@ -34,7 +34,7 @@ class Reef2050PlanActionReportSummaryCommandSpec extends Specification implement then: 1 * activityService.search( [type : Reef2050PlanActionReportConfig.REEF_2050_PLAN_ACTION_REPORTING_2018_ACTIVITY_TYPE, - progress: ActivityService.PROGRESS_FINISHED, publicationStatus: ReportService.REPORT_APPROVED]) >> [reports:[]] + progress: ActivityService.PROGRESS_FINISHED, publicationStatus: PublicationStatus.APPROVED]) >> [reports:[]] reports.size() == 3 } @@ -44,7 +44,7 @@ class Reef2050PlanActionReportSummaryCommandSpec extends Specification implement then: 1 * activityService.search( [type : Reef2050PlanActionReportConfig.REEF_2050_PLAN_ACTION_REPORTING_2018_ACTIVITY_TYPE, - progress: ActivityService.PROGRESS_FINISHED, publicationStatus: ReportService.REPORT_APPROVED]) >> [resp:[activities:[[plannedEndDate:'2018-07-01T00:00:00Z']]]] + progress: ActivityService.PROGRESS_FINISHED, publicationStatus: PublicationStatus.APPROVED]) >> [resp:[activities:[[plannedEndDate:'2018-07-01T00:00:00Z']]]] reports.size() == 4 } @@ -55,7 +55,7 @@ class Reef2050PlanActionReportSummaryCommandSpec extends Specification implement then: 1 * activityService.search( [type : Reef2050PlanActionReportConfig.REEF_2050_PLAN_ACTION_REPORTING_2018_ACTIVITY_TYPE, - progress: ActivityService.PROGRESS_FINISHED, publicationStatus: ReportService.REPORT_APPROVED]) >> [reports:[]] + progress: ActivityService.PROGRESS_FINISHED, publicationStatus: PublicationStatus.APPROVED]) >> [reports:[]] and: reports[0].periodStart == null diff --git a/src/test/groovy/au/org/ala/merit/command/SaveReportDataCommandSpec.groovy b/src/test/groovy/au/org/ala/merit/command/SaveReportDataCommandSpec.groovy index 7af2b1a59..05184acde 100644 --- a/src/test/groovy/au/org/ala/merit/command/SaveReportDataCommandSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/command/SaveReportDataCommandSpec.groovy @@ -1,6 +1,7 @@ package au.org.ala.merit.command import au.org.ala.merit.ActivityService +import au.org.ala.merit.PublicationStatus import au.org.ala.merit.ReportService import au.org.ala.merit.SiteService import org.apache.http.HttpStatus @@ -50,8 +51,8 @@ class SaveReportDataCommandSpec extends Specification { savedData:[activityId:'a2'], report:[reportId:'r2'] ] - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -73,8 +74,8 @@ class SaveReportDataCommandSpec extends Specification { reportId:'r1', site:[siteId:'s2'] ] - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:'s1'] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:'s1'] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -93,8 +94,8 @@ class SaveReportDataCommandSpec extends Specification { activityId:'a2', reportId:'r1' ] - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:'a1'] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:'s1'] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:'a1'] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:'s1'] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -116,8 +117,8 @@ class SaveReportDataCommandSpec extends Specification { ], reportId:'r1' ] - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -152,8 +153,8 @@ class SaveReportDataCommandSpec extends Specification { ] ] ] - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:jsonData.site.siteId] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:jsonData.site.siteId] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -189,8 +190,8 @@ class SaveReportDataCommandSpec extends Specification { ] ] String siteId = 's1' - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:siteId] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:siteId] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -227,8 +228,8 @@ class SaveReportDataCommandSpec extends Specification { ] String siteId = 's1' - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity @@ -264,8 +265,8 @@ class SaveReportDataCommandSpec extends Specification { ] ] - Map r1Report = [reportId:jsonData.reportId, publicationStatus:ReportService.REPORT_NOT_APPROVED, activityId:jsonData.activityId] - Map savedActivity = [activityId:jsonData.activityId, publicationStatus: ReportService.REPORT_NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:siteId] + Map r1Report = [reportId:jsonData.reportId, publicationStatus:PublicationStatus.NOT_APPROVED, activityId:jsonData.activityId] + Map savedActivity = [activityId:jsonData.activityId, publicationStatus: PublicationStatus.NOT_APPROVED, progress:ActivityService.PROGRESS_PLANNED, siteId:siteId] reportService.get(jsonData.reportId) >> r1Report activityService.get(jsonData.activityId) >> savedActivity From b7621d7cb7e9a5301076b80030917c28b3f47bfb Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 23 Oct 2023 10:19:03 +1100 Subject: [PATCH 2/2] Support publicationStatus for sites #3011 --- .../au/org/ala/merit/ProjectController.groovy | 2 +- .../controllers/au/org/ala/merit/SiteController.groovy | 10 +++++----- grails-app/views/site/_sitesList.gsp | 2 +- grails-app/views/site/index.gsp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/grails-app/controllers/au/org/ala/merit/ProjectController.groovy b/grails-app/controllers/au/org/ala/merit/ProjectController.groovy index 209e1102d..293c806d1 100644 --- a/grails-app/controllers/au/org/ala/merit/ProjectController.groovy +++ b/grails-app/controllers/au/org/ala/merit/ProjectController.groovy @@ -203,7 +203,7 @@ class ProjectController { else if (template == RLP_TEMPLATE) { // The RLP Project Template doesn't need site details or activities. - project.sites = new JSONArray(project.sites?.collect{new JSONObject([name:it.name, siteId:it.siteId, lastUpdated:it.lastUpdated, type:it.type, extent:[:]])} ?: []) + project.sites = new JSONArray(project.sites?.collect{new JSONObject([name:it.name, siteId:it.siteId, lastUpdated:it.lastUpdated, type:it.type, extent:[:], publicationStatus:it.publicationStatus])} ?: []) project.remove('activities') model.overview.template = 'rlpOverview' diff --git a/grails-app/controllers/au/org/ala/merit/SiteController.groovy b/grails-app/controllers/au/org/ala/merit/SiteController.groovy index 92ea32477..61d9c7beb 100644 --- a/grails-app/controllers/au/org/ala/merit/SiteController.groovy +++ b/grails-app/controllers/au/org/ala/merit/SiteController.groovy @@ -117,7 +117,7 @@ class SiteController { flash.message = "Access denied: User does not have editor permission to edit site: ${id}" redirect(controller:'home', action:'index') } else { - if (result.site.type == SiteService.SITE_TYPE_COMPOUND) { + if (SiteService.isReadOnly(result.site)) { redirect(action:'index', id:id) } result @@ -174,7 +174,7 @@ class SiteController { List siteIds = payload.siteIds project?.sites?.each { site -> - if (site.type == SiteService.SITE_TYPE_COMPOUND) { + if (SiteService.isReadOnly(site)) { siteIds.remove(site.siteId) } } @@ -196,7 +196,7 @@ class SiteController { return } Map site = siteService.get(id) - if (!projectService.canUserEditProject(userService.getCurrentUserId(), projectId) || site.type == SiteService.SITE_TYPE_COMPOUND) { + if (!projectService.canUserEditProject(userService.getCurrentUserId(), projectId) || SiteService.isReadOnly(site)) { render status:403, text: "Access denied: User does not have permission to edit sites for project: ${projectId}" return } @@ -214,7 +214,7 @@ class SiteController { def ajaxDelete(String id) { // permissions check Map site = siteService.get(id) - if (!isUserMemberOfSiteProjects(site) || site.type == SiteService.SITE_TYPE_COMPOUND) { + if (!isUserMemberOfSiteProjects(site) || SiteService.isReadOnly(site)) { render status:403, text: "Access denied: User does not have permission to edit site: ${id}" return } @@ -234,7 +234,7 @@ class SiteController { log.debug("Updating site: " + id) Map site = siteService.get(id) // permissions check - if (!isUserMemberOfSiteProjects(site) || site.type == SiteService.SITE_TYPE_COMPOUND) { + if (!isUserMemberOfSiteProjects(site) || SiteService.isReadOnly(site)) { render status:403, text: "Access denied: User does not have permission to edit site: ${id}" return } diff --git a/grails-app/views/site/_sitesList.gsp b/grails-app/views/site/_sitesList.gsp index b31bec499..4d07d34f4 100644 --- a/grails-app/views/site/_sitesList.gsp +++ b/grails-app/views/site/_sitesList.gsp @@ -42,7 +42,7 @@ - + diff --git a/grails-app/views/site/index.gsp b/grails-app/views/site/index.gsp index f9cd73861..06458fd3c 100644 --- a/grails-app/views/site/index.gsp +++ b/grails-app/views/site/index.gsp @@ -59,7 +59,7 @@ Site Actions:
- +