Skip to content

Commit

Permalink
Merge pull request #2673 from PnX-SI/develop
Browse files Browse the repository at this point in the history
Develop > Master / Clean git history 2.13
  • Loading branch information
camillemonchicourt authored Aug 28, 2023
2 parents 2c3b17f + 4112da7 commit 8ce2702
Show file tree
Hide file tree
Showing 148 changed files with 5,689 additions and 2,752 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- master
- hotfixes
- develop
- fixtestfront
pull_request:
branches:
- master
Expand Down Expand Up @@ -37,17 +38,14 @@ jobs:
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "postgis_raster";'
env:
PGPASSWORD: geonatpasswd
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Add database extensions
run: |
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "hstore";'
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "uuid-ossp";'
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "pg_trgm";'
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "unaccent";'
psql -h localhost -U geonatadmin -d geonature2db -f install/assets/db/add_pg_extensions.sql
env:
PGPASSWORD: geonatpasswd
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -75,14 +73,7 @@ jobs:
working-directory: ./backend
- name: Install database
run: |
geonature db upgrade geonature@head -x local-srid=2154
geonature db autoupgrade -x local-srid=2154
geonature db upgrade geonature-samples@head
geonature db upgrade taxhub@head
geonature taxref import-v15 --skip-bdc-statuts
geonature db upgrade nomenclatures_taxonomie_data@head
geonature db upgrade ref_geo_fr_departments@head
install/03b_populate_db_for_test.sh
env:
GEONATURE_CONFIG_FILE: config/test_config.toml
# FRONTEND
Expand Down Expand Up @@ -114,6 +105,7 @@ jobs:
geonature install-gn-module contrib/gn_module_occhab OCCHAB --build=false
geonature db upgrade occhab-samples@head
geonature install-gn-module contrib/gn_module_validation VALIDATION --build=false
geonature permissions supergrant --group --nom "Grp_admin" --yes
env:
GEONATURE_CONFIG_FILE: config/test_config.toml
- name: Run GeoNature backend
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- name: Frontend code formatting check (Prettier)
uses: creyD/prettier_action@v4.3
with:
dry: True
prettier_options: --config frontend/.prettierrc --ignore-path frontend/.prettierignore --check frontend/**/*.ts contrib/*/frontend/**/*.ts
run: npm install prettier && npm run format:check
working-directory: ./frontend
32 changes: 10 additions & 22 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
debian-version: [ '10', '11' ]
debian-version: [ '10', '11', '12' ]
include:
- debian-version: '10'
python-version: '3.7'
Expand All @@ -29,6 +29,10 @@ jobs:
python-version: '3.9'
postgres-version: '13'
postgis-version: '3.2'
- debian-version: '12'
python-version: '3.11'
postgres-version: '15'
postgis-version: '3.3'

name: Debian ${{ matrix.debian-version }}

Expand All @@ -54,17 +58,14 @@ jobs:
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "postgis_raster";'
env:
PGPASSWORD: geonatpasswd
- uses: actions/checkout@v3
with:
submodules: true
- name: Add database extensions
run: |
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "hstore";'
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "uuid-ossp";'
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "pg_trgm";'
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "unaccent";'
psql -h localhost -U geonatadmin -d geonature2db -f install/assets/db/add_pg_extensions.sql
env:
PGPASSWORD: geonatpasswd
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -88,20 +89,7 @@ jobs:
GEONATURE_CONFIG_FILE: config/test_config.toml
- name: Install database
run: |
geonature db upgrade geonature@head -x local-srid=2154
geonature db autoupgrade -x local-srid=2154
geonature db upgrade ref_geo_fr_departments@head
geonature taxref import-v16
geonature db upgrade geonature-samples@head
geonature db upgrade nomenclatures_taxonomie_data@head
geonature db upgrade ref_geo_fr_municipalities@head
geonature db upgrade ref_geo_inpn_grids_5@head
geonature sensitivity add-referential \
--source-name "Référentiel sensibilité TAXREF v16 20230203" \
--url https://geonature.fr/data/inpn/sensitivity/RefSensibiliteV16_20230203.zip \
--zipfile RefSensibiliteV16_20230203.zip \
--csvfile RefSensibiliteV16_20230203/RefSensibilite_16.csv \
--encoding=iso-8859-15
install/03b_populate_db_for_test.sh
env:
GEONATURE_CONFIG_FILE: config/test_config.toml
- name: Show database status
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ backend/static/node_modules
backend/media

backend/run.py
cache/*

.vscode

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12.3
2.13.0
13 changes: 4 additions & 9 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,14 @@ COPY --from=build-utils /build/dist/*.whl .
COPY --from=build-utils-geo /build/dist/*.whl .
COPY --from=build-geonature /build/dist/*.whl .

COPY --chmod=755 /install/03b_populate_db.sh /populate_db.sh
COPY --chmod=755 /install/assets/docker_startup.sh /startup.sh

ENV GEONATURE_CONFIG_FILE ""

EXPOSE 8000

CMD [ "gunicorn", "geonature:create_app()", \
"--worker-tmp-dir=/dev/shm", \
"--name=geonature", \
"--workers=2", \
"--threads=2", \
"--access-logfile=-", \
"--error-logfile=-", \
"--bind=0.0.0.0:8000" \
]
CMD ["/startup.sh"]


FROM wheels-light AS wheels
Expand Down
2 changes: 1 addition & 1 deletion backend/dependencies/TaxHub
Submodule TaxHub updated 40 files
+7 −1 .github/workflows/pytest.yml
+1 −1 VERSION
+65 −0 apptax/migrations/versions/23c25552d707_create_bdc_status_table_if_not_exists.py
+54 −0 apptax/migrations/versions/32c5ed42bdbd_add_table_t_meta_taxref.py
+113 −0 apptax/migrations/versions/3bd542b72955_optimize_vm_taxref_for_autocomplete.py
+70 −0 apptax/migrations/versions/6607b25b2d66_taxref_set_null_to_empty_string.py
+10 −1 apptax/taxonomie/commands/migrate_taxref/commands_v15.py
+10 −1 apptax/taxonomie/commands/migrate_taxref/commands_v16.py
+22 −0 apptax/taxonomie/commands/migrate_taxref/data/5_clean_db.sql
+2 −2 apptax/taxonomie/commands/migrate_taxref/data/specific_taxref_v15_v16/3.2_alter_taxref_data.sql
+7 −1 apptax/taxonomie/commands/taxref.py
+4 −1 apptax/taxonomie/commands/taxref_v15_v16.py
+88 −47 apptax/taxonomie/commands/utils.py
+10 −0 apptax/taxonomie/models.py
+22 −1 apptax/taxonomie/routesbiblistes.py
+6 −2 apptax/taxonomie/routesbibnoms.py
+34 −17 apptax/taxonomie/routestaxref.py
+39 −32 apptax/tests/fixtures.py
+25 −0 apptax/tests/test_bib_noms.py
+27 −0 apptax/tests/test_biblistes.py
+1 −1 apptax/tests/test_media.py
+6 −0 apptax/tests/test_taxref.py
+4 −6 apptax/tests/test_taxref_last_version.py
+6 −2 apptax/utils/utilssqlalchemy.py
+1 −1 data/scripts/update_taxref/apply_changes.sh
+1 −1 data/scripts/update_taxref/clean_db.sh
+2 −2 data/scripts/update_taxref/import_taxref_v11_data.sh
+2 −2 data/scripts/update_taxref/import_taxref_v13_data.sh
+1 −1 data/scripts/update_taxref/import_taxref_v14.sh
+1 −1 dependencies/UsersHub-authentification-module
+1 −1 dependencies/Utils-Flask-SQLAlchemy
+1 −1 dependencies/Utils-Flask-SQLAlchemy-Geo
+15 −5 docs/auteurs.rst
+1,218 −0 docs/changelog.md
+0 −862 docs/changelog.rst
+1 −1 install_app.sh
+1 −1 install_db.sh
+1 −1 requirements-dependencies.in
+67 −63 requirements-dev.txt
+61 −57 requirements.txt
21 changes: 14 additions & 7 deletions backend/geonature/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from flask_sqlalchemy import before_models_committed
from werkzeug.middleware.proxy_fix import ProxyFix
from werkzeug.middleware.shared_data import SharedDataMiddleware
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.wrappers import Response
from psycopg2.errors import UndefinedTable
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError, ProgrammingError
Expand Down Expand Up @@ -51,14 +53,16 @@ def configure_alembic(alembic_config):
'migrations' entry point value of the 'gn_module' group for all modules having such entry point.
Thus, alembic will find migrations of all installed geonature modules.
"""
version_locations = alembic_config.get_main_option("version_locations", default="").split()
version_locations = set(
alembic_config.get_main_option("version_locations", default="").split()
)
if "VERSION_LOCATIONS" in config["ALEMBIC"]:
version_locations.extend(config["ALEMBIC"]["VERSION_LOCATIONS"].split())
version_locations |= set(config["ALEMBIC"]["VERSION_LOCATIONS"].split())
for entry_point in chain(
entry_points(group="alembic", name="migrations"),
entry_points(group="gn_module", name="migrations"),
):
version_locations += [entry_point.value]
version_locations.add(entry_point.value)
alembic_config.set_main_option("version_locations", " ".join(version_locations))
return alembic_config

Expand Down Expand Up @@ -95,9 +99,6 @@ def create_app(with_external_mods=True):

app.config.update(config)

if "SCRIPT_NAME" not in os.environ:
os.environ["SCRIPT_NAME"] = app.config["APPLICATION_ROOT"].rstrip("/")

# Enable deprecation warnings in debug mode
if app.debug and not sys.warnoptions:
warnings.filterwarnings(action="default", category=DeprecationWarning)
Expand All @@ -106,6 +107,11 @@ def create_app(with_external_mods=True):
app.wsgi_app = SchemeFix(app.wsgi_app, scheme=config.get("PREFERRED_URL_SCHEME"))
app.wsgi_app = ProxyFix(app.wsgi_app, x_host=1)
app.wsgi_app = RequestID(app.wsgi_app)
if app.config["APPLICATION_ROOT"] != "/":
app.wsgi_app = DispatcherMiddleware(
Response("Not Found", status=404),
{app.config["APPLICATION_ROOT"].rstrip("/"): app.wsgi_app},
)

if config.get("CUSTOM_STATIC_FOLDER"):
app.wsgi_app = SharedDataMiddleware(
Expand Down Expand Up @@ -156,6 +162,8 @@ def load_current_user():
g.current_user = user_from_token(request.cookies["token"]).role
except (KeyError, UnreadableAccessRightsError, AccessRightsExpiredError):
g.current_user = None
g._permissions_by_user = {}
g._permissions = {}

if config.get("SENTRY_DSN"):
from sentry_sdk import set_tag, set_user
Expand Down Expand Up @@ -190,7 +198,6 @@ def set_sentry_context():
("ref_geo.routes:routes", "/geo"),
("geonature.core.gn_commons.routes:routes", "/gn_commons"),
("geonature.core.gn_permissions.routes:routes", "/permissions"),
("geonature.core.gn_permissions.backoffice.views:routes", "/permissions_backoffice"),
("geonature.core.users.routes:routes", "/users"),
("geonature.core.gn_synthese.routes:routes", "/synthese"),
("geonature.core.gn_meta.routes:routes", "/meta"),
Expand Down
1 change: 1 addition & 0 deletions backend/geonature/core/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import geonature.core.gn_permissions.admin
20 changes: 20 additions & 0 deletions backend/geonature/core/admin/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import partial

from flask import g
from werkzeug.exceptions import Unauthorized

Expand Down Expand Up @@ -33,3 +35,21 @@ def can_delete(self):
@property
def can_export(self):
return self._can_action("E")


# https://github.com/flask-admin/flask-admin/issues/1807
# https://stackoverflow.com/questions/54638047/correct-way-to-register-flask-admin-views-with-application-factory
class ReloadingIterator:
def __init__(self, iterator_factory):
self.iterator_factory = iterator_factory

def __iter__(self):
return self.iterator_factory()


class DynamicOptionsMixin:
def get_dynamic_options(self, view):
raise NotImplementedError

def get_options(self, view):
return ReloadingIterator(partial(self.get_dynamic_options, view))
14 changes: 7 additions & 7 deletions backend/geonature/core/gn_commons/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from geonature.core.admin.utils import CruvedProtectedMixin
from geonature.core.gn_commons.models import TModules
from geonature.core.gn_permissions.models import TObjects
from geonature.core.gn_permissions.models import PermObject
from geonature.core.gn_commons.schemas import TAdditionalFieldsSchema
from geonature.utils.env import DB

Expand Down Expand Up @@ -86,8 +86,8 @@ class BibFieldAdmin(CruvedProtectedMixin, ModelView):
)
},
"objects": {
"query_factory": lambda: DB.session.query(TObjects).filter(
TObjects.code_object.in_(
"query_factory": lambda: DB.session.query(PermObject).filter(
PermObject.code_object.in_(
current_app.config["ADDITIONAL_FIELDS"]["IMPLEMENTED_OBJECTS"]
)
)
Expand All @@ -97,9 +97,9 @@ class BibFieldAdmin(CruvedProtectedMixin, ModelView):
"bib_nomenclature_type": "Si Type widget = Nomenclature",
"field_label": "Label du champ en interface",
"field_name": "Nom du champ en base de donnée",
"field_values": """Obligatoire si widget = select/multiselect/checkbox,radio (Format JSON : tableau de 'value/label'.Utilisez des doubles quotes pour les valeurs et les clés).
"field_values": """Obligatoire si widget = select/multiselect/checkbox,radio (Format JSON : tableau de 'value/label'. Utilisez des doubles quotes pour les valeurs et les clés).
Exemple [{"label": "trois", "value": 3}, {"label": "quatre", "value": 4}]""",
"default_value": "La valeur par défaut doit être une des valeurs du champs 'Valeurs' ci dessus",
"default_value": "La valeur par défaut doit être une des valeurs du champs 'Valeurs' ci-dessus. Pour les valeurs textuelles, il n'est pas nécessaire de remettre la valeur entre guillement",
"id_list": "Identifiant en BDD de la liste (pour Type widget = taxonomy/observers)",
"field_order": "Numéro d'ordonnancement du champs (si plusieurs champs pour le même module/objet/JDD)",
"modules": "Module(s) auquel le champs est rattaché. *Obligatoire",
Expand All @@ -110,7 +110,7 @@ class BibFieldAdmin(CruvedProtectedMixin, ModelView):

class TMobileAppsAdmin(CruvedProtectedMixin, ModelView):
module_code = "ADMIN"
object_code = "ALL"
object_code = "MOBILE_APPS"

column_list = (
"app_code",
Expand All @@ -132,7 +132,7 @@ class TMobileAppsAdmin(CruvedProtectedMixin, ModelView):

class TModulesAdmin(CruvedProtectedMixin, ModelView):
module_code = "ADMIN"
object_code = "ALL"
object_code = "MODULES"

can_view_details = True
action_disallowed_list = ["delete"]
Expand Down
4 changes: 0 additions & 4 deletions backend/geonature/core/gn_commons/medias/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def insert_or_update_media(id_media=None):

m = TMediaRepository(data=data, file=file, id_media=id_media).create_or_update_media()

TMediumRepository.sync_medias()

return m.as_dict()


Expand All @@ -106,8 +104,6 @@ def delete_media(id_media):

TMediaRepository(id_media=id_media).delete()

TMediumRepository.sync_medias()

return {"resp": "media {} deleted".format(id_media)}


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

from .base import cor_field_module, cor_field_object, cor_field_dataset
from geonature.core.gn_meta.models import TDatasets
from geonature.core.gn_permissions.models import TObjects
from geonature.core.gn_permissions.models import PermObject


@serializable
Expand Down Expand Up @@ -49,8 +49,8 @@ class TAdditionalFields(DB.Model):
"TModules",
secondary=cor_field_module,
)
objects = DB.relationship("TObjects", secondary=cor_field_object)
datasets = DB.relationship("TDatasets", secondary=cor_field_dataset)
objects = DB.relationship(PermObject, secondary=cor_field_object)
datasets = DB.relationship(TDatasets, secondary=cor_field_dataset)

def __str__(self):
return f"{self.field_label} ({self.description})"
2 changes: 1 addition & 1 deletion backend/geonature/core/gn_commons/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TModules(DB.Model):
meta_update_date = DB.Column(DB.DateTime)

objects = DB.relationship(
"TObjects", secondary=lambda: _resolve_import_cor_object_module(), backref="modules"
"PermObject", secondary=lambda: _resolve_import_cor_object_module(), backref="modules"
)
# relationship datasets add via backref

Expand Down
Loading

0 comments on commit 8ce2702

Please sign in to comment.