feat(files): the Downloads page goes — the tray, a Storage tab and a Downloads settings tab take its place
- The Downloads module, its rail icon and badge are gone. A bookmark, the remembered page and an old
history entry that name it land on Files (urlState.resolvePage); `g d` goes to Files too.
- Users page: a Storage tab — the disk in numbers, every user's use against their own limit with
their file count, every user's downloads; aligned tables, one menu per row (edit / reset quota,
open source, copy, the owner's quota). The admin storage rows carry quota + file count, the admin
job list its owner.
- Settings: a Downloads tab — the download formats in one list (duplicate a built-in, edit or delete
your own) and the site sign-ins, moved from Account.
- "View" on an added download, a clip or a converting upload opens the tray on that row (unfolded,
back if closed; a finished one opens as a file; under a player it opens without taking focus).
- The download dialog opens on the format used last.
- DataTable: `pager={false}` for a short list, `cardRow` to give a lone "…" its own card line.
- Welcome and README speak of Files; a new Files screenshot.
This commit is contained in:
@@ -842,6 +842,7 @@ def admin_list_downloads(
|
||||
out = []
|
||||
for j in jobs:
|
||||
data = serialize(j, assets.get(j.asset_id) if j.asset_id is not None else None)
|
||||
data["user_id"] = j.user_id
|
||||
data["user_email"] = emails.get(j.user_id)
|
||||
out.append(data)
|
||||
return out
|
||||
@@ -860,19 +861,35 @@ def admin_storage(admin: User = Depends(admin_user), db: Session = Depends(get_d
|
||||
.where(DownloadJob.asset_id.is_not(None))
|
||||
.group_by(DownloadJob.user_id)
|
||||
).all()
|
||||
emails = {
|
||||
u.id: u.email
|
||||
for u in db.execute(select(User).where(User.id.in_([uid for uid, _ in per_user]))).scalars()
|
||||
uids = [uid for uid, _ in per_user]
|
||||
emails = {u.id: u.email for u in db.execute(select(User).where(User.id.in_(uids))).scalars()}
|
||||
# What each one's Files lists: their finished files.
|
||||
files: dict[int, int] = {
|
||||
uid: n
|
||||
for uid, n in db.execute(
|
||||
select(DownloadJob.user_id, func.count())
|
||||
.where(DownloadJob.user_id.in_(uids), DownloadJob.status == JobStatus.DONE)
|
||||
.group_by(DownloadJob.user_id)
|
||||
).tuples()
|
||||
}
|
||||
|
||||
def row(uid: int) -> dict:
|
||||
lim = quota.resolve(db, uid)
|
||||
return {
|
||||
"user_id": uid,
|
||||
"email": emails.get(uid),
|
||||
"footprint_bytes": quota.footprint(db, uid),
|
||||
"files": files.get(uid, 0),
|
||||
"max_bytes": lim.max_bytes,
|
||||
"unlimited": lim.unlimited,
|
||||
}
|
||||
|
||||
return {
|
||||
"files_on_disk": on_disk[0],
|
||||
"total_bytes": int(on_disk[1]),
|
||||
"total_assets": total_assets,
|
||||
"total_cap_bytes": sysconfig.get_int(db, "download_total_max_bytes"),
|
||||
"per_user": [
|
||||
{"user_id": uid, "email": emails.get(uid), "footprint_bytes": quota.footprint(db, uid)}
|
||||
for uid, _ in per_user
|
||||
],
|
||||
"per_user": [row(uid) for uid in uids],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -598,6 +598,29 @@ def test_the_admin_storage_view_counts_a_waiting_upload(db, as_user, make_user,
|
||||
assert {p["user_id"]: p["footprint_bytes"] for p in r["per_user"]} == {u.id: 10}
|
||||
|
||||
|
||||
def test_the_admin_storage_view_names_each_users_quota_and_files(
|
||||
db, as_user, make_user, _root, monkeypatch
|
||||
):
|
||||
# A row says how full the user is against THEIR limit (a custom one, here), and how many files
|
||||
# their Files lists — the finished ones, not one still waiting for its conversion.
|
||||
_probe(monkeypatch)
|
||||
u = make_user()
|
||||
done, _ = _ingest(db, _root, u.id, size=10)
|
||||
waiting, _ = _ingest(db, _root, u.id, name="b.mov", size=5)
|
||||
done.status, waiting.status = "done", "queued"
|
||||
db.commit()
|
||||
admin = as_user(make_user(role="admin"))
|
||||
put = admin.put(f"/api/admin/downloads/quota/{u.id}", json={"max_bytes": 1000})
|
||||
assert put.status_code == 200
|
||||
row = admin.get("/api/admin/downloads/storage").json()["per_user"]
|
||||
assert [(p["user_id"], p["files"], p["max_bytes"], p["unlimited"]) for p in row] == [
|
||||
(u.id, 1, 1000, False)
|
||||
]
|
||||
# Every download names its owner, so its row can open THEIR quota.
|
||||
jobs = admin.get("/api/admin/downloads").json()
|
||||
assert {(j["id"], j["user_id"]) for j in jobs} == {(done.id, u.id), (waiting.id, u.id)}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("job_status", "asset_status", "ref_count"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user