v1
This commit is contained in:
@@ -6,7 +6,7 @@ from flask import Blueprint, abort, current_app, flash, redirect, render_templat
|
||||
from flask_login import current_user, login_required, login_user
|
||||
|
||||
from ..extensions import db
|
||||
from ..uploads import abs_upload_path, ensure_company_upload_dir, is_valid_upload_relpath
|
||||
from ..uploads import abs_upload_path, ensure_company_upload_dir, get_company_upload_bytes, is_valid_upload_relpath
|
||||
from ..models import Company, Display, DisplaySession, Playlist, PlaylistItem, User
|
||||
|
||||
bp = Blueprint("admin", __name__, url_prefix="/admin")
|
||||
@@ -75,7 +75,52 @@ def company_detail(company_id: int):
|
||||
company = db.session.get(Company, company_id)
|
||||
if not company:
|
||||
abort(404)
|
||||
return render_template("admin/company_detail.html", company=company)
|
||||
|
||||
upload_root = current_app.config["UPLOAD_FOLDER"]
|
||||
used_bytes = get_company_upload_bytes(upload_root, company.id)
|
||||
|
||||
return render_template(
|
||||
"admin/company_detail.html",
|
||||
company=company,
|
||||
storage={
|
||||
"used_bytes": used_bytes,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/companies/<int:company_id>/storage")
|
||||
@login_required
|
||||
def update_company_storage(company_id: int):
|
||||
admin_required()
|
||||
|
||||
company = db.session.get(Company, company_id)
|
||||
if not company:
|
||||
abort(404)
|
||||
|
||||
raw = (request.form.get("storage_max_mb") or "").strip()
|
||||
if raw == "":
|
||||
# Treat empty as unlimited
|
||||
company.storage_max_bytes = None
|
||||
db.session.commit()
|
||||
flash("Storage limit cleared (unlimited).", "success")
|
||||
return redirect(url_for("admin.company_detail", company_id=company_id))
|
||||
|
||||
try:
|
||||
mb = float(raw)
|
||||
except ValueError:
|
||||
flash("Invalid storage limit. Please enter a number (MB).", "danger")
|
||||
return redirect(url_for("admin.company_detail", company_id=company_id))
|
||||
|
||||
if mb <= 0:
|
||||
company.storage_max_bytes = None
|
||||
db.session.commit()
|
||||
flash("Storage limit cleared (unlimited).", "success")
|
||||
return redirect(url_for("admin.company_detail", company_id=company_id))
|
||||
|
||||
company.storage_max_bytes = int(mb * 1024 * 1024)
|
||||
db.session.commit()
|
||||
flash("Storage limit updated.", "success")
|
||||
return redirect(url_for("admin.company_detail", company_id=company_id))
|
||||
|
||||
|
||||
@bp.post("/companies/<int:company_id>/users")
|
||||
|
||||
Reference in New Issue
Block a user