Skip to content

Commit f93ff69

Browse files
authored
delete user records
1 parent 95cd0ca commit f93ff69

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ def admin_clear():
239239
res = db[col].delete_many({})
240240
return jsonify({"deleted": res.deleted_count})
241241

242+
@app.route('/api/admin/clear_user_records', methods=['POST'])
243+
def admin_clear_user_records():
244+
"""Wist alle records van een specifieke gebruiker in een collectie."""
245+
db = get_db()
246+
if db is None: return jsonify({'error': 'DB Offline'}), 500
247+
data = request.json
248+
col = data.get('collection')
249+
client_id = data.get('client_id')
250+
if not col: return jsonify({'error': 'Geen collectie opgegeven'}), 400
251+
if not client_id: return jsonify({'error': 'Geen client_id opgegeven'}), 400
252+
res = db[col].delete_many({'_meta.owner': client_id})
253+
return jsonify({"deleted": res.deleted_count})
254+
242255
@app.route('/api/admin/bulk_delete', methods=['POST'])
243256
def admin_bulk_delete():
244257
db = get_db()

dashboard.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ <h2 id="det-name" class="text-3xl font-bold text-white tracking-tight">...</h2>
165165
<button onclick="triggerImport()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Import"><i class="fas fa-upload"></i></button>
166166
<button onclick="doClone()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Kloon"><i class="fas fa-copy"></i></button>
167167
<button onclick="truncateEndpoint()" class="w-10 h-10 rounded-xl bg-yellow-500/10 hover:bg-yellow-500/20 flex items-center justify-center text-yellow-500 transition border border-yellow-500/20" title="Leegmaken"><i class="fas fa-eraser"></i></button>
168+
<button onclick="clearUserRecords()" class="w-10 h-10 rounded-xl bg-orange-500/10 hover:bg-orange-500/20 flex items-center justify-center text-orange-500 transition border border-orange-500/20" title="Verwijder gebruiker records"><i class="fas fa-user-times"></i></button>
168169
<button onclick="dropEndpoint()" class="w-10 h-10 rounded-xl bg-red-500/10 hover:bg-red-500/20 flex items-center justify-center text-red-500 transition border border-red-500/20" title="Drop"><i class="fas fa-trash-alt"></i></button>
169170
</div>
170171
</div>
@@ -476,6 +477,19 @@ <h3 class="text-xl font-bold text-white">Data Lifecycle</h3>
476477
}
477478

478479
async function truncateEndpoint() { if(confirm("⚠️ Alle data in deze collectie wissen?")) { await fetch(`${API}/api/admin/clear`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ collection: currentEp })}); refresh(); } }
480+
async function clearUserRecords() {
481+
const defaultUser = (currentFilter.type === 'USER') ? currentFilter.value : '';
482+
const clientId = prompt("Client ID van de gebruiker wiens records je wilt verwijderen:", defaultUser);
483+
if (!clientId) return;
484+
if(confirm(`⚠️ Alle records van gebruiker "${clientId}" in deze collectie wissen?`)) {
485+
await fetch(`${API}/api/admin/clear_user_records`, {
486+
method: 'POST',
487+
headers: {'Content-Type':'application/json'},
488+
body: JSON.stringify({ collection: currentEp, client_id: clientId })
489+
});
490+
refresh();
491+
}
492+
}
479493
async function dropEndpoint() { if(confirm("⛔ COLLECTIE VOLLEDIG VERWIJDEREN?")) { await fetch(`${API}/api/admin/collections/${currentEp}`, { method: 'DELETE' }); window.location.reload(); } }
480494
function downloadEndpoint() { window.location.href = `${API}/api/admin/export/${currentEp}`; }
481495
async function doClone() { const d = prompt("Naam voor kopie:"); if(d) { await fetch(`${API}/api/admin/clone`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ source: currentEp, destination: d })}); refresh(); } }

0 commit comments

Comments
 (0)