🐛 封存历史审计与手工改码取件码
This commit is contained in:
1 parent
d75044e884
commit
5db619a1e8
3 files changed
+27
No files matched your search
@@ -856,6 +856,7 @@ async def update_file(
|
||||
if not file_code:
|
||||
raise HTTPException(status_code=404, detail="文件不存在")
|
||||
target_name = file_service._build_file_activity_name(file_code)
|
||||
previous_code = file_code.code
|
||||
update_data = {}
|
||||
|
||||
if data.code is not None and data.code != file_code.code:
|
||||
@@ -879,6 +880,11 @@ async def update_file(
|
||||
update_data["expired_count"] = data.expired_count
|
||||
|
||||
await file_code.update_from_dict(update_data).save()
|
||||
if "code" in update_data:
|
||||
await ShareCodeReservations.get_or_create(
|
||||
code=previous_code,
|
||||
defaults={"file_code_id": file_code.id, "reason": "manual_update"},
|
||||
)
|
||||
if update_data:
|
||||
await file_service.record_admin_activity(
|
||||
action="file.update",
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from tortoise import connections
|
||||
|
||||
|
||||
async def migrate():
|
||||
"""把既有审计日志中的取件码也登记为永久占用。"""
|
||||
conn = connections.get("default")
|
||||
await conn.execute_query(
|
||||
"""
|
||||
INSERT OR IGNORE INTO share_code_reservations (code, file_code_id, reason)
|
||||
SELECT DISTINCT TRIM(code), file_code_id, 'historical_audit'
|
||||
FROM transfer_stats
|
||||
WHERE code IS NOT NULL AND TRIM(code) <> ''
|
||||
"""
|
||||
)
|
||||
@@ -32,6 +32,13 @@ class ShareCodeReservationTests(unittest.TestCase):
|
||||
reservation = await ShareCodeReservations.get(code="OLD_CODE")
|
||||
self.assertEqual(reservation.file_code_id, item.id)
|
||||
self.assertEqual(reservation.reason, "restored")
|
||||
|
||||
# 模拟管理员手工改码:被替换的旧码也必须永久封存。
|
||||
await ShareCodeReservations.get_or_create(
|
||||
code="MANUALOLD",
|
||||
defaults={"file_code_id": item.id, "reason": "manual_update"},
|
||||
)
|
||||
self.assertTrue(await ShareCodeReservations.filter(code="MANUALOLD").exists())
|
||||
finally:
|
||||
await Tortoise.close_connections()
|
||||
|
||||
|
||||
Reference in new issue
Block a user