Skip to content

Commit

Permalink
ldap, console : new orgUniqueId georchestra#4374 georchestra#4372 geo…
Browse files Browse the repository at this point in the history
…rchestra/georchestra-gateway#159

Add organizationId object

Fix olcAttribute type uniqueOrganizationId

Console - new form field - uniqueOrganizationId

Custom proconnect tag for docker image

ldap management - add new uniqueOrganizationId

up attribute and add siret c2c info

new uniqueOrganizationId field in orgDao

console, ldap - add new orgUniqueId field

use organizatioid

change jsp new account

new code insertion for field uniqueOrganizationId

org create form translation

Fix app. properties with uniqueOrganizationId

translate missing key

use standard var name

rename new org field according to console rules

Fix JSON var name

fix getter annotation

add missing new file

Insert new orgUniqueId field in commons

New field Mapping with organization class

fix around new orgUniqueId field

Changes around new orgUniqueId ldap field

Fix JSP error

remove useless console log

Add new account orgUniqueId field

complete code with new org field

Control orgUniqId unicity before save, update

fix org validation by orgUniqueId field

correct makefile btag
  • Loading branch information
Gaetanbrl committed Jan 6, 2025
1 parent bfd103a commit 870d656
Show file tree
Hide file tree
Showing 33 changed files with 200 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface OrganizationsApi {

Optional<Organization> findById(String id);

Optional<Organization> findByOrgUniqueId(String id);

Optional<Organization> findByShortName(String shortName);

Optional<byte[]> getLogo(String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class Organization implements Serializable {

private String mail;

/** Custom field added by georchestra.ldif file */
private String orgUniqueId;

/**
* String that somehow represents the current version, may be a timestamp, a
* hash, etc. Provided by request header {@code sec-lastupdated}
Expand Down
3 changes: 3 additions & 0 deletions console/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ public Org getOrgInfos(@PathVariable String cn) {
return this.orgDao.findByCommonName(cn);
}

/**
* Retreive full information about one org as JSON document from unique
* organization id number (e.g french SIRET number). Following keys will be
* available :
*
* * 'id' (not used) * 'name' * 'shortName' * 'cities' as json array ex:
* [654,865498,98364,9834534,984984,6978984,98498] * 'status' * 'orgType' *
* 'address' * 'members' as json array ex: ["testadmin", "testuser"]
*
*/
@RequestMapping(value = REQUEST_MAPPING
+ "/uoi/{orgUniqueId:.+}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
@ResponseBody
public Org getOrgInfosFromUniqueOrgId(@PathVariable String orgUniqueId) {
Org orgInfos = this.orgDao.findByOrgUniqueId(orgUniqueId);
this.checkOrgAuthorization(orgInfos.getId());
return orgInfos;
}

/**
* Update information of one org
*
Expand All @@ -185,6 +204,9 @@ public Org getOrgInfos(@PathVariable String cn) {
* plante, 73059 Chambrille", "members": [ "testadmin", "testuser" ] }
*
*/
/**
* TODO: Control orgUniqueId unicity
*/
@RequestMapping(value = REQUEST_MAPPING
+ "/{commonName:.+}", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
@ResponseBody
Expand All @@ -196,6 +218,10 @@ public Org updateOrgInfos(@PathVariable String commonName, HttpServletRequest re
// Parse Json
JSONObject json = this.parseRequest(request);

if (!this.validation.validateOrgUnicity(json)) {
throw new IOException("Organization : already exists");
}

// Validate request against required fields for admin part
if (!this.validation.validateOrgField("name", json)) {
throw new IOException("required field : name");
Expand Down Expand Up @@ -258,6 +284,10 @@ public Org createOrg(HttpServletRequest request) throws IOException, JSONExcepti
// Parse Json
JSONObject json = this.parseRequest(request);

if (!this.validation.validateOrgUnicity(json)) {
throw new IOException("An organization with this identification number already exists.");
}

// Validate request against required fields for admin part
if (!this.validation.validateOrgField("shortName", json)) {
throw new IOException("required field : shortName");
Expand Down Expand Up @@ -482,6 +512,7 @@ protected void updateFromRequest(Org org, JSONObject json) throws IOException {
org.setUrl(json.optString(Org.JSON_URL));
org.setLogo(json.optString(Org.JSON_LOGO));
org.setMail(json.optString(Org.JSON_MAIL));
org.setOrgUniqueId(json.optString(Org.JSON_ORG_UNIQ_ID));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
private String url;
private String orgType;
private String mail;
private String orgUniqueId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
public class EditOrgDetailsFormController {
private OrgsDao orgsDao;
private Validation validation;
private static final String[] FIELDS = { "id", "url", "description", "logo", "name", "address", "mail" };
private static final String[] FIELDS = { "id", "url", "description", "logo", "name", "address", "mail",
"orgUniqueId" };

private static final Log LOG = LogFactory.getLog(EditOrgDetailsFormController.class.getName());

Expand Down Expand Up @@ -94,6 +95,7 @@ public String setupForm(HttpServletRequest request, Model model) {
model.addAttribute("id", org.getId());
model.addAttribute("logo", org.getLogo());
model.addAttribute("mail", org.getMail());
model.addAttribute("orgUniqueId", org.getOrgUniqueId());
HttpSession session = request.getSession();
for (String f : FIELDS) {
if (validation.isOrgFieldRequired(f)) {
Expand All @@ -110,6 +112,7 @@ public String edit(Model model, @ModelAttribute EditOrgDetailsFormBean formBean,
validation.validateOrgField("url", formBean.getUrl(), resultErrors);
validation.validateOrgField("address", formBean.getAddress(), resultErrors);
validation.validateOrgField("description", formBean.getDescription(), resultErrors);
validation.validateOrgField("orgUniqueId", formBean.getOrgUniqueId(), resultErrors);
// TODO validate mail address for the organization ?

if (resultErrors.hasErrors()) {
Expand All @@ -122,6 +125,7 @@ public String edit(Model model, @ModelAttribute EditOrgDetailsFormBean formBean,
orgOrigin.setDescription(formBean.getDescription());
orgOrigin.setUrl(formBean.getUrl());
orgOrigin.setAddress(formBean.getAddress());
orgOrigin.setOrgUniqueId(formBean.getOrgUniqueId());

if (!logo.isEmpty()) {
orgOrigin.setLogo(transformLogoFileToBase64(logo));
Expand Down Expand Up @@ -154,6 +158,7 @@ private EditOrgDetailsFormBean createForm(Org org) {
formBean.setAddress(org.getAddress());
formBean.setOrgType(org.getOrgType());
formBean.setMail(org.getMail());
formBean.setOrgUniqueId(org.getOrgUniqueId());
return formBean;
}

Expand Down Expand Up @@ -192,6 +197,11 @@ protected void logOrgDetailsChanges(Org org, EditOrgDetailsFormBean formBean, Mu
if (StringUtils.isNotEmpty(org.getMail()) && !org.getMail().equals(formBean.getMail())) {
logUtils.createAndLogDetails(id, Org.JSON_MAIL, org.getMail(), formBean.getMail(), type);
}

if (!org.getOrgUniqueId().equals(formBean.getOrgUniqueId())) {
logUtils.createAndLogDetails(id, Org.JSON_ORG_UNIQ_ID, org.getOrgUniqueId(), formBean.getAddress(), type);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class AccountFormBean implements Serializable {

private @Getter @Setter String orgMail;

private @Getter @Setter String orgUniqueId;

public boolean getPrivacyPolicyAgreed() {
return privacyPolicyAgreed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public AccountFormBean getAccountFormBean() {
public void initForm(WebDataBinder dataBinder) {
dataBinder.setAllowedFields("firstName", "surname", "email", "phone", "org", "title", "description", "uid",
"password", "confirmPassword", "privacyPolicyAgreed", "consentAgreed", "createOrg", "orgName",
"orgShortName", "orgAddress", "orgType", "orgCities", "orgDescription", "orgUrl", "orgMail", "orgLogo",
"recaptcha_response_field");
"orgShortName", "orgUniqueId", "orgAddress", "orgType", "orgCities", "orgDescription", "orgUrl",
"orgMail", "orgLogo", "recaptcha_response_field");
}

@RequestMapping(value = "/account/new", method = RequestMethod.GET)
Expand Down Expand Up @@ -258,6 +258,7 @@ public String create(HttpServletRequest request, @ModelAttribute AccountFormBean
org.setUrl(formBean.getOrgUrl());
org.setLogo(formBean.getOrgLogo());
org.setMail(formBean.getOrgMail());
org.setOrgUniqueId(formBean.getOrgUniqueId());
// Parse and store cities
orgCities = orgCities.trim();
if (orgCities.length() > 0)
Expand Down Expand Up @@ -409,6 +410,7 @@ private void validateFields(@ModelAttribute AccountFormBean formBean, BindingRes
validation.validateUserField("title", formBean.getTitle(), result);
validation.validateUserField("description", formBean.getDescription(), result);

// unique orgUniqueId value
if (formBean.getCreateOrg() && !result.hasErrors()) {
validation.validateOrgField("name", formBean.getOrgName(), result);
validation.validateOrgField("shortName", formBean.getOrgShortName(), result);
Expand All @@ -417,7 +419,10 @@ private void validateFields(@ModelAttribute AccountFormBean formBean, BindingRes
validation.validateOrgField("url", formBean.getOrgUrl(), result);
validation.validateOrgField("description", formBean.getOrgDescription(), result);
validation.validateOrgField("logo", formBean.getOrgLogo(), result);
validation.validateOrgField("orgUniqueId", formBean.getOrgUniqueId(), result);
validation.validateUrlFieldWithSpecificMsg("orgUrl", formBean.getOrgUrl(), result);

validation.validateOrgUniqueIdField(formBean.getOrgUniqueId(), null, result);
} else {
validation.validateUserField("org", formBean.getOrg(), result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.georchestra.ds.orgs.Org;
import org.georchestra.ds.orgs.OrgsDao;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;

Expand All @@ -45,6 +50,9 @@
*/
public class Validation {

@Autowired
private OrgsDao orgDao;

private Set<String> requiredUserFields;
private Set<String> requiredOrgFields;

Expand Down Expand Up @@ -191,4 +199,41 @@ public boolean validateUrlFieldWithSpecificMsg(String fullyQualifiedField, Strin
}
return true;
}

public boolean validateOrgUnicityByUniqueId(String orgUniqueId, String uuid) {
// case - not value to verify
if (orgUniqueId == null || orgUniqueId.isEmpty()) {
return true;
}
// test if org with same value already exists
Org findByOrgUniqueId = this.orgDao.findByOrgUniqueId(orgUniqueId);
// No org exists with this field value
if (findByOrgUniqueId == null) {
return true;
}
// No uuid to compare means that's an org creation
// and at this step, an org already exists with this orgUniqueId
if (uuid == null) {
// we can't validate this orgUniqueId that already exists
return false;
}
// Control if this is same org update
return Objects.equals(findByOrgUniqueId.getUniqueIdentifier(), UUID.fromString(uuid));
}

public boolean validateOrgUniqueIdField(String orgUniqueId, String uniqueId, Errors errors) {
if (!this.validateOrgUnicityByUniqueId(orgUniqueId, uniqueId)) {
errors.rejectValue("orgUniqueId", "error.orgUniqueIdExists", "orgUniqueIdExists");
return false;
}
return true;
}

public boolean validateOrgUnicity(JSONObject json) {
boolean isUniqueOrg = true;
if (json.has("orgUniqueId")) {
isUniqueOrg = this.validateOrgUnicityByUniqueId(json.getString("orgUniqueId"), json.getString("uuid"));
}
return isUniqueOrg;
}
}
3 changes: 3 additions & 0 deletions console/src/main/webapp/WEB-INF/i18n/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ confirmPassword.error.pwdNotEquals=These passwords don\'t match
confirmPassword.error.pwdNotEquals.tag=Mismatch
description.label=Description
description.placeholder=Description
orgUniqueId.label=Identification number
email.label=E-mail
email.placeholder=E-mail
email.error.required=Required
email.error.invalidFormat=Invalid format
email.error.exist=This e-mail is already in use, you can try to <a href="{0}">reset your password</a>.
error.required=Required
error.badUrl=malformed url
error.orgUniqueIdExists=An organisation with this identification number already exists.
facsimile.label=Fax
facsimile.placeholder=Fax
firstName.label=First Name
Expand All @@ -113,6 +115,7 @@ org.cannot_find_org_in_list=My organization is not present
org.required=Required
org.creation.label=Organization Name
org.creation.shortLabel=Short Name
org.creation.orgUniqueId=Identification number
org.creation.address=Address
org.creation.orgType=Organization type
org.creation.orgDescription=Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ confirmPassword.error.pwdNotEquals.tag=Nicht das gleiche Passwort
description.label=Beschreibung
description.placeholder=Beschreibung
email.label=E-Mail
orgUniqueId.label=Identifikationsnummer
email.placeholder=E-Mail
email.error.required=Notwendig
email.error.invalidFormat=Ungültiges Format
email.error.exist=Diese E-Mail Adresse ist bereits in Benutzung, Sie können ihr <a href="{0}">Passwort zurücksetzen</a>.
error.required=Notwendig
error.badUrl=malformed url
error.orgUniqueIdExists=Eine Organisation mit dieser Identifikationsnummer existiert bereits.
facsimile.label=Fax
facsimile.placeholder=Fax
firstName.label=Vorname
Expand All @@ -111,6 +113,7 @@ org.cannot_find_org_in_list=Meine Organisation ist nicht vorhanden
org.required=Notwendig
org.creation.label=Organisations-Name
org.creation.shortLabel=Kurzbezeichnung
org.creation.orgUniqueId=Identifikationsnummer
org.creation.address=Adresse
org.creation.orgType=Organisationstyp
org.creation.orgDescription=Beschreibung
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ confirmPassword.error.pwdNotEquals.tag=Diferentes
description.label=Descripción
description.placeholder=Descripción
email.label=dirección de correo electrónico
orgUniqueId.label=Identificación
email.placeholder=dirección de correo electrónico
email.error.required=Requerido
email.error.invalidFormat=Formato inválido
email.error.exist=Este correo electrónico ya está en uso, puede intentar <a href="{0}">restablecer su contraseña</a>.
error.required=Requerido
error.badUrl=malformed url
error.orgUniqueIdExists=Ya existe una organización con este número de identificación.
facsimile.label=Fax
facsimile.placeholder=Fax
firstName.label=Nombre
Expand All @@ -110,6 +112,7 @@ org.cannot_find_org_in_list=Mi organización no esta presente
org.required=Requerida
org.creation.label=Nombre de la Organización
org.creation.shortLabel=Nombre corto
org.creation.orgUniqueId=Número de identificación
org.creation.address=Dirección
org.creation.orgType=Tipo de Organización
org.creation.orgDescription=Descripción
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ confirmPassword.error.pwdNotEquals=Les mots de passe sont différents
confirmPassword.error.pwdNotEquals.tag=Différents
description.label=Description
description.placeholder=Description
orgUniqueId.label=Numéro d'identification
email.label=Courriel
email.placeholder=Courriel
email.error.required=Requis
email.error.invalidFormat=Format invalide
email.error.exist=Ce courriel est déjà utilisé, vous pouvez tenter de <a href="{0}">réinitialiser votre mot de passe</a>.
error.required=Requis
error.badUrl=Format d'url invalide
error.orgUniqueIdExists=Une organisation avec ce numéro d'identification existe déjà.
facsimile.label=Fax
facsimile.placeholder=Fax
firstName.label=Prénom
Expand All @@ -111,12 +113,14 @@ org.cannot_find_org_in_list=Mon organisme n'apparaît pas dans la liste
org.required=Requis
org.creation.label=Votre organisme
org.creation.shortLabel=Libellé court
org.creation.orgUniqueId=Numéro d'identification
org.creation.address=Adresse
org.creation.orgType=Type d\'organisme
org.creation.orgDescription=Description
org.creation.orgUrl=Url
org.creation.orgMail=Mail
org.creation.orgLogo=Logo
org.creation.orgUniqueId=Numéro d'identification
org.shortNameFormat=Le nom court ne doit comporter que des caractères alphanumériques
password.label=Mot de passe
password.placeholder=Mot de passe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ confirmPassword.error.pwdNotEquals.tag=Verschillend
description.label=Beschrijving
description.placeholder=Beschrijving
email.label=Email
orgUniqueId.label=Identificatienummer
email.placeholder=Email
email.error.required=Verplicht
email.error.invalidFormat=Ongeldig formaat
email.error.exist=Deze e-mail is al in gebruik, u kunt proberen om <a href="{0}">uw wachtwoord opnieuw in te stellen</a>
error.required=Verplicht
error.badUrl=malformed url
error.orgUniqueIdExists=Er bestaat al een organisatie met dit identificatienummer.
facsimile.label=Fax
facsimile.placeholder=Fax
firstName.label=Voornaam
Expand All @@ -111,6 +113,7 @@ org.cannot_find_org_in_list=Mijn organisatie verschijnt niet in de lijst
org.required=Verplicht
org.creation.label=Uw organisatie
org.creation.shortLabel=Kort label
org.creation.orgUniqueId=Identificatienummer
org.creation.address=Adres
org.creation.orgType=Type organisatie
org.creation.orgDescription=Description
Expand Down
Loading

0 comments on commit 870d656

Please sign in to comment.