diff --git a/server/mergin/sync/models.py b/server/mergin/sync/models.py index 0d65c8bf..08fecb71 100644 --- a/server/mergin/sync/models.py +++ b/server/mergin/sync/models.py @@ -35,7 +35,6 @@ Storages = {"local": DiskStorage} project_deleted = signal("project_deleted") -project_version_created = signal("project_version_created") class PushChangeType(Enum): @@ -809,8 +808,6 @@ def __init__( self.project_size = self.project.disk_usage db.session.flush() - project_version_created.send(self) - @staticmethod def from_v_name(name: str) -> int: """Parsed version name as integer (v5 -> 5)""" diff --git a/server/mergin/sync/private_api_controller.py b/server/mergin/sync/private_api_controller.py index 5bac41bd..c6122166 100644 --- a/server/mergin/sync/private_api_controller.py +++ b/server/mergin/sync/private_api_controller.py @@ -6,19 +6,20 @@ from flask import render_template, request, current_app, jsonify, abort from flask_login import current_user from sqlalchemy.orm import defer -from sqlalchemy import text +from sqlalchemy import text, and_, desc, asc from .. import db from ..auth import auth_required from ..auth.models import User, UserProfile from .forms import AccessPermissionForm -from .models import Project, AccessRequest, ProjectRole, RequestStatus +from .models import Project, AccessRequest, ProjectRole, RequestStatus, ProjectVersion from .schemas import ( ProjectListSchema, ProjectAccessRequestSchema, AdminProjectSchema, ProjectAccessSchema, ProjectAccessDetailSchema, + ProjectVersionListSchema, ) from .permissions import ( require_project_by_uuid, diff --git a/server/mergin/sync/public_api_controller.py b/server/mergin/sync/public_api_controller.py index 66367b73..b7c70c2c 100644 --- a/server/mergin/sync/public_api_controller.py +++ b/server/mergin/sync/public_api_controller.py @@ -12,6 +12,7 @@ from typing import Dict from urllib.parse import quote import uuid +from time import time from datetime import datetime import psycopg2 from blinker import signal @@ -86,6 +87,7 @@ from ..utils import format_time_delta push_triggered = signal("push_triggered") +project_version_created = signal("project_version_created") def parse_project_access_update_request(access: Dict) -> Dict: @@ -232,6 +234,7 @@ def add_project(namespace): # noqa: E501 db.session.add(pa) db.session.add(version) db.session.commit() + project_version_created.send(version) return NoContent, 200 @@ -870,6 +873,7 @@ def project_push(namespace, project_name): f"A project version {ProjectVersion.to_v_name(next_version)} for project: {project.id} created. " f"Transaction id: {upload.id}. No upload." ) + project_version_created.send(pv) return jsonify(ProjectSchema().dump(project)), 200 except IntegrityError as err: db.session.rollback() @@ -1079,6 +1083,7 @@ def push_finish(transaction_id): logging.info( f"Push finished for project: {project.id}, project version: {v_next_version}, transaction id: {transaction_id}." ) + project_version_created.send(pv) except (psycopg2.Error, FileNotFoundError, DataSyncError, IntegrityError) as err: db.session.rollback() logging.exception( @@ -1210,6 +1215,7 @@ def clone_project(namespace, project_name): # noqa: E501 db.session.add(pa) db.session.add(project_version) db.session.commit() + project_version_created.send(project_version) return NoContent, 200 diff --git a/server/mergin/tests/utils.py b/server/mergin/tests/utils.py index 0128553d..4e6905ef 100644 --- a/server/mergin/tests/utils.py +++ b/server/mergin/tests/utils.py @@ -10,6 +10,7 @@ from dataclasses import asdict from datetime import datetime +import pysqlite3 from flask import url_for, current_app import os from dateutil.tz import tzlocal