Skip to content

Commit

Permalink
Fix/observation details (#376)
Browse files Browse the repository at this point in the history
* Ajout has_instance_permission à t_observation_details

* Fix : ajout médias aux observation détails

* Ajout média schéma

* has_instance_permission sur nouveau object
  • Loading branch information
amandine-sahl authored Oct 22, 2024
1 parent 60e0219 commit 2445004
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"medias": {
"type_widget": "medias",
"attribut_label": "Médias",
"schema_dot_table": "gn_monitoring.t_observations_details"
"schema_dot_table": "gn_monitoring.t_observation_details"
}
}
}
1 change: 1 addition & 0 deletions backend/gn_module_monitoring/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def get_id_table_location(object_type):
"site": "t_base_sites",
"visit": "t_base_visits",
"observation": "t_observations",
"observation_detail": "t_observation_details",
}

schema_name = "gn_monitoring"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Add observation details entry in bib_tables_location
Revision ID: 6f90dd1aaf69
Revises: be30fb5c1a56
Create Date: 2024-10-21 15:35:31.740577
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "6f90dd1aaf69"
down_revision = "be30fb5c1a56"
branch_labels = None
depends_on = None


def upgrade():
op.execute(
"""
INSERT INTO gn_commons.bib_tables_location(table_desc, schema_name, table_name, pk_field, uuid_field_name)
VALUES
('Table centralisant les détails des observations réalisées lors d''une visite sur un site',
'gn_monitoring', 't_observation_details', 'id_observation_detail', 'uuid_observation_detail')
ON CONFLICT(schema_name, table_name) DO NOTHING;
"""
)


def downgrade():
op.execute(
"""
DELETE FROM gn_commons.bib_tables_location
WHERE schema_name = 'gn_monitoring' AND table_name = 't_observation_details';
"""
)
11 changes: 10 additions & 1 deletion backend/gn_module_monitoring/monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_permission_by_action(self, module_code=None, object_code=None):


@serializable
class TMonitoringObservationDetails(DB.Model):
class TMonitoringObservationDetails(DB.Model, MonitoringQuery, PermissionModel):
__tablename__ = "t_observation_details"
__table_args__ = {"schema": "gn_monitoring"}

Expand All @@ -96,6 +96,15 @@ class TMonitoringObservationDetails(DB.Model):
overlaps="medias,medias",
)

def has_instance_permission(self, scope):
# Récupération de la permission des observations
if self.id_observation:
return DB.session.get(
TMonitoringObservations, self.id_observation
).has_instance_permission(scope)
else:
return True


@serializable
class TMonitoringObservations(TObservations, PermissionModel, ObservationsQuery):
Expand Down
2 changes: 2 additions & 0 deletions backend/gn_module_monitoring/monitoring/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,5 @@ class Meta:
model = TMonitoringObservationDetails
include_fk = True
load_relationships = True

medias = MA.Nested(MediaSchema, many=True)
2 changes: 1 addition & 1 deletion backend/gn_module_monitoring/monitoring/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def unflatten_specific_properties(self, properties):
def get_readable_list_object(self, relation_name, children_type):
childs_model = monitoring_definitions.MonitoringModel(object_type=children_type)

if getattr(childs_model, "has_instance_permission"):
if getattr(childs_model, "has_instance_permission", None):
scope = get_scopes_by_action(
id_role=g.current_user.id_role,
module_code=self._module_code,
Expand Down

0 comments on commit 2445004

Please sign in to comment.