Remove delete functionality from vehicles and buildings

- Remove DELETE endpoints for vehicles and buildings from api.py
- Remove delete_vehicle() method from vehicle service
- Remove delete buttons from vehicles.html and buildings.html
This commit is contained in:
Reditus committed 2026-05-19 05:56:27 +01:00
1 parent 6e7a850ba2
commit e977f8cd5b
4 files changed
+2 -71

No files matched your search

+1 -39
View File
@@ -608,49 +608,11 @@ def register_api_routes(app, services, settings):
return jsonify({'success': False, 'error': str(e)}) return jsonify({'success': False, 'error': str(e)})
# Delete vehicle # Delete vehicle
@app.route('/api/vehicles/<int:vehicle_id>', methods=['DELETE'])
@auth_req
def delete_vehicle(vehicle_id):
success, message = vehicle_svc.delete_vehicle(vehicle_id)
if success: if success:
return jsonify({'success': True, 'message': message}) return jsonify({'success': True, 'message': message})
return jsonify({'success': False, 'error': message}), 404 if 'not found' in message.lower() else 500 return jsonify({'success': False, 'error': message}), 404 if 'not found' in message.lower() else 500
# Delete building
@app.route('/api/buildings/<int:building_id>', methods=['DELETE'])
@auth_req
def delete_building(building_id):
conn = db.get_connection()
if not conn:
return jsonify({'success': False, 'error': 'Database connection failed'}), 500
cur = None
try:
cur = conn.cursor()
cur.execute("SET session_replication_role = replica")
cur.execute("DELETE FROM dune.building_instances WHERE building_id = %s", [building_id])
cur.execute("DELETE FROM dune.buildings WHERE id = %s RETURNING id", [building_id])
deleted = cur.fetchone()
if deleted:
cur.execute("DELETE FROM dune.actors WHERE id = %s RETURNING id", [building_id])
conn.commit()
cur.execute("SET session_replication_role = default")
return jsonify({'success': True, 'message': f'Building {building_id} deleted'})
else:
conn.rollback()
cur.execute("SET session_replication_role = default")
return jsonify({'success': False, 'error': 'Building not found'}), 404
except Exception as e:
logger.error(f"Failed to delete building {building_id}: {e}")
try:
cur.execute("SET session_replication_role = default")
except Exception:
pass
return jsonify({'success': False, 'error': str(e)}), 500
finally:
if cur:
cur.close()
db.return_connection(conn)
# Debug endpoints (should be restricted in production) # Debug endpoints (should be restricted in production)
@app.route('/api/debug/vehicle_properties/<int:vehicle_id>') @app.route('/api/debug/vehicle_properties/<int:vehicle_id>')
@auth_req @auth_req
+1 -30
View File
@@ -126,33 +126,4 @@ class VehicleService:
ORDER BY id ORDER BY id
""", [vehicle_id]) or [] """, [vehicle_id]) or []
def delete_vehicle(self, vehicle_id):
conn = self.db.get_connection()
if not conn:
return False, "Database connection failed"
cur = None
try:
cur = conn.cursor()
cur.execute("SET session_replication_role = replica")
cur.execute("DELETE FROM dune.vehicles WHERE id = %s RETURNING id", [vehicle_id])
deleted = cur.fetchone()
if deleted:
cur.execute("DELETE FROM dune.actors WHERE id = %s RETURNING id", [vehicle_id])
conn.commit()
cur.execute("SET session_replication_role = default")
return True, f"Vehicle {vehicle_id} deleted"
else:
conn.rollback()
cur.execute("SET session_replication_role = default")
return False, "Vehicle not found"
except Exception as e:
logger.error(f"Failed to delete vehicle {vehicle_id}: {e}")
try:
cur.execute("SET session_replication_role = default")
except Exception:
pass
return False, str(e)
finally:
if cur:
cur.close()
self.db.return_connection(conn)
-1
View File
@@ -38,7 +38,6 @@
<td>{% if b.is_powered == 'True' %}<span class="badge badge-online">Powered</span>{% elif b.is_powered == 'False' %}<span class="badge" style="background:#666;color:#fff;">Unpowered</span>{% else %}?{% endif %}</td> <td>{% if b.is_powered == 'True' %}<span class="badge badge-online">Powered</span>{% elif b.is_powered == 'False' %}<span class="badge" style="background:#666;color:#fff;">Unpowered</span>{% else %}?{% endif %}</td>
<td>{{ b.instance_count }}</td> <td>{{ b.instance_count }}</td>
<td style="font-size:11px;font-family:monospace;max-width:200px;word-break:break-all;">{{ b.transform_text or '' }}</td> <td style="font-size:11px;font-family:monospace;max-width:200px;word-break:break-all;">{{ b.transform_text or '' }}</td>
<td><button class="btn-delete" data-id="{{ b.id }}" data-type="building" title="Delete">🗑️</button></td>
</tr> </tr>
{% else %} {% else %}
<tr><td colspan="8" class="empty">No buildings found</td></tr> <tr><td colspan="8" class="empty">No buildings found</td></tr>
-1
View File
@@ -57,7 +57,6 @@
<td>{% if v.pilot_name %}<span class="badge badge-online">Active</span> <a href="/players/{{ v.pilot_pawn_id }}">{{ v.pilot_name }}</a>{% else %}&mdash;{% endif %}</td> <td>{% if v.pilot_name %}<span class="badge badge-online">Active</span> <a href="/players/{{ v.pilot_pawn_id }}">{{ v.pilot_name }}</a>{% else %}&mdash;{% endif %}</td>
<td>{{ v.map or 'N/A' }}</td> <td>{{ v.map or 'N/A' }}</td>
<td style="font-size:11px;font-family:monospace;max-width:250px;word-break:break-all;">{{ v.transform_text or '' }}</td> <td style="font-size:11px;font-family:monospace;max-width:250px;word-break:break-all;">{{ v.transform_text or '' }}</td>
<td><button class="btn-delete" data-id="{{ v.id }}" data-type="vehicle" title="Delete">🗑️</button></td>
</tr> </tr>
{% else %} {% else %}
<tr><td colspan="8" class="empty">No vehicles found</td></tr> <tr><td colspan="8" class="empty">No vehicles found</td></tr>