Skip to content

Commit

Permalink
style(backend): apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Vergez committed May 25, 2023
1 parent ba99b9f commit 0ea5172
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
5 changes: 2 additions & 3 deletions backend/geonature/core/gn_synthese/utils/query_select_sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def _filter_query_with_permissions(self, user, permissions):
.one()
)
perm_filters.append(
self.model.id_nomenclature_sensitivity
!= non_diffusion.id_nomenclature
self.model.id_nomenclature_sensitivity != non_diffusion.id_nomenclature
)
if perm.scope_value:
if perm.scope_value not in datasets_by_scope:
Expand All @@ -180,7 +179,7 @@ def _filter_query_with_permissions(self, user, permissions):
return or_(*permissions_filters)
else:
return sa.false()

def filter_query_with_permissions(self, user, permissions):
where_clause = self._filter_query_with_permissions(user=user, permissions=permissions)
self.query = self.query.where(where_clause)
Expand Down
5 changes: 3 additions & 2 deletions backend/geonature/core/sensitivity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
"id_nomenclature_sensitivity",
db.Integer,
ForeignKey("ref_nomenclatures.t_nomenclatures.id_nomenclature"),
primary_key=True
primary_key=True,
),
db.Column("id_area_type", db.Integer, ForeignKey(BibAreasTypes.id_type), primary_key=True),
schema="gn_sensitivity"
schema="gn_sensitivity",
)


class SensitivityRule(db.Model):
__tablename__ = "t_sensitivity_rules"
__table_args__ = {"schema": "gn_sensitivity"}
Expand Down
36 changes: 24 additions & 12 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,27 +672,39 @@ def test_get_autocomplete_taxons_synthese(self, synthese_data, users):
def synthese_module():
return TModules.query.filter_by(module_code="SYNTHESE").one()


@pytest.fixture()
def synthese_read_permissions(synthese_module):
def _synthese_read_permissions(role, scope_value, action="R", **kwargs):
action = PermAction.query.filter_by(code_action=action).one()
with db.session.begin_nested():
db.session.add(
Permission(
role=role, action=action, module=synthese_module, scope_value=scope_value, **kwargs
)
)
Permission(
role=role,
action=action,
module=synthese_module,
scope_value=scope_value,
**kwargs,
)
)

return _synthese_read_permissions


@pytest.mark.usefixtures("client_class", "temporary_transaction")
class TestSyntheseBlurring:
def test_split_blurring_permissions(self, app, users, synthese_module, synthese_read_permissions):
def test_split_blurring_permissions(
self, app, users, synthese_module, synthese_read_permissions
):
current_user = users["self_user"]
with app.test_request_context(headers=logged_user_headers(current_user)):
app.preprocess_request()
permissions = get_permissions(action_code="R", id_role=current_user.id_role,
module_code=synthese_module.module_code, object_code="ALL")
permissions = get_permissions(
action_code="R",
id_role=current_user.id_role,
module_code=synthese_module.module_code,
object_code="ALL",
)
sensitive, unsensitive = split_blurring_permissions(permissions=permissions)

assert all(s.sensitivity_filter for s in sensitive)
Expand All @@ -701,11 +713,11 @@ def test_split_blurring_permissions(self, app, users, synthese_module, synthese_
def test_synthese_blurring(self, users, synthese_module, synthese_read_permissions):
current_user = users["self_user"]
set_logged_user_cookie(self.client, current_user)
# None is 3
# None is 3
synthese_read_permissions(current_user, None, sensitivity_filter=True)
synthese_read_permissions(current_user, 2, sensitivity_filter=False)

url = url_for("gn_synthese.get_observations_for_web")
r = self.client.get(url)
assert False

assert False

0 comments on commit 0ea5172

Please sign in to comment.