Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 22, 2024
1 parent c3a5e96 commit 172ddb5
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions server/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
HTTPException,
NotAuthorizedException,
NotFoundException,
PermissionDeniedException,
ValidationException,
)
from litestar.params import Body
from litestar.response import Redirect, Template
from uuid6 import uuid7

from config import TURNSTILE_SECRET_KEY, TURNSTILE_SITE_KEY, UTC
from server.base import BadRequestException, Request, http_client, pg
from server.auth import require_user_editor, require_user_login
from server.base import AuthorizedRequest, BadRequestException, Request, http_client, pg
from server.model import Patch, Wiki
from server.router import Router

Expand Down Expand Up @@ -58,17 +58,12 @@ class CreateSuggestion:


@router
@litestar.post("/suggest")
@litestar.post("/suggest", guards=[require_user_editor])
async def suggest_api(
subject_id: int,
data: Annotated[CreateSuggestion, Body(media_type=RequestEncodingType.URL_ENCODED)],
request: Request,
request: AuthorizedRequest,
) -> Redirect:
if not request.auth:
raise PermissionDeniedException
if request.auth.allow_edit:
raise PermissionDeniedException

if not data.desc:
raise ValidationException("missing suggestion description")

Expand Down Expand Up @@ -149,11 +144,8 @@ async def suggest_api(


@router
@litestar.post("/api/delete-patch/{patch_id:str}")
async def delete_patch(patch_id: str, request: Request) -> Redirect:
if not request.auth:
raise NotAuthorizedException

@litestar.post("/api/delete-patch/{patch_id:str}", guards=[require_user_login])
async def delete_patch(patch_id: str, request: AuthorizedRequest) -> Redirect:
async with pg.acquire() as conn:
async with conn.transaction():
p = await conn.fetchrow(
Expand Down

0 comments on commit 172ddb5

Please sign in to comment.