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 856ac38
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions server/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +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 import require_user_login

Check failure on line 19 in server/contrib.py

View workflow job for this annotation

GitHub Actions / mypy

Module "server" does not explicitly export attribute "require_user_login"
from server.auth import require_user_editor
from server.base import BadRequestException, Request, http_client, pg
from server.model import Patch, Wiki
from server.router import Router
Expand Down Expand Up @@ -58,17 +59,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,
) -> 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 +145,8 @@ async def suggest_api(


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

async with pg.acquire() as conn:
async with conn.transaction():
p = await conn.fetchrow(
Expand Down

0 comments on commit 856ac38

Please sign in to comment.