This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wao. See http://git.codelutin.com/wao.git commit 94e7bd8f1d593d96608d89d75110b013fa1249f5 Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Jan 21 15:45:44 2015 +0100 On permet la création de contacts que pour les membres du labo affecté à la ligne --- .../java/fr/ifremer/wao/services/AuthenticatedWaoUser.java | 8 ++++++++ .../java/fr/ifremer/wao/services/service/ContactsService.java | 10 ++++++++++ .../wao/services/service/SclerochronologySamplingPlan.java | 7 +++++++ .../webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java b/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java index 214d21a..0ca8bdb 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java @@ -224,6 +224,14 @@ public class AuthenticatedWaoUser implements Serializable{ return userProfile.isCoordinatorOrObserver() && isCanWrite(); } + /** + * Si l'utilisateur peut créer un contact pour une ligne du plan associée à l'organisation + * dont le topiaId est en paramètre. + */ + public boolean isAuthorizedToCreateContact(String sampleRowOrganisationId) { + return isAuthorizedToCreateContact() && waoUser.getOrganisation().getTopiaId().equals(sampleRowOrganisationId); + } + public boolean isAuthorizedToUpdateContact() { return (userProfile.isCoordinatorOrObserver() || userProfile.isAdmin()) && isCanWrite(); } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java index e0bfdeb..a097e2a 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java @@ -872,11 +872,18 @@ public class ContactsService extends WaoServiceSupport { throw new MissingContactMainObserverException(contact); } + // pour obsmer et obsvente, tous les observateurs doivent faire partie de la société à laquelle est affectée la ligne Set<WaoUser> possibleObservers = getPossibleObservers(contact.getSampleRow()); if ( ! possibleObservers.contains(mainObserver)) { throw new MismatchContactMainObserverCompanyException(contact, mainObserver, contact.getSampleRow().getOrganisation()); } + // pour scléro, les observateurs peuvent appartenir à la même société mais des labos différents. Toutefois, l'observateur + // principal doit appartenir au labo + if ( ! contact.getMainObserver().getOrganisation().equals(contact.getSampleRow().getOrganisation())) { + throw new MismatchContactMainObserverCompanyException(contact, mainObserver, contact.getSampleRow().getOrganisation()); + } + if (contact.isSecondaryObserversNotEmpty()) { if (contact.getSecondaryObservers().contains(mainObserver)) { throw new DuplicatedContactMainObserverInSecondaryObserversException(contact); @@ -1135,6 +1142,9 @@ public class ContactsService extends WaoServiceSupport { WaoUser mainObserver = authenticatedWaoUser.getWaoUser(); Preconditions.checkState( + authenticatedWaoUser.isAuthorizedToCreateContact(sampleRow.getOrganisation().getTopiaId()), + authenticatedWaoUser + " is not allowed to create a contact for row " + sampleRow); + Preconditions.checkState( getPossibleObservers(sampleRow).contains(mainObserver), authenticatedWaoUser + " is not allowed to create a contact for row " + sampleRow); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java index 0f6ab70..052a9fe 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java @@ -70,6 +70,8 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab public static class SclerochronologySamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { + protected String organisationId; + protected String organisationFullName; protected String samplingContext; @@ -91,10 +93,15 @@ public class SclerochronologySamplingPlan extends SamplingPlan implements Iterab samplingContext = WaoUtils.l(locale, sampleRow.getSclerochronologySamplingContext()); samplingContextInfo = sampleRow.getSclerochronologySamplingContextInfo(); individualMeasurementStrategy = WaoUtils.l(locale, sampleRow.getIndividualMeasurementStrategy()); + organisationId = sampleRow.getOrganisation().getTopiaId(); organisationFullName = sampleRow.getOrganisation().getFullName(); totalIndividuals = Effort.sum(effortInIndividualsPerMonths.values()); } + public String getOrganisationId() { + return organisationId; + } + public String getOrganisationFullName() { return organisationFullName; } diff --git a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp index edb945f..0b0b28c 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp @@ -394,7 +394,7 @@ </s:a> </li> </s:if> - <s:if test="authenticatedWaoUser.authorizedToCreateContact"> + <s:if test="authenticatedWaoUser.authorizedToCreateContact(organisationId)"> <li> <s:url action="create-contact" id="createContactUrl"> <s:param name="sampleRowId" value="sampleRowId" /> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.