Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floutage des données sensibles #2687

Merged
merged 12 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jobs:
add_sample_data: true
install_sig_layers: true
install_grid_layer_5: true
install_grid_layer_10: true
install_ref_sensitivity: true
# FRONTEND
- name: Cache node modules
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ jobs:
--health-retries 5

steps:
- name: Add postgis_raster database extension
if: ${{ matrix.postgis-version >= 3 }}
run: |
psql -h localhost -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "postgis_raster";'
env:
PGPASSWORD: geonatpasswd
- uses: actions/checkout@v4
with:
submodules: true
Expand Down Expand Up @@ -104,6 +98,7 @@ jobs:
add_sample_data: true
install_sig_layers: true
install_grid_layer_5: true
install_grid_layer_10: true
install_ref_sensitivity: true
- name: Show database status
run: |
Expand Down
5 changes: 3 additions & 2 deletions backend/geonature/core/gn_commons/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class Meta:
model = TValidations
load_instance = True
include_fk = True
validation_label = fields.Nested(NomenclatureSchema, dump_only=True)
validator_role = MA.Nested(UserSchema, dump_only=True)

validation_label = fields.Nested(NomenclatureSchema, dump_only=True)
validator_role = MA.Nested(UserSchema, dump_only=True)


class BibWidgetSchema(MA.SQLAlchemyAutoSchema):
Expand Down
4 changes: 4 additions & 0 deletions backend/geonature/core/gn_meta/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
from geonature.utils.schema import CruvedSchemaMixin
from geonature.core.gn_commons.models import TModules
from geonature.core.gn_commons.schemas import ModuleSchema

# Note: import of SourceSchema is importent as it trigger import of synthese models
# which define TDatasets.sources & TDatasets.synthese_records_count, and these must be
# defined before AutoSchema creation to be known by marshmallow!
from geonature.core.gn_synthese.schemas import SourceSchema
from geonature.core.gn_permissions.tools import get_scopes_by_action

Expand Down
6 changes: 5 additions & 1 deletion backend/geonature/core/gn_permissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sqlalchemy import select

from geonature.utils.env import db
from geonature.utils.config import config
from geonature.core.admin.admin import admin
from geonature.core.admin.utils import CruvedProtectedMixin, DynamicOptionsMixin
from geonature.core.gn_permissions.models import (
Expand Down Expand Up @@ -356,7 +357,10 @@ class PermissionAdmin(CruvedProtectedMixin, ModelView):
"role.nom_complet": "nom du rôle",
"availability": "Permission",
"scope": "Filtre sur l'appartenance des données",
"sensitivity_filter": "Exclure les données sensibles",
"sensitivity_filter": (
"Flouter" if config["SYNTHESE"]["BLUR_SENSITIVE_OBSERVATIONS"] else "Exclure"
)
+ " les données sensibles",
}
column_select_related_list = ("availability",)
column_searchable_list = ("role.identifiant", "role.nom_complet")
Expand Down
18 changes: 15 additions & 3 deletions backend/geonature/core/gn_synthese/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
joinedload,
contains_eager,
deferred,
query_expression,
)
from sqlalchemy.sql import select, func, exists
from sqlalchemy.schema import FetchedValue
Expand All @@ -20,7 +21,7 @@
from geoalchemy2.shape import to_shape

from geojson import Feature
from flask import g
from flask import g, current_app
import flask_sqlalchemy
from utils_flask_sqla.models import qfilter

Expand Down Expand Up @@ -414,6 +415,7 @@
the_geom_4326_geojson = column_property(func.ST_AsGeoJSON(the_geom_4326), deferred=True)
the_geom_point = deferred(DB.Column(Geometry("GEOMETRY", 4326)))
the_geom_local = deferred(DB.Column(Geometry("GEOMETRY")))
the_geom_authorized = query_expression()
precision = DB.Column(DB.Integer)
id_area_attachment = DB.Column(DB.Integer, ForeignKey(LAreas.id_area))
date_min = DB.Column(DB.DateTime, nullable=False)
Expand Down Expand Up @@ -455,13 +457,23 @@
return True

def _has_permissions_grant(self, permissions):
blur_sensitive_observations = current_app.config["SYNTHESE"]["BLUR_SENSITIVE_OBSERVATIONS"]
if not permissions:
return False
for perm in permissions:
if perm.has_other_filters_than("SCOPE", "SENSITIVITY"):
continue # unsupported filters
if perm.sensitivity_filter and self.nomenclature_sensitivity.cd_nomenclature != "0":
continue # sensitivity filter denied access, check next permission
if perm.sensitivity_filter:
if (
blur_sensitive_observations
and self.nomenclature_sensitivity.cd_nomenclature == "4"
):
continue

Check warning on line 471 in backend/geonature/core/gn_synthese/models.py

View check run for this annotation

Codecov / codecov/patch

backend/geonature/core/gn_synthese/models.py#L471

Added line #L471 was not covered by tests
if (
not blur_sensitive_observations
and self.nomenclature_sensitivity.cd_nomenclature != "0"
):
continue
if perm.scope_value:
if g.current_user == self.digitiser:
return True
Expand Down
Loading