Skip to content

Commit

Permalink
Merge pull request #2730 from PnX-SI/develop
Browse files Browse the repository at this point in the history
Develop > Master / 2.13.2
  • Loading branch information
camillemonchicourt committed Sep 28, 2023
2 parents a978d6a + 86ba9f5 commit 0a3764b
Show file tree
Hide file tree
Showing 35 changed files with 551 additions and 144 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ jobs:
working-directory: ./backend
- name: Install database
run: |
install/03b_populate_db_for_test.sh
install/03b_populate_db.sh
env:
GEONATURE_CONFIG_FILE: config/test_config.toml
srid_local: 2154
install_bdc_statuts: true
add_sample_data: true
install_sig_layers: true
install_grid_layer_5: true
install_ref_sensitivity: true
# FRONTEND
- name: Cache node modules
uses: actions/cache@v3
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ jobs:
GEONATURE_CONFIG_FILE: config/test_config.toml
- name: Install database
run: |
install/03b_populate_db_for_test.sh
install/03b_populate_db.sh
env:
GEONATURE_CONFIG_FILE: config/test_config.toml
srid_local: 2154
install_bdc_statuts: true
add_sample_data: true
install_sig_layers: true
install_grid_layer_5: true
install_ref_sensitivity: true
- name: Show database status
run: |
geonature db status
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.13.1
2.13.2
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.2

FROM python:3.9-bullseye AS build
FROM python:3.11-bookworm AS build

ENV PIP_ROOT_USER_ACTION=ignore
RUN --mount=type=cache,target=/root/.cache \
Expand Down
13 changes: 6 additions & 7 deletions backend/geonature/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,18 @@ 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(
app.wsgi_app,
{
"/static": config["CUSTOM_STATIC_FOLDER"],
app.static_url_path: config["CUSTOM_STATIC_FOLDER"],
},
)
if app.config["APPLICATION_ROOT"] != "/":
app.wsgi_app = DispatcherMiddleware(
Response("Not Found", status=404),
{app.config["APPLICATION_ROOT"].rstrip("/"): app.wsgi_app},
)

app.json = MyJSONProvider(app)

Expand Down
1 change: 1 addition & 0 deletions backend/geonature/celery_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __call__(self, *args, **kwargs):

app.Task = ContextTask

app.conf.imports += ("geonature.tasks",)
app.conf.imports += tuple(
[ep.module for dist in iter_modules_dist() for ep in dist.entry_points.select(name="tasks")]
)
14 changes: 7 additions & 7 deletions backend/geonature/core/gn_commons/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ def get_t_mobile_apps():
if app.relative_path_apk:
relative_apk_path = Path("mobile", app.relative_path_apk)
app_dict["url_apk"] = url_for("media", filename=str(relative_apk_path), _external=True)
relative_settings_path = relative_apk_path.parent / "settings.json"
app_dict["url_settings"] = url_for(
"media", filename=relative_settings_path, _external=True
)
settings_file = Path(current_app.config["MEDIA_FOLDER"]) / relative_settings_path
with settings_file.open() as f:
app_dict["settings"] = json.load(f)
relative_settings_path = Path(f"mobile/{app.app_code.lower()}/settings.json")
app_dict["url_settings"] = url_for(
"media", filename=relative_settings_path, _external=True
)
settings_file = Path(current_app.config["MEDIA_FOLDER"]) / relative_settings_path
with settings_file.open() as f:
app_dict["settings"] = json.load(f)
mobile_apps.append(app_dict)
if len(mobile_apps) == 1:
return mobile_apps[0]
Expand Down
10 changes: 6 additions & 4 deletions backend/geonature/core/gn_meta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ def _get_read_scope(self, user=None):
cruved = get_scopes_by_action(id_role=user.id_role, module_code="METADATA")
return cruved["R"]

def _get_create_scope(self, module_code, user=None):
def _get_create_scope(self, module_code, user=None, object_code=None):
if user is None:
user = g.current_user
cruved = get_scopes_by_action(id_role=user.id_role, module_code=module_code)
cruved = get_scopes_by_action(
id_role=user.id_role, module_code=module_code, object_code=object_code
)
return cruved["C"]

def filter_by_scope(self, scope, user=None):
Expand Down Expand Up @@ -366,14 +368,14 @@ def filter_by_readable(self, user=None):
"""
return self.filter_by_scope(self._get_read_scope(user))

def filter_by_creatable(self, module_code, user=None):
def filter_by_creatable(self, module_code, user=None, object_code=None):
"""
Return all dataset where user have read rights minus those who user to not have
create rigth
"""
query = self.filter(TDatasets.modules.any(module_code=module_code))
scope = self._get_read_scope(user)
create_scope = self._get_create_scope(module_code, user=user)
create_scope = self._get_create_scope(module_code, user=user, object_code=object_code)
if create_scope < scope:
scope = create_scope
return query.filter_by_scope(scope)
Expand Down
13 changes: 12 additions & 1 deletion backend/geonature/core/gn_meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from werkzeug.datastructures import Headers
from geonature.core.gn_permissions import decorators as permissions
from geonature.core.gn_permissions.tools import get_scopes_by_action
from geonature.core.gn_permissions.models import TObjects
from geonature.core.gn_meta.mtd import mtd_utils
import geonature.utils.filemanager as fm
import geonature.utils.utilsmails as mail
Expand Down Expand Up @@ -99,15 +100,25 @@ def get_datasets():
.. :quickref: Metadata;
:query boolean active: filter on active fiel
:query string create: filter on C permission for the module_code specified
(we can specify the object_code by adding a . between both)
:query int id_acquisition_framework: get only dataset of given AF
:returns: `list<TDatasets>`
"""
params = MultiDict(request.args)
if request.is_json:
params.update(request.json)
fields = params.get("fields", type=str, default=[])
if fields:
fields = fields.split(",")
if "create" in params:
query = TDatasets.query.filter_by_creatable(params.pop("create"))
create = params.pop("create").split(".")
if len(create) > 1:
query = TDatasets.query.filter_by_creatable(
module_code=create[0], object_code=create[1]
)
else:
query = TDatasets.query.filter_by_creatable(module_code=create[0])
else:
query = TDatasets.query.filter_by_readable()

Expand Down
20 changes: 12 additions & 8 deletions backend/geonature/core/gn_meta/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ class Meta:
def module_input(self, item, original, many, **kwargs):
if "modules" in item:
for i, module in enumerate(original.modules):
if not hasattr(module, "generate_input_url_for_dataset"):
continue
object_code = getattr(module.generate_input_url_for_dataset, "object_code", "ALL")
create_scope = get_scopes_by_action(
id_role=g.current_user.id_role, module_code=module.module_code
id_role=g.current_user.id_role,
module_code=module.module_code,
object_code=object_code,
)["C"]
if not original.has_instance_permission(create_scope):
continue
if hasattr(module, "generate_input_url_for_dataset"):
item["modules"][i].update(
{
"input_url": module.generate_input_url_for_dataset(original),
"input_label": module.generate_input_url_for_dataset.label,
}
)
item["modules"][i].update(
{
"input_url": module.generate_input_url_for_dataset(original),
"input_label": module.generate_input_url_for_dataset.label,
}
)
return item

# retro-compatibility with mobile app
Expand Down
1 change: 1 addition & 0 deletions backend/geonature/core/gn_synthese/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ class VSyntheseForWebApp(DB.Model):
unique_id_sinp = DB.Column(UUID(as_uuid=True))
unique_id_sinp_grp = DB.Column(UUID(as_uuid=True))
id_source = DB.Column(DB.Integer, nullable=False)
id_module = DB.Column(DB.Integer)
entity_source_pk_value = DB.Column(DB.Integer)
id_dataset = DB.Column(DB.Integer)
dataset_name = DB.Column(DB.Integer)
Expand Down
1 change: 1 addition & 0 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ def create_report(permissions):

synthese = Synthese.query.options(
Load(Synthese).raiseload("*"),
joinedload("nomenclature_sensitivity"),
joinedload("cor_observers"),
joinedload("digitiser"),
joinedload("dataset"),
Expand Down
9 changes: 5 additions & 4 deletions backend/geonature/core/gn_synthese/utils/query_select_sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from geoalchemy2.shape import from_shape

from geonature.utils.env import DB

from geonature.core.gn_commons.models import TModules
from geonature.core.gn_synthese.models import (
CorObserverSynthese,
CorAreaSynthese,
Expand Down Expand Up @@ -372,17 +374,16 @@ def filter_other_filters(self, user):
self.query = self.query.where(self.model.id_dataset.in_(formated_datasets))
if "date_min" in self.filters:
self.query = self.query.where(self.model.date_min >= self.filters.pop("date_min"))

if "date_max" in self.filters:
# set the date_max at 23h59 because a hour can be set in timestamp
date_max = datetime.datetime.strptime(self.filters.pop("date_max"), "%Y-%m-%d")
date_max = date_max.replace(hour=23, minute=59, second=59)
self.query = self.query.where(self.model.date_max <= date_max)

if "id_source" in self.filters:
self.add_join(TSources, self.model.id_source, TSources.id_source)
self.query = self.query.where(self.model.id_source == self.filters.pop("id_source"))

self.query = self.query.where(self.model.id_source.in_(self.filters.pop("id_source")))
if "id_module" in self.filters:
self.query = self.query.where(self.model.id_module.in_(self.filters.pop("id_module")))
if "id_acquisition_framework" in self.filters:
if hasattr(self.model, "id_acquisition_framework"):
self.query = self.query.where(
Expand Down
Loading

0 comments on commit 0a3764b

Please sign in to comment.