Skip to content

Commit

Permalink
Merge pull request #1661 from PnX-SI/hotfixes
Browse files Browse the repository at this point in the history
release 2.9.1
  • Loading branch information
bouttier authored Jan 27, 2022
2 parents 37fc47f + 3e25511 commit 7af2c82
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
push:
branches:
- master
- freeze
- hotfixes
- develop
pull_request:
branches:
- master
- freeze
- hotfixes
- develop

jobs:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.0
2.9.1
2 changes: 1 addition & 1 deletion backend/dependencies/TaxHub
2 changes: 1 addition & 1 deletion backend/geonature/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def load_current_user():
# Pass the ID_APP to the submodule to avoid token conflict between app on the same server
with app.app_context():
try:
gn_app = Application.query.filter_by(code_application='GN').one()
gn_app = Application.query.filter_by(code_application=config['CODE_APPLICATION']).one()
except (ProgrammingError, NoResultFound):
logging.warning("Warning: unable to find GeoNature application, database not yet initialized?")
else:
Expand Down
4 changes: 2 additions & 2 deletions backend/geonature/core/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def loginCas():
cookie_exp = datetime.datetime.utcnow()
expiration = current_app.config["COOKIE_EXPIRATION"]
cookie_exp += datetime.timedelta(seconds=expiration)
# generation d'un token
user["id_application"] = current_app.config["ID_APP"]
s = Serializer(current_app.config["SECRET_KEY"], expiration)
token = s.dumps(user)
response.set_cookie("token", token, expires=cookie_exp)
Expand Down Expand Up @@ -180,4 +180,4 @@ def insert_user_and_org(info_user):
raise CasAuthentificationError(
"Error insering user in GeoNature", status_code=500
)
return user
return user
2 changes: 1 addition & 1 deletion backend/geonature/core/gn_meta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class TAcquisitionFramework(CruvedMixin, FilterMixin, db.Model):
unique_acquisition_framework_id = DB.Column(
UUIDType(as_uuid=True), default=select([func.uuid_generate_v4()])
)
acquisition_framework_name = DB.Column(DB.Unicode)
acquisition_framework_name = DB.Column(DB.Unicode(255))
acquisition_framework_desc = DB.Column(DB.Unicode)
id_nomenclature_territorial_level = DB.Column(
DB.Integer,
Expand Down
73 changes: 44 additions & 29 deletions backend/geonature/core/gn_meta/mtd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get_xml(self, path):
url = urljoin(self.api_endpoint, path)
url = url.format(ID_INSTANCE=self.instance_id)
response = requests.get(url)
assert(response.status_code == 200)
response.raise_for_status()
return response.content

def _get_af_xml(self):
Expand Down Expand Up @@ -77,38 +77,49 @@ def add_unexisting_digitizer(id_digitizer):
insert_user_and_org(user)


def add_or_update_organism(uuid, nom, email):
statement = (
pg_insert(Organisme)
.values(
uuid_organisme=uuid,
nom_organisme=nom,
email_organisme=email,
)
.on_conflict_do_update(
index_elements=['uuid_organisme'],
set_=dict(
nom_organisme=nom,
email_organisme=email,
),
)
.returning(Organisme.id_organisme)
)
return db.session.execute(statement).scalar()


def associate_actors(actors, CorActor, pk_name, pk_value):
for actor in actors:
if not actor['uuid_organism']:
continue
statement = pg_insert(Organisme) \
.values(
uuid_organisme=actor['uuid_organism'],
nom_organisme=actor['organism'],
email_organisme=actor['email'],
).on_conflict_do_update(
index_elements=['uuid_organisme'],
set_=dict(
nom_organisme=actor['organism'],
email_organisme=actor['email'],
),
with db.session.begin_nested():
id_organism = add_or_update_organism(
uuid=actor['uuid_organism'],
nom=actor['organism'] or '',
email=actor['email'],
)
db.session.execute(statement)
# retrieve organism id
org = Organisme.query \
.filter_by(uuid_organisme=actor['uuid_organism']) \
.first()
statement = pg_insert(CorActor) \
statement = (
pg_insert(CorActor)
.values(
#id_acquisition_framework=af.id_acquisition_framework,
id_organism=org.id_organisme,
id_organism=id_organism,
id_nomenclature_actor_role=func.ref_nomenclatures.get_id_nomenclature(
"ROLE_ACTEUR", actor["actor_role"]
),
**{pk_name: pk_value},
).on_conflict_do_nothing(
)
.on_conflict_do_nothing(
index_elements=[pk_name, 'id_organism', 'id_nomenclature_actor_role'],
)
)
db.session.execute(statement)


Expand All @@ -120,24 +131,28 @@ def sync_af_and_ds():

af_list = mtd_api.get_af_list()
for af in af_list:
add_unexisting_digitizer(af['id_digitizer'])
with db.session.begin_nested():
add_unexisting_digitizer(af['id_digitizer'])
actors = af.pop('actors')
statement = pg_insert(TAcquisitionFramework) \
.values(**af) \
statement = (
pg_insert(TAcquisitionFramework)
.values(**af)
.on_conflict_do_update(
index_elements=['unique_acquisition_framework_id'],
set_=af)
db.session.execute(statement)
af = TAcquisitionFramework.query \
.filter_by(unique_acquisition_framework_id=af['unique_acquisition_framework_id']) \
.first()
.returning(TAcquisitionFramework.id_acquisition_framework)
)
af_id = db.session.execute(statement).scalar()
af = TAcquisitionFramework.query.get(af_id)
associate_actors(actors, CorAcquisitionFrameworkActor,
'id_acquisition_framework', af.id_acquisition_framework)
# TODO: remove actors removed from MTD
db.session.commit()

ds_list = mtd_api.get_ds_list()
for ds in ds_list:
add_unexisting_digitizer(ds['id_digitizer'])
with db.session.begin_nested():
add_unexisting_digitizer(ds['id_digitizer'])
actors = ds.pop('actors')
af_uuid = ds.pop('uuid_acquisition_framework')
af = TAcquisitionFramework.query.filter_by(unique_acquisition_framework_id=af_uuid).first()
Expand Down
5 changes: 4 additions & 1 deletion backend/geonature/core/gn_meta/mtd/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from lxml import etree as ET

from geonature.utils.config import config
from geonature.core.gn_meta.models import TAcquisitionFramework


namespace = config["XML_NAMESPACE"]

Expand Down Expand Up @@ -74,7 +76,8 @@ def parse_acquisition_framework(ca):

# We extract all the required informations from the different tags of the XML file
ca_uuid = get_tag_content(ca, "identifiantCadre")
ca_name = get_tag_content(ca, "libelle")
ca_name_max_length = TAcquisitionFramework.acquisition_framework_name.property.columns[0].type.length
ca_name = get_tag_content(ca, "libelle")[:ca_name_max_length-1]
ca_desc = get_tag_content(ca, "description", default_value="")
date_info = ca.find(namespace + "ReferenceTemporelle")
ca_create_date = get_tag_content(ca, "dateCreationMtd", default_value=datetime.datetime.now())
Expand Down
10 changes: 5 additions & 5 deletions backend/geonature/core/gn_permissions/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ def __check_cruved_scope(*args, **kwargs):
if user_with_highter_perm:
user_with_highter_perm = user_with_highter_perm[0]

# if get_role = True : set info_role as kwargs
if get_role:
kwargs["info_role"] = user_with_highter_perm
if get_scope:
kwargs["scope"] = int(user_with_highter_perm.value_filter)
# if no perm or perm = 0 -> raise 403
if user_with_highter_perm is None or user_with_highter_perm.value_filter == "0":
if object_code:
message = f"""User {user["id_role"]} cannot "{action}" in {module_code} on {object_code}"""
else:
message = f"""User {user["id_role"]} cannot "{action}" in {module_code}"""
raise Forbidden(description=message)
# if get_role = True : set info_role as kwargs
if get_role:
kwargs["info_role"] = user_with_highter_perm
if get_scope:
kwargs["scope"] = int(user_with_highter_perm.value_filter)
g.user = user_with_highter_perm
return fn(*args, **kwargs)

Expand Down
10 changes: 3 additions & 7 deletions backend/geonature/core/gn_synthese/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from geonature.core.gn_meta.models import TDatasets, TAcquisitionFramework
from geonature.core.ref_geo.models import LAreas
from geonature.core.ref_geo.models import LiMunicipalities
from geonature.core.gn_commons.models import THistoryActions, TValidations, last_validation, \
TMedias, TModules
from geonature.utils.env import DB, db
Expand Down Expand Up @@ -282,10 +281,7 @@ def has_instance_permission(self, scope):
return True
if g.current_user in self.cor_observers:
return True
if scope == 2:
if g.current_user.organisme in self.dataset.organism_actors:
return True
return False
return self.dataset.has_instance_permission(scope)
elif scope == 3:
return True

Expand Down Expand Up @@ -467,8 +463,8 @@ def serialize_geofn(self, geoCol, idCol):
class VColorAreaTaxon(DB.Model):
__tablename__ = "v_color_taxon_area"
__table_args__ = {"schema": "gn_synthese"}
cd_nom = DB.Column(DB.Integer(), ForeignKey("taxonomie.taxref.cd_nom"), primary_key=True)
id_area = DB.Column(DB.Integer(), ForeignKey("ref_geo.l_area.id_area"), primary_key=True)
cd_nom = DB.Column(DB.Integer(), ForeignKey(Taxref.cd_nom), primary_key=True)
id_area = DB.Column(DB.Integer(), ForeignKey(LAreas.id_area), primary_key=True)
nb_obs = DB.Column(DB.Integer())
last_date = DB.Column(DB.DateTime())
color = DB.Column(DB.Unicode())
13 changes: 10 additions & 3 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time

from collections import OrderedDict
from warnings import warn

from flask import Blueprint, request, current_app, send_from_directory, render_template, jsonify
from werkzeug.exceptions import Forbidden, NotFound
Expand Down Expand Up @@ -765,7 +766,11 @@ def get_color_taxon():
"""
params = request.args
limit = int(params.get("limit", 100))
offset = int(params.get("offset", 0))
page = params.get("page", 1, int)

if "offset" in request.args:
warn("offset is deprecated, please use page for pagination (start at 1)", DeprecationWarning)
page = (int(request.args["offset"]) / limit) + 1
id_areas_type = params.getlist("code_area_type")
cd_noms = params.getlist("cd_nom")
id_areas = params.getlist("id_area")
Expand All @@ -780,11 +785,13 @@ def get_color_taxon():
if not LAreas in [mapper.class_ for mapper in q._join_entities]:
q = q.join(LAreas, LAreas.id_area == VColorAreaTaxon.id_area)
q = q.filter(LAreas.id_area.in_(tuple(id_areas)))
q = q.order_by(VColorAreaTaxon.cd_nom).order_by(VColorAreaTaxon.id_area)
if len(cd_noms) > 0:
q = q.filter(VColorAreaTaxon.cd_nom.in_(tuple(cd_noms)))
data = q.limit(limit).offset(offset).all()
results = q.paginate(page=page, per_page=limit, error_out=False)


return jsonify([d.as_dict() for d in data])
return jsonify([d.as_dict() for d in results.items])


@routes.route("/taxa_count", methods=["GET"])
Expand Down
2 changes: 1 addition & 1 deletion backend/geonature/core/users/register_post_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def send_email_for_recovery(data):
"""
user = data["role"]
recipients = current_app.config["MAIL_CONFIG"]["MAIL_USERNAME"]
url_password = current_app.config["URL_APPLICATION"] + "#/new-password?token=" + data["token"]
url_password = current_app.config["URL_APPLICATION"] + "/#/new-password?token=" + data["token"]

msg_html = render_template(
"email_login_and_new_pass.html",
Expand Down
1 change: 1 addition & 0 deletions backend/geonature/utils/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class GnGeneralSchemaConf(Schema):
API_ENDPOINT = fields.Url(required=True)
API_TAXHUB = fields.Url(required=True)
LOCAL_SRID = fields.Integer(load_default=2154)
CODE_APPLICATION = fields.String(load_default='GN')
XML_NAMESPACE = fields.String(load_default="{http://inpn.mnhn.fr/mtd}")
MTD_API_ENDPOINT = fields.Url(load_default="https://preprod-inpn.mnhn.fr/mtd")
CAS_PUBLIC = fields.Nested(CasFrontend, load_default=CasFrontend().load({}))
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pypnnomenclature@https://github.com/PnX-SI/Nomenclature-api-module/archive/1.5.1
pypn_habref_api@https://github.com/PnX-SI/Habref-api-module/archive/0.3.0.tar.gz
utils-flask-sqlalchemy-geo@https://github.com/PnX-SI/Utils-Flask-SQLAlchemy-Geo/archive/0.2.2.zip
utils-flask-sqlalchemy@https://github.com/PnX-SI/Utils-Flask-SQLAlchemy/archive/0.2.6.zip
taxhub@https://github.com/PnX-SI/TaxHub/archive/1.9.3.zip
taxhub@https://github.com/PnX-SI/TaxHub/archive/1.9.4.zip
2 changes: 1 addition & 1 deletion config/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ install_usershub_schema=true
usershub_release=2.2.1

# Définir dans quelle version de TaxHub (release, branche ou tag) prendre le code SQL permettant la création du schéma taxonomie de la base de données de GeoNature
taxhub_release=1.9.0
taxhub_release=1.9.4

# Proxy - si le serveur sur lequel se trouve GeoNature se trouve derrière un proxy
# laisser vide si vous n'avez pas de proxy
Expand Down
23 changes: 22 additions & 1 deletion docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
CHANGELOG
=========

2.9.1 (2022-01-27)
------------------

**🚀 Nouveautés**

* Utilisation du paramètre ``page`` de Flask à la place du paramètre maison ``offset`` pour la pagination des routes (rétro-compatible)
* Installation de TaxHub en version 1.9.4 (version corrective) par défaut
* Ajout du paramètre de configuration ``CODE_APPLICATION`` (par défaut ``GN``) (#1635)

**🐛 Corrections**

* Correction de l'URL de réinitialisation de mot passe envoyée par email (#1620)
* Correction d’un problème d’authentification avec le CAS
* Occtax : Correction des listes déroulantes masquées dans le bloc dénombrement, en rajoutant un scroll
* Correction de l'URL de l'API de TaxHub (slash final manquant) pour l'affichage des photos sur la fiche d'un profil de taxon
* Correction de la synchronisation des métadonnées depuis MTD
* Correction de la génération du token quand on utilise le CAS de l'INPN pour se connecter à GeoNature
* Correction des permissions trop restrictives d’accès aux données de la synthèse
* Correction de la pagination de la route ``/color_taxon`` en rajoutant un ordonnancement par ``cd_nom`` et ``id_area`` (utilisé par Occtax-mobile)
* Contournement d'un problème de redirection incorrecte par l’API de TaxHub lorsque celui-ci est mal configuré (#1438, #1616)

2.9.0 - Actias luna (2022-01-13)
--------------------------------

Expand Down Expand Up @@ -35,7 +56,7 @@ CHANGELOG
* Association automatique et paramétrable des jeux de données personnels auto-générés à des modules (Occtax par défaut) (#1555)
* Utilisation du C du CRUVED de l'utilisateur pour lister les jeux de données dans lesquels il peut ajouter des données dans les différents modules (et non plus le R du CRUVED sur GeoNature) (#659)

**Corrections**
**🐛 Corrections**

* [OCCTAX] Correction de l'enregistrement des dénombrements lors de l'enchainement des relevés (#1479 par @jbrieuclp)
* [OCCTAX] Correction du filtre du champs "Habitat" par typologie d'habitat
Expand Down
21 changes: 21 additions & 0 deletions docs/versions-compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ COMPATIBILITE

Versions fournies et testées des dépendances

GeoNature 2.9.1
---------------

+----------------------------+---------+
| Application / Module | Version |
+============================+=========+
| TaxHub | 1.9.4 |
+----------------------------+---------+
| UsersHub | 2.2.2 |
+----------------------------+---------+
| Nomenclature-Api | 1.5.1 |
+----------------------------+---------+
| Authentification-Api | 1.5.9 |
+----------------------------+---------+
| Habref-Api | 0.3.0 |
+----------------------------+---------+
| Utils-Flask-SQLAlchemy | 0.2.6 |
+----------------------------+---------+
| Utils-Flask-SQLAlchemy-Geo | 0.2.2 |
+----------------------------+---------+

GeoNature 2.9.0
---------------

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/GN2CommonModule/form/data-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class DataFormService {

getTaxaBibList() {
return Observable.of([])
return this._http.get<any>(`${AppConfig.API_TAXHUB}/biblistes`).map(d => d.data);
return this._http.get<any>(`${AppConfig.API_TAXHUB}/biblistes/`).map(d => d.data);
}

async getTaxonInfoSynchrone(cd_nom: number): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[placeholder]="placeholder||label"
[virtualScroll]="true"
[formControl]="parentFormControl"
appendTo="body"
>
<ng-template
ng-option-tmp
Expand Down
Loading

0 comments on commit 7af2c82

Please sign in to comment.