WebHost: allow deleting Rooms and Seeds, as well as their associated data (#3071)
This commit is contained in:
parent
5e5792009c
commit
3c564d7b96
|
@ -6,6 +6,7 @@ import multiprocessing
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
from uuid import UUID
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
|
|
||||||
from pony.orm import db_session, select, commit
|
from pony.orm import db_session, select, commit
|
||||||
|
@ -62,6 +63,16 @@ def autohost(config: dict):
|
||||||
def keep_running():
|
def keep_running():
|
||||||
try:
|
try:
|
||||||
with Locker("autohost"):
|
with Locker("autohost"):
|
||||||
|
# delete unowned user-content
|
||||||
|
with db_session:
|
||||||
|
# >>> bool(uuid.UUID(int=0))
|
||||||
|
# True
|
||||||
|
rooms = Room.select(lambda room: room.owner == UUID(int=0)).delete(bulk=True)
|
||||||
|
seeds = Seed.select(lambda seed: seed.owner == UUID(int=0) and not seed.rooms).delete(bulk=True)
|
||||||
|
slots = Slot.select(lambda slot: not slot.seed).delete(bulk=True)
|
||||||
|
# Command gets deleted by ponyorm Cascade Delete, as Room is Required
|
||||||
|
if rooms or seeds or slots:
|
||||||
|
logging.info(f"{rooms} Rooms, {seeds} Seeds and {slots} Slots have been deleted.")
|
||||||
run_guardian()
|
run_guardian()
|
||||||
while 1:
|
while 1:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
@ -191,6 +202,6 @@ def run_guardian():
|
||||||
guardian = threading.Thread(name="Guardian", target=guard)
|
guardian = threading.Thread(name="Guardian", target=guard)
|
||||||
|
|
||||||
|
|
||||||
from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed
|
from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed, Slot
|
||||||
from .customserver import run_server_process, get_static_server_data
|
from .customserver import run_server_process, get_static_server_data
|
||||||
from .generate import gen_game
|
from .generate import gen_game
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<th class="center">Players</th>
|
<th class="center">Players</th>
|
||||||
<th>Created (UTC)</th>
|
<th>Created (UTC)</th>
|
||||||
<th>Last Activity (UTC)</th>
|
<th>Last Activity (UTC)</th>
|
||||||
|
<th>Mark for deletion</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
<td>{{ room.seed.slots|length }}</td>
|
<td>{{ room.seed.slots|length }}</td>
|
||||||
<td>{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
|
<td>{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
|
||||||
<td>{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }}</td>
|
<td>{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }}</td>
|
||||||
|
<td><a href="{{ url_for("disown_room", room=room.id) }}">Delete next maintenance.</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -51,6 +53,7 @@
|
||||||
<th>Seed</th>
|
<th>Seed</th>
|
||||||
<th class="center">Players</th>
|
<th class="center">Players</th>
|
||||||
<th>Created (UTC)</th>
|
<th>Created (UTC)</th>
|
||||||
|
<th>Mark for deletion</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -60,6 +63,7 @@
|
||||||
<td>{% if seed.multidata %}{{ seed.slots|length }}{% else %}1{% endif %}
|
<td>{% if seed.multidata %}{{ seed.slots|length }}{% else %}1{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
|
<td>{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
|
||||||
|
<td><a href="{{ url_for("disown_seed", seed=seed.id) }}">Delete next maintenance.</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import zipfile
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from flask import request, flash, redirect, url_for, session, render_template
|
from flask import request, flash, redirect, url_for, session, render_template, abort
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
from pony.orm import commit, flush, select, rollback
|
from pony.orm import commit, flush, select, rollback
|
||||||
from pony.orm.core import TransactionIntegrityError
|
from pony.orm.core import TransactionIntegrityError
|
||||||
|
@ -219,3 +219,29 @@ def user_content():
|
||||||
rooms = select(room for room in Room if room.owner == session["_id"])
|
rooms = select(room for room in Room if room.owner == session["_id"])
|
||||||
seeds = select(seed for seed in Seed if seed.owner == session["_id"])
|
seeds = select(seed for seed in Seed if seed.owner == session["_id"])
|
||||||
return render_template("userContent.html", rooms=rooms, seeds=seeds)
|
return render_template("userContent.html", rooms=rooms, seeds=seeds)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/disown_seed/<suuid:seed>", methods=["GET"])
|
||||||
|
def disown_seed(seed):
|
||||||
|
seed = Seed.get(id=seed)
|
||||||
|
if not seed:
|
||||||
|
return abort(404)
|
||||||
|
if seed.owner != session["_id"]:
|
||||||
|
return abort(403)
|
||||||
|
|
||||||
|
seed.owner = 0
|
||||||
|
|
||||||
|
return redirect(url_for("user_content"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/disown_room/<suuid:room>", methods=["GET"])
|
||||||
|
def disown_room(room):
|
||||||
|
room = Room.get(id=room)
|
||||||
|
if not room:
|
||||||
|
return abort(404)
|
||||||
|
if room.owner != session["_id"]:
|
||||||
|
return abort(403)
|
||||||
|
|
||||||
|
room.owner = 0
|
||||||
|
|
||||||
|
return redirect(url_for("user_content"))
|
||||||
|
|
Loading…
Reference in New Issue