sync
This commit is contained in:
@@ -9,7 +9,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .community_review import publish_observation
|
||||
from .models import DataSource, ExternalEntityAlias, ExternalObservation
|
||||
from .models import DataSource, ExternalEntityAlias, ExternalObservation, ModerationStatus
|
||||
|
||||
|
||||
SOURCE_DEFAULTS = {
|
||||
@@ -77,6 +77,18 @@ def stage_observations(
|
||||
session.add(observation)
|
||||
created += 1
|
||||
else:
|
||||
# Preserve the published snapshot, but withdraw it from activity until
|
||||
# a moderator confirms the changed source record.
|
||||
changed = any(getattr(observation, key) != values[key] for key in (
|
||||
"source_url", "fish_name", "fish_external_id", "waterbody_name",
|
||||
"waterbody_external_id", "x", "y", "weight_g",
|
||||
)) or observation.payload != payload
|
||||
if observation.status != "rejected" and changed and observation.catch_report is not None:
|
||||
observation.catch_report.moderation_status = ModerationStatus.pending
|
||||
observation.status = "staged"
|
||||
observation.fish = None
|
||||
observation.waterbody = None
|
||||
observation.review_note = "Source record changed; manual mapping and publication required"
|
||||
for key, value in values.items():
|
||||
setattr(observation, key, value)
|
||||
updated += 1
|
||||
@@ -90,6 +102,8 @@ def stage_observations(
|
||||
def _auto_publish(session: Session, observation: ExternalObservation) -> bool:
|
||||
"""Publish only complete observations covered by previously reviewed aliases."""
|
||||
if (
|
||||
observation.catch_report_id is not None
|
||||
or
|
||||
observation.status not in {"staged", "mapped", "ready"}
|
||||
or not observation.source.enabled
|
||||
or observation.fish_external_id is None
|
||||
|
||||
Reference in New Issue
Block a user