admin improve, uploading bot messages
This commit is contained in:
1 parent
0c1bee31f4
commit
77921ba6a8
3 files changed
+81
-18
No files matched your search
+19
-15
@@ -1153,20 +1153,24 @@ async def s_api_v1_admin_licenses(request):
|
||||
filters.append(UserContent.status.in_(status_values))
|
||||
applied_filters['status'] = status_values
|
||||
|
||||
license_type_field = cast(UserContent.meta['license_type'], String)
|
||||
|
||||
if license_type_param:
|
||||
lt_values: List[int] = []
|
||||
lt_values: List[str] = []
|
||||
for part in license_type_param.split(','):
|
||||
part = part.strip()
|
||||
if not part:
|
||||
continue
|
||||
try:
|
||||
lt_values.append(int(part))
|
||||
except ValueError:
|
||||
continue
|
||||
part = (part or '').strip()
|
||||
if part:
|
||||
lt_values.append(part)
|
||||
if lt_values:
|
||||
license_type_expr = cast(UserContent.meta['license_type'].astext, Integer)
|
||||
filters.append(license_type_expr.in_(lt_values))
|
||||
applied_filters['license_type'] = lt_values
|
||||
clauses = []
|
||||
plain_values = [value for value in lt_values if value.lower() not in {'unknown', 'null'}]
|
||||
if plain_values:
|
||||
clauses.append(license_type_field.in_(plain_values))
|
||||
if any(value.lower() in {'unknown', 'null'} for value in lt_values):
|
||||
clauses.append(license_type_field.is_(None))
|
||||
if clauses:
|
||||
filters.append(or_(*clauses))
|
||||
applied_filters['license_type'] = lt_values
|
||||
|
||||
if user_id_param:
|
||||
try:
|
||||
@@ -1291,14 +1295,14 @@ async def s_api_v1_admin_licenses(request):
|
||||
type_counts_rows = (await session.execute(type_stmt)).all()
|
||||
type_counts = {ctype or 'unknown': int(count or 0) for ctype, count in type_counts_rows}
|
||||
|
||||
license_type_expr = func.coalesce(cast(UserContent.meta['license_type'].astext, Integer), -1)
|
||||
license_type_stmt = select(license_type_expr.label('license_type'), func.count()).group_by('license_type')
|
||||
license_type_expr = func.coalesce(license_type_field, 'unknown')
|
||||
license_type_stmt = select(license_type_expr.label('license_type'), func.count()).group_by(license_type_expr)
|
||||
if filters:
|
||||
license_type_stmt = license_type_stmt.where(and_(*filters))
|
||||
license_type_counts_rows = (await session.execute(license_type_stmt)).all()
|
||||
license_type_counts: Dict[str, int] = {}
|
||||
for lt_value, count in license_type_counts_rows:
|
||||
key = 'unknown' if lt_value in (None, -1) else str(int(lt_value))
|
||||
key = 'unknown' if lt_value in (None, 'null', 'None') else str(lt_value)
|
||||
license_type_counts[key] = int(count or 0)
|
||||
|
||||
items: List[Dict[str, Any]] = []
|
||||
@@ -1721,7 +1725,7 @@ async def s_api_v1_admin_node_setrole(request):
|
||||
row = (await session.execute(select(KnownNode).where(KnownNode.ip == host))).scalars().first()
|
||||
if not row:
|
||||
return response.json({"error": "NOT_FOUND"}, status=404)
|
||||
meta = row.meta or {}
|
||||
meta = {**(row.meta or {})}
|
||||
meta['role'] = role
|
||||
row.meta = meta
|
||||
await session.commit()
|
||||
|
||||
Reference in new issue
Block a user