mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-09 11:15:08 +08:00
Merge branch 'main' into 766_admin_enhancement
This commit is contained in:
@@ -28,6 +28,7 @@ def get_users_ordered_by_username(
|
|||||||
search_text: Optional[str] = None,
|
search_text: Optional[str] = None,
|
||||||
auth_method: Optional[str] = None,
|
auth_method: Optional[str] = None,
|
||||||
max_count: Optional[int] = Query(100, gt=0, le=10000),
|
max_count: Optional[int] = Query(100, gt=0, le=10000),
|
||||||
|
desc: Optional[bool] = False,
|
||||||
api_client: ApiClient = Depends(deps.get_api_client),
|
api_client: ApiClient = Depends(deps.get_api_client),
|
||||||
db: Session = Depends(deps.get_db),
|
db: Session = Depends(deps.get_db),
|
||||||
):
|
):
|
||||||
@@ -41,6 +42,7 @@ def get_users_ordered_by_username(
|
|||||||
auth_method=auth_method,
|
auth_method=auth_method,
|
||||||
search_text=search_text,
|
search_text=search_text,
|
||||||
limit=max_count,
|
limit=max_count,
|
||||||
|
desc=desc,
|
||||||
)
|
)
|
||||||
return [u.to_protocol_frontend_user() for u in users]
|
return [u.to_protocol_frontend_user() for u in users]
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ def get_users_ordered_by_display_name(
|
|||||||
auth_method: Optional[str] = None,
|
auth_method: Optional[str] = None,
|
||||||
search_text: Optional[str] = None,
|
search_text: Optional[str] = None,
|
||||||
max_count: Optional[int] = Query(100, gt=0, le=10000),
|
max_count: Optional[int] = Query(100, gt=0, le=10000),
|
||||||
|
desc: Optional[bool] = False,
|
||||||
api_client: ApiClient = Depends(deps.get_api_client),
|
api_client: ApiClient = Depends(deps.get_api_client),
|
||||||
db: Session = Depends(deps.get_db),
|
db: Session = Depends(deps.get_db),
|
||||||
):
|
):
|
||||||
@@ -68,6 +71,7 @@ def get_users_ordered_by_display_name(
|
|||||||
auth_method=auth_method,
|
auth_method=auth_method,
|
||||||
search_text=search_text,
|
search_text=search_text,
|
||||||
limit=max_count,
|
limit=max_count,
|
||||||
|
desc=desc,
|
||||||
)
|
)
|
||||||
return [u.to_protocol_frontend_user() for u in users]
|
return [u.to_protocol_frontend_user() for u in users]
|
||||||
|
|
||||||
@@ -96,6 +100,7 @@ def get_users_cursor(
|
|||||||
|
|
||||||
items: list[protocol.FrontEndUser]
|
items: list[protocol.FrontEndUser]
|
||||||
qry_max_count = max_count + 1 if lt is None or gt is None else max_count
|
qry_max_count = max_count + 1 if lt is None or gt is None else max_count
|
||||||
|
desc = lt and not gt
|
||||||
|
|
||||||
def get_next_prev(num_rows: int, lt: str | None, gt: str | None, key_fn: Callable[[protocol.FrontEndUser], str]):
|
def get_next_prev(num_rows: int, lt: str | None, gt: str | None, key_fn: Callable[[protocol.FrontEndUser], str]):
|
||||||
p, n = None, None
|
p, n = None, None
|
||||||
@@ -115,10 +120,9 @@ def get_users_cursor(
|
|||||||
num_rows = len(items)
|
num_rows = len(items)
|
||||||
if qry_max_count > max_count and num_rows == qry_max_count:
|
if qry_max_count > max_count and num_rows == qry_max_count:
|
||||||
assert not (lt and gt)
|
assert not (lt and gt)
|
||||||
if lt:
|
items = items[:-1]
|
||||||
items = items[1:]
|
if desc:
|
||||||
else:
|
items.reverse()
|
||||||
items = items[:-1]
|
|
||||||
return items, num_rows
|
return items, num_rows
|
||||||
|
|
||||||
n, p = None, None
|
n, p = None, None
|
||||||
@@ -134,6 +138,7 @@ def get_users_cursor(
|
|||||||
auth_method=auth_method,
|
auth_method=auth_method,
|
||||||
search_text=search_text,
|
search_text=search_text,
|
||||||
max_count=qry_max_count,
|
max_count=qry_max_count,
|
||||||
|
desc=desc,
|
||||||
api_client=api_client,
|
api_client=api_client,
|
||||||
db=db,
|
db=db,
|
||||||
)
|
)
|
||||||
@@ -152,6 +157,7 @@ def get_users_cursor(
|
|||||||
auth_method=auth_method,
|
auth_method=auth_method,
|
||||||
search_text=search_text,
|
search_text=search_text,
|
||||||
max_count=qry_max_count,
|
max_count=qry_max_count,
|
||||||
|
desc=desc,
|
||||||
api_client=api_client,
|
api_client=api_client,
|
||||||
db=db,
|
db=db,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ class UserRepository:
|
|||||||
auth_method: Optional[str] = None,
|
auth_method: Optional[str] = None,
|
||||||
search_text: Optional[str] = None,
|
search_text: Optional[str] = None,
|
||||||
limit: Optional[int] = 100,
|
limit: Optional[int] = 100,
|
||||||
|
desc: bool = False,
|
||||||
) -> list[User]:
|
) -> list[User]:
|
||||||
if not self.api_client.trusted:
|
if not self.api_client.trusted:
|
||||||
if not api_client_id:
|
if not api_client_id:
|
||||||
@@ -184,14 +185,13 @@ class UserRepository:
|
|||||||
pattern = "%{}%".format(search_text.replace("\\", "\\\\").replace("_", "\\_").replace("%", "\\%"))
|
pattern = "%{}%".format(search_text.replace("\\", "\\\\").replace("_", "\\_").replace("%", "\\%"))
|
||||||
qry = qry.filter(User.username.like(pattern))
|
qry = qry.filter(User.username.like(pattern))
|
||||||
|
|
||||||
if limit is not None and lte_username and not gte_username:
|
if desc:
|
||||||
# select top rows but return results in ascernding order
|
qry = qry.order_by(User.username.desc(), User.id.desc())
|
||||||
sub_qry = qry.order_by(User.username.desc(), User.id.desc()).limit(limit).subquery("u")
|
|
||||||
qry = self.db.query(User).select_entity_from(sub_qry).order_by(User.username, User.id)
|
|
||||||
else:
|
else:
|
||||||
qry = qry.order_by(User.username, User.id)
|
qry = qry.order_by(User.username, User.id)
|
||||||
if limit is not None:
|
|
||||||
qry = qry.limit(limit)
|
if limit is not None:
|
||||||
|
qry = qry.limit(limit)
|
||||||
|
|
||||||
return qry.all()
|
return qry.all()
|
||||||
|
|
||||||
@@ -205,6 +205,7 @@ class UserRepository:
|
|||||||
auth_method: Optional[str] = None,
|
auth_method: Optional[str] = None,
|
||||||
search_text: Optional[str] = None,
|
search_text: Optional[str] = None,
|
||||||
limit: Optional[int] = 100,
|
limit: Optional[int] = 100,
|
||||||
|
desc: bool = False,
|
||||||
) -> list[User]:
|
) -> list[User]:
|
||||||
|
|
||||||
if not self.api_client.trusted:
|
if not self.api_client.trusted:
|
||||||
@@ -256,13 +257,12 @@ class UserRepository:
|
|||||||
if auth_method:
|
if auth_method:
|
||||||
qry = qry.filter(User.auth_method == auth_method)
|
qry = qry.filter(User.auth_method == auth_method)
|
||||||
|
|
||||||
if limit is not None and lte_display_name and not gte_display_name:
|
if desc:
|
||||||
# select top rows but return results in ascernding order
|
qry = qry.order_by(User.display_name.desc(), User.id.desc())
|
||||||
sub_qry = qry.order_by(User.display_name.desc(), User.id.desc()).limit(limit).subquery("u")
|
|
||||||
qry = self.db.query(User).select_entity_from(sub_qry).order_by(User.display_name, User.id)
|
|
||||||
else:
|
else:
|
||||||
qry = qry.order_by(User.display_name, User.id)
|
qry = qry.order_by(User.display_name, User.id)
|
||||||
if limit is not None:
|
|
||||||
qry = qry.limit(limit)
|
if limit is not None:
|
||||||
|
qry = qry.limit(limit)
|
||||||
|
|
||||||
return qry.all()
|
return qry.all()
|
||||||
|
|||||||
Reference in New Issue
Block a user