Skip to content
Snippets Groups Projects
Commit 65a142b9 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Adding write protection for observations

parent 41a6b555
Branches
Tags
No related merge requests found
...@@ -297,6 +297,7 @@ public class ObservationController extends HttpServlet { ...@@ -297,6 +297,7 @@ public class ObservationController extends HttpServlet {
request.setAttribute("hierarchyCategories", SessionControllerGetter.getOrganismBean().getHierarchyCategoryNames(SessionLocaleUtil.getCurrentLocale(request))); request.setAttribute("hierarchyCategories", SessionControllerGetter.getOrganismBean().getHierarchyCategoryNames(SessionLocaleUtil.getCurrentLocale(request)));
request.setAttribute("observationMethods", em.createNamedQuery("ObservationMethod.findAll", ObservationMethod.class).getResultList()); request.setAttribute("observationMethods", em.createNamedQuery("ObservationMethod.findAll", ObservationMethod.class).getResultList());
request.setAttribute("organizationGroups", organizationGroups); request.setAttribute("organizationGroups", organizationGroups);
request.setAttribute("editAccess", "W"); // User always has edit access to new observation
if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.OBSERVATION_AUTHORITY, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER)) if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.OBSERVATION_AUTHORITY, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER))
{ {
request.setAttribute("statusTypeIds", em.createNamedQuery("ObservationStatusType.findAll").getResultList()); request.setAttribute("statusTypeIds", em.createNamedQuery("ObservationStatusType.findAll").getResultList());
...@@ -346,6 +347,18 @@ public class ObservationController extends HttpServlet { ...@@ -346,6 +347,18 @@ public class ObservationController extends HttpServlet {
{ {
request.setAttribute("messageKey",request.getParameter("messageKey")); request.setAttribute("messageKey",request.getParameter("messageKey"));
} }
// Determine the edit access
String editAccess = "R"; // Read access only
if(observation.getUserId().equals(user.getUserId()) || user.isSuperUser() || user.isOrganizationAdmin())
{
editAccess = "W";
}
else if(user.isObservationAuthority())
{
editAccess = "A"; // Approve
}
request.setAttribute("editAccess", editAccess);
request.getRequestDispatcher("/observationForm.ftl").forward(request, response); request.getRequestDispatcher("/observationForm.ftl").forward(request, response);
} }
catch(NullPointerException | NumberFormatException ex) catch(NullPointerException | NumberFormatException ex)
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
*/ */
var featureOverlay, GISInfoMap; var featureOverlay, GISInfoMap;
var draw; // global so we can remove it later
var olMapDivId = "objectGISInfoMap"; var olMapDivId = "objectGISInfoMap";
/** /**
...@@ -68,7 +69,7 @@ function initGisInfoMap(containerId, center, zoomLevel, displayMarker, drawnObjs ...@@ -68,7 +69,7 @@ function initGisInfoMap(containerId, center, zoomLevel, displayMarker, drawnObjs
// Create the DOM structure // Create the DOM structure
var theContainer = el(containerId); var theContainer = el(containerId);
theContainer.innerHTML = [ theContainer.innerHTML = [
"<div class='form-group'>", "<div class='form-group' id='drawOptions'>",
" <label>",getI18nMsg("mapDrawTypeLabel"),"</label>", " <label>",getI18nMsg("mapDrawTypeLabel"),"</label>",
" <select class='form-control' id='type' style='width: auto; display: inline;'>", " <select class='form-control' id='type' style='width: auto; display: inline;'>",
" <option value='Point'>",getI18nMsg("point"),"</option>", " <option value='Point'>",getI18nMsg("point"),"</option>",
...@@ -367,7 +368,7 @@ ol.inherits(app.geoLocationControl, ol.control.Control); ...@@ -367,7 +368,7 @@ ol.inherits(app.geoLocationControl, ol.control.Control);
}); });
var draw; // global so we can remove it later
function addDrawInteraction() { function addDrawInteraction() {
draw = new ol.interaction.Draw({ draw = new ol.interaction.Draw({
features: features, features: features,
......
...@@ -68,7 +68,10 @@ ...@@ -68,7 +68,10 @@
var chooseFromMapLayers = {"chooseFromMapLayers":<#if mapLayers?has_content>${mapLayers}<#else>[]</#if>}; var chooseFromMapLayers = {"chooseFromMapLayers":<#if mapLayers?has_content>${mapLayers}<#else>[]</#if>};
initGisInfoMap("observationFormMap",[${defaultMapCenter.x?c},${defaultMapCenter.y?c}],${defaultMapZoom},false, geoInfo, chooseFromMapLayers); initGisInfoMap("observationFormMap",[${defaultMapCenter.x?c},${defaultMapCenter.y?c}],${defaultMapZoom},false, geoInfo, chooseFromMapLayers);
</#if> </#if>
<#if editAccess!="W">
GISInfoMap.removeInteraction(draw);
document.getElementById("drawOptions").innerHTML ="";
</#if>
<#if observation.observationData?has_content> <#if observation.observationData?has_content>
observationData = ${observation.observationData}; observationData = ${observation.observationData};
getDataSchema(${observation.organism.organismId}, organizationId); getDataSchema(${observation.organism.organismId}, organizationId);
...@@ -539,7 +542,12 @@ ...@@ -539,7 +542,12 @@
<input type="hidden" name="observationData" value=""/> <input type="hidden" name="observationData" value=""/>
<input type="hidden" name="observationId" value="${observation.observationId!"-1"}"/> <input type="hidden" name="observationId" value="${observation.observationId!"-1"}"/>
<!--button type="button" onclick="var theForm=document.getElementById('observationForm');theForm['geoInfo'].value=getFeatures();try{mw.save();theForm['observationData'].value=JSON.stringify(mw.toInspect);return validateForm(theForm) && validateGIS(theForm);}catch(e){console.log(e.message);console.log(e);return false;}">Test</button--> <!--button type="button" onclick="var theForm=document.getElementById('observationForm');theForm['geoInfo'].value=getFeatures();try{mw.save();theForm['observationData'].value=JSON.stringify(mw.toInspect);return validateForm(theForm) && validateGIS(theForm);}catch(e){console.log(e.message);console.log(e);return false;}">Test</button-->
<#if ! observation.organism?has_content> <#if observation.user?has_content>
<div class="form-group">
<label>${i18nBundle.observer}: ${observation.user.firstName} ${observation.user.lastName}</label>
</div>
</#if>
<#if ! observation.organism?has_content>
<div class="form-group"> <div class="form-group">
<label for="cropCategoryId">${i18nBundle.listSelectedCropCategoryOnTop}</label> <label for="cropCategoryId">${i18nBundle.listSelectedCropCategoryOnTop}</label>
<select class="form-control" id="cropCategoryIdList" name="cropCategoryId" onchange="filterCrops(this.options[this.options.selectedIndex].value);"> <select class="form-control" id="cropCategoryIdList" name="cropCategoryId" onchange="filterCrops(this.options[this.options.selectedIndex].value);">
...@@ -582,22 +590,23 @@ ...@@ -582,22 +590,23 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="locationPointOfInterestId">${i18nBundle.location}&nbsp;&nbsp;<button role="button" type="button" onclick="addNewLocationPopup();">${i18nBundle.addNew}</button></label> <label for="locationPointOfInterestId">${i18nBundle.location}&nbsp;&nbsp;<button role="button" type="button" onclick="addNewLocationPopup();">${i18nBundle.addNew}</button></label>
<select class="form-control" name="locationPointOfInterestId" id="locationPointOfInterestId" onchange="showCorrectMap();"> <select class="form-control" name="locationPointOfInterestId" id="locationPointOfInterestId" onchange="showCorrectMap();" <#if editAccess!="W">readonly="readonly"</#if>>
<option value="-1">${i18nBundle.pleaseSelect} ${i18nBundle.location?lower_case}</option> <option value="-1">${i18nBundle.pleaseSelect} ${i18nBundle.location?lower_case}</option>
</select> </select>
<span class="help-block" id="${formId}_locationPointOfInterestId_validation"></span> <span class="help-block" id="${formId}_locationPointOfInterestId_validation"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<#if editAccess!="W" && observation.locationIsPrivate?has_content && observation.locationIsPrivate == true><input type="hidden" name="locationIsPrivate" value="true"/></#if>
<label> <label>
<input type="checkbox" name="locationIsPrivate"<#if !observation.locationIsPrivate?has_content || observation.locationIsPrivate == false><#else>checked="checked"</#if>/> <input type="checkbox" name="locationIsPrivate"<#if !observation.locationIsPrivate?has_content || observation.locationIsPrivate == false><#else>checked="checked"</#if> <#if editAccess!="W">disabled="disabled"</#if>/>
</label> </label>
${i18nBundle.locationIsPrivate} ${i18nBundle.locationIsPrivate}
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="organizationGroupId">${i18nBundle.availableFor} ${i18nBundle.organizationGroupList?lower_case}</label> <label for="organizationGroupId">${i18nBundle.availableFor} ${i18nBundle.organizationGroupList?lower_case}</label>
<select class="form-control chosen-select" name="organizationGroupId" multiple="multiple" data-placeholder="${i18nBundle.all}"> <select class="form-control chosen-select" name="organizationGroupId" multiple="multiple" data-placeholder="${i18nBundle.all}" <#if editAccess!="W">readonly="readonly"</#if>>
<#list organizationGroups as group> <#list organizationGroups as group>
<option value="${group.organizationGroupId}" <#if selectedOrganizationGroupIds?seq_contains(group.organizationGroupId)> selected="selected"</#if>>${group.groupName}</option> <option value="${group.organizationGroupId}" <#if selectedOrganizationGroupIds?seq_contains(group.organizationGroupId)> selected="selected"</#if>>${group.groupName}</option>
</#list> </#list>
...@@ -606,14 +615,15 @@ ...@@ -606,14 +615,15 @@
<#setting time_zone=user.organizationId.defaultTimeZone!"UTC"> <#setting time_zone=user.organizationId.defaultTimeZone!"UTC">
<div class="form-group"> <div class="form-group">
<label for="timeOfObservation">${i18nBundle.timeOfObservation}</label> <label for="timeOfObservation">${i18nBundle.timeOfObservation}</label>
<input type="text" class="form-control" id="timeOfObservation" name="timeOfObservation" placeholder="${i18nBundle.timeOfObservation}" value="${(observation.timeOfObservation?string("yyyy-MM-dd HH:mmZ"))!.now?string("yyyy-MM-dd HH:mmZ")}" onblur="validateField(this);" /> <input type="text" class="form-control" id="timeOfObservation" name="timeOfObservation" placeholder="${i18nBundle.timeOfObservation}" value="${(observation.timeOfObservation?string("yyyy-MM-dd HH:mmZ"))!.now?string("yyyy-MM-dd HH:mmZ")}" onblur="validateField(this);" <#if editAccess!="W">readonly="readonly"</#if>/>
<span class="help-block" id="${formId}_timeOfObservation_validation"></span> <span class="help-block" id="${formId}_timeOfObservation_validation"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<#if editAccess!="W" && observation.isQuantified?has_content && observation.isQuantified ==true><input type="hidden" name="isQuantified" value="true"/></#if>
<label> <label>
<input type="checkbox" name="isQuantified"<#if observation.isQuantified?has_content && observation.isQuantified == false><#else>checked="checked"</#if>/> <input type="checkbox" name="isQuantified"<#if observation.isQuantified?has_content && observation.isQuantified == false><#else> checked="checked"</#if> <#if editAccess!="W">disabled="disabled"</#if>/>
</label> </label>
${i18nBundle.isQuantified} ${i18nBundle.isQuantified}
</div> </div>
...@@ -627,8 +637,9 @@ ...@@ -627,8 +637,9 @@
<#if !noBroadcast> <#if !noBroadcast>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<#if editAccess!="W" && observation.broadcastMessage?has_content && observation.broadcastMessage ==true><input type="hidden" name="isQuantified" value="true"/></#if>
<label> <label>
<input type="checkbox" name="broadcastMessage"<#if (observation.broadcastMessage?has_content && observation.broadcastMessage == false) || noBroadcast><#else>checked="checked"</#if>/> <input type="checkbox" name="broadcastMessage"<#if (observation.broadcastMessage?has_content && observation.broadcastMessage == false) || noBroadcast><#else>checked="checked"</#if> <#if editAccess!="W">disabled="disabled"</#if>/>
</label> </label>
${i18nBundle.broadcastMessage} ${i18nBundle.broadcastMessage}
</div> </div>
...@@ -636,12 +647,12 @@ ...@@ -636,12 +647,12 @@
<div class="form-group"> <div class="form-group">
<label for="observationHeading">${i18nBundle.observationHeading}</label> <label for="observationHeading">${i18nBundle.observationHeading}</label>
<input type="text" class="form-control" name="observationHeading" placeholder="" value="${observation.observationHeading!""}" onblur="validateField(this);"/> <input type="text" class="form-control" name="observationHeading" placeholder="" value="${observation.observationHeading!""}" onblur="validateField(this);" <#if editAccess!="W">readonly="readonly"</#if>/>
<span class="help-block" id="${formId}_observationHeading_validation"></span> <span class="help-block" id="${formId}_observationHeading_validation"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="observationText">${i18nBundle.observationText}</label> <label for="observationText">${i18nBundle.observationText}</label>
<textarea class="form-control" name="observationText" placeholder="" >${observation.observationText!""}</textarea> <textarea class="form-control" name="observationText" placeholder="" <#if editAccess!="W">readonly="readonly"</#if>>${observation.observationText!""}</textarea>
<span class="help-block" id="${formId}_observationText_validation"></span> <span class="help-block" id="${formId}_observationText_validation"></span>
</div> </div>
<#if observation.observationIllustrationSet?has_content && observation.observationIllustrationSet?size == 1> <#if observation.observationIllustrationSet?has_content && observation.observationIllustrationSet?size == 1>
...@@ -649,7 +660,7 @@ ...@@ -649,7 +660,7 @@
<img src="/static/images/observations/${observation.organismId}/${illustration.observationIllustrationPK.fileName}" alt="TODO: Add describing text" class="img-responsive"/> <img src="/static/images/observations/${observation.organismId}/${illustration.observationIllustrationPK.fileName}" alt="TODO: Add describing text" class="img-responsive"/>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="deleteIllustration" value="true"> <input type="checkbox" name="deleteIllustration" value="true"/>
${i18nBundle.deleteIllustration} ${i18nBundle.deleteIllustration}
</label> </label>
</div> </div>
...@@ -686,7 +697,7 @@ ...@@ -686,7 +697,7 @@
</div> </div>
</#if> </#if>
<button type="submit" class="btn btn-default">${i18nBundle.submit}</button> <button type="submit" class="btn btn-default">${i18nBundle.submit}</button>
<#if observation.observationId?has_content> <#if observation.observationId?has_content && editAccess == "W">
<button type="button" class="btn btn-danger" onclick="if(confirm('${i18nBundle.confirmDelete}')){window.location.href='/observation?action=deleteObservation&observationId=${observation.observationId}';}">${i18nBundle.delete}</button> <button type="button" class="btn btn-danger" onclick="if(confirm('${i18nBundle.confirmDelete}')){window.location.href='/observation?action=deleteObservation&observationId=${observation.observationId}';}">${i18nBundle.delete}</button>
</#if> </#if>
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment