Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column: TableTN #61 #78

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/pwncore/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class Team(Model):
secret_hash = fields.TextField()
coins = fields.IntField(default=0)
points = fields.IntField(default=0)

table_tn = fields.IntField(null=True)

members: fields.ReverseRelation[User]
containers: fields.ReverseRelation[Container]

Expand Down
27 changes: 27 additions & 0 deletions src/pwncore/routes/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class UserAddBody(BaseModel):
class UserRemoveBody(BaseModel):
tag: str

class TableTNBody(BaseModel):
table_tn: int | None


@router.get("/list")
async def team_list():
Expand Down Expand Up @@ -116,3 +119,27 @@ async def get_team_containers(response: Response, jwt: RequireJwt):
)

return result

@atomic()
@router.post("/team/{id}")
async def upsert_table_tn(id: int, data: TableTNBody, response: Response, jwt: RequireJwt):
# Admin-only access
if not jwt.get("is_admin", False):
response.status_code = 403
return {"msg_code": "not_authorized"}

# Get the team by ID
team = await Team.get_or_none(id=id)
if not team:
response.status_code = 404
return {"msg_code": "team_not_found"}

# Upsert the TableTN value
try:
team.table_tn = data.table_tn
await team.save()
except Exception:
response.status_code = 500
return {"msg_code": "db_error"}

return {"msg_code": "tabletn_upserted"}