Skip to content

Column: TableTN #61 #78

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
53 changes: 3 additions & 50 deletions src/pwncore/routes/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from pwncore.config import config
from pwncore.models import Team, User, Team_Pydantic, User_Pydantic, Container
from pwncore.routes.auth import RequireJwt
from pwncore.routes.admin import ADMIN_HASH

# from pwncore.routes.leaderboard import gcache

# Metadata at the top for instant caccessibility
# Metadata at the top for instant accessibility
metadata = {"name": "team", "description": "Operations with teams"}

router = APIRouter(prefix="/team", tags=["team"])
Expand Down Expand Up @@ -120,58 +121,10 @@ async def get_team_containers(response: Response, jwt: RequireJwt):

return result

@atomic()
@router.post("/remove")
async def remove_member(user_info: UserRemoveBody, response: Response, jwt: RequireJwt):
team_id = jwt["team_id"]
user = await User.get_or_none(team_id=team_id, tag=user_info.tag)

if not user:
response.status_code = 403
return {"msg_code": config.msg_codes["user_not_in_team"]}

try:
await user.delete()
except Exception:
response.status_code = 500
return {"msg_code": config.msg_codes["db_error"]}

return {"msg_code": config.msg_codes["user_removed"]}


@router.get("/containers")
async def get_team_containers(response: Response, jwt: RequireJwt):
containers = await Container.filter(team_id=jwt["team_id"]).prefetch_related(
"ports", "problem"
)

result = {
container.problem.id: await container.ports.all().values_list("port", flat=True)
for container in containers
}

return result


@atomic()
@router.post("team/{id}")
async def upsert_table_tn(id: int, data: TableTNBody, request: Request, response: Response):
admin_password = (await request.body()).strip()

if not bcrypt.verify(admin_password, ADMIN_HASH):
response.status_code = 401
return {"msg_code": "not_authorized"}

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

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"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were NOT meant to be removed.

response.status_code = 401