feat(user): implement user restrictions
## APIs Restricted for Restricted Users
A restricted user is blocked from performing the following actions, and will typically receive a `403 Forbidden` error:
* **Chat & Notifications:**
* Sending any chat messages (public or private).
* Joining or leaving chat channels.
* Creating new PM channels.
* **User Profile & Content:**
* Uploading a new avatar.
* Uploading a new profile cover image.
* Changing their username.
* Updating their userpage content.
* **Scores & Gameplay:**
* Submitting scores in multiplayer rooms.
* Deleting their own scores (to prevent hiding evidence of cheating).
* **Beatmaps:**
* Rating beatmaps.
* Taging beatmaps.
* **Relationship:**
* Adding friends or blocking users.
* Removing friends or unblocking users.
* **Teams:**
* Creating, updating, or deleting a team.
* Requesting to join a team.
* Handling join requests for a team they manage.
* Kicking a member from a team they manage.
* **Multiplayer:**
* Creating or deleting multiplayer rooms.
* Joining or leaving multiplayer rooms.
## What is Invisible to Normal Users
* **Leaderboards:**
* Beatmap leaderboards.
* Multiplayer (playlist) room leaderboards.
* **User Search/Lists:**
* Restricted users will not appear in the results of the `/api/v2/users` endpoint.
* They will not appear in the list of a team's members.
* **Relationship:**
* They will not appear in a user's friend list (`/friends`).
* **Profile & History:**
* Attempting to view a restricted user's profile, events, kudosu history, or score history will result in a `404 Not Found` error, effectively making their profile invisible (unless the user viewing the profile is the restricted user themselves).
* **Chat:**
* Normal users cannot start a new PM with a restricted user (they will get a `404 Not Found` error).
* **Ranking:**
* Restricted users are excluded from any rankings.
### How to Restrict a User
Insert into `user_account_history` with `type=restriction`.
```sql
-- length is in seconds
INSERT INTO user_account_history (`description`, `length`, `permanent`, `timestamp`, `type`, `user_id`) VALUE ('some description', 86400, 0, '2025-10-05 01:00:00', 'RESTRICTION', 1);
```
---
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -143,6 +143,9 @@ async def create_room(
|
||||
current_user: ClientUser,
|
||||
redis: Redis,
|
||||
):
|
||||
if await current_user.is_restricted(db):
|
||||
raise HTTPException(status_code=403, detail="Your account is restricted from multiplayer.")
|
||||
|
||||
user_id = current_user.id
|
||||
db_room = await create_playlist_room_from_api(db, room, user_id)
|
||||
await _participate_room(db_room.id, user_id, db_room, db, redis)
|
||||
@@ -189,6 +192,9 @@ async def delete_room(
|
||||
room_id: Annotated[int, Path(..., description="房间 ID")],
|
||||
current_user: ClientUser,
|
||||
):
|
||||
if await current_user.is_restricted(db):
|
||||
raise HTTPException(status_code=403, detail="Your account is restricted from multiplayer.")
|
||||
|
||||
db_room = (await db.exec(select(Room).where(Room.id == room_id))).first()
|
||||
if db_room is None:
|
||||
raise HTTPException(404, "Room not found")
|
||||
@@ -211,6 +217,9 @@ async def add_user_to_room(
|
||||
redis: Redis,
|
||||
current_user: ClientUser,
|
||||
):
|
||||
if await current_user.is_restricted(db):
|
||||
raise HTTPException(status_code=403, detail="Your account is restricted from multiplayer.")
|
||||
|
||||
db_room = (await db.exec(select(Room).where(Room.id == room_id))).first()
|
||||
if db_room is not None:
|
||||
await _participate_room(room_id, user_id, db_room, db, redis)
|
||||
@@ -235,6 +244,9 @@ async def remove_user_from_room(
|
||||
current_user: ClientUser,
|
||||
redis: Redis,
|
||||
):
|
||||
if await current_user.is_restricted(db):
|
||||
raise HTTPException(status_code=403, detail="Your account is restricted from multiplayer.")
|
||||
|
||||
db_room = (await db.exec(select(Room).where(Room.id == room_id))).first()
|
||||
if db_room is not None:
|
||||
participated_user = (
|
||||
|
||||
Reference in New Issue
Block a user