mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
Read through services in the scoped routes
The workspace-scoped mobile and shared-variable routes queried models in the controller, which the boundary inventory counts as new crossings. They now go through WorkspaceService and ManagedDatabaseService; the baseline drops the two crossings the mobile routes no longer make.
This commit is contained in:
1 parent
7768318e31
commit
ebb19c8444
5 files changed
+12
-15
No files matched your search
@@ -9,6 +9,9 @@ from app.services.workspace_service import WorkspaceService
|
||||
|
||||
mobile_bp = Blueprint('mobile', __name__)
|
||||
|
||||
# How many servers the offline cache carries.
|
||||
OFFLINE_CACHE_SERVERS = 50
|
||||
|
||||
|
||||
@mobile_bp.route('/push/register', methods=['POST'])
|
||||
@jwt_required()
|
||||
@@ -99,12 +102,10 @@ def get_mobile_summary():
|
||||
except Exception:
|
||||
metrics = {}
|
||||
|
||||
from app.models.server import Server
|
||||
from app.models.security_alert import SecurityAlert
|
||||
|
||||
# Only the servers this caller can reach — the workspace rule /servers applies.
|
||||
server_count = WorkspaceService.filter_accessible_servers(
|
||||
Server.query, get_current_user()).count()
|
||||
server_count = len(WorkspaceService.accessible_servers(get_current_user()))
|
||||
active_alerts = SecurityAlert.query.filter_by(resolved=False).count() if hasattr(SecurityAlert, 'resolved') else 0
|
||||
|
||||
# MonitoringService returns nested sections; a section that could not be
|
||||
@@ -124,10 +125,7 @@ def get_mobile_summary():
|
||||
@jwt_required()
|
||||
def get_offline_data():
|
||||
"""Get data for offline caching."""
|
||||
from app.models.server import Server
|
||||
|
||||
servers = WorkspaceService.filter_accessible_servers(
|
||||
Server.query, get_current_user()).limit(50).all()
|
||||
servers = WorkspaceService.accessible_servers(get_current_user())[:OFFLINE_CACHE_SERVERS]
|
||||
return jsonify({
|
||||
'servers': [{'id': s.id, 'name': s.name, 'hostname': s.hostname, 'status': s.status} for s in servers],
|
||||
'cached_at': __import__('datetime').datetime.utcnow().isoformat(),
|
||||
|
||||
@@ -32,7 +32,8 @@ def _require_server(server_id):
|
||||
# reads the proxy state but may not change it.
|
||||
if (request.method not in ('GET', 'HEAD', 'OPTIONS') and server.workspace_id
|
||||
and not WorkspaceService.can_write_in_workspace(user, server.workspace_id)):
|
||||
return None, (jsonify({'error': 'You have read-only access to this workspace'}), 403)
|
||||
from app.exceptions import PermissionDeniedError
|
||||
raise PermissionDeniedError('You have read-only access to this workspace')
|
||||
return server, None
|
||||
|
||||
|
||||
|
||||
@@ -189,9 +189,9 @@ def _check_resource_read(resource_type, resource_id):
|
||||
return _bad('access denied', 403)
|
||||
return None
|
||||
if resource_type == 'database':
|
||||
from app.models.managed_database import ManagedDatabase
|
||||
from app.services.managed_database_service import ManagedDatabaseService
|
||||
try:
|
||||
row = ManagedDatabase.query_active().filter_by(id=int(resource_id)).first()
|
||||
row = ManagedDatabaseService.get(int(resource_id))
|
||||
except (TypeError, ValueError):
|
||||
row = None
|
||||
if row is None:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"policy": "Exact reviewed inventory of direct persistence, subprocess, and filesystem mutation calls in Flask API controllers. New calls are forbidden; remove entries as controllers delegate to services.",
|
||||
"counts": {
|
||||
"filesystem": 8,
|
||||
"persistence": 445
|
||||
"persistence": 443
|
||||
},
|
||||
"owners": {
|
||||
"api/admin.py": {
|
||||
@@ -501,8 +501,6 @@
|
||||
"api/manifests.py::reset_bootstrap::persistence::db.session.commit()::1",
|
||||
"api/manifests.py::scaffold_manifest::persistence::Application.query_active().filter_by(id=app_id).first()::1",
|
||||
"api/mobile.py::get_mobile_summary::persistence::SecurityAlert.query.filter_by(resolved=False).count()::1",
|
||||
"api/mobile.py::get_mobile_summary::persistence::Server.query.count()::1",
|
||||
"api/mobile.py::get_offline_data::persistence::Server.query.limit(50).all()::1",
|
||||
"api/mobile.py::register_push::persistence::User.query.get(user_id)::1",
|
||||
"api/mobile.py::register_push::persistence::db.session.commit()::1",
|
||||
"api/notifications.py::get_user_preferences::persistence::User.query.get(current_user_id)::1",
|
||||
|
||||
@@ -18,8 +18,8 @@ debt. Regenerate with `python scripts/generate-migration-inventory.py`.
|
||||
| API crashes swallowed without recording | app.error_reporting | 0 | 0 | INVARIANT at 0 |
|
||||
| Hand-shaped {'error': ...} bodies in app/api | typed errors + the global handler | 849 | 850 | migrate when touched; new endpoints raise |
|
||||
| Raw subprocess calls outside the runners | app/utils/system.py runners | 23 | 23 | migrate when touched |
|
||||
| Controller-boundary violations (routes doing service work) | service layer extraction | 453 | 453 | migrate when touched (first-wave ratchet) |
|
||||
| raw api.* calls in pages/ | E1: useServerQuery/useServerMutation | 363 | 371 | migrate when touched |
|
||||
| Controller-boundary violations (routes doing service work) | service layer extraction | 451 | 451 | migrate when touched (first-wave ratchet) |
|
||||
| raw api.* calls in pages/ | E1: useServerQuery/useServerMutation | 364 | 371 | migrate when touched |
|
||||
| per-page toast.error extractions in pages/ | E1: query-layer error presentation | 185 | 206 | migrate when touched |
|
||||
| hand-rolled form-group blocks | F2: FormField/useForm | 206 | 206 | migrate when touched |
|
||||
| unencoded ?k=${v} query interpolations in services/api | C4: buildQuery/encoding template | 0 | 0 | INVARIANT at 0 |
|
||||
|
||||
Reference in new issue
Block a user