Skip to content

Commit 8fffb14

Browse files
authored
Fixes #102: Защитить ручки Lecturer/Photo (#107)
* Lecturer Photo Security * Makefile * Comment deprication * Style
1 parent 8976081 commit 8fffb14

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

calendar_backend/routes/lecturer/comment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
settings = get_settings()
13-
router = APIRouter(prefix="/lecturer/{lecturer_id}", tags=["Lecturer: Comment"])
13+
router = APIRouter(prefix="/lecturer/{lecturer_id}", tags=["Lecturer: Comment"], deprecated=True)
1414

1515

1616
@router.post("/comment/", response_model=CommentLecturer)

calendar_backend/routes/lecturer/comment_review.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from calendar_backend.routes.models import CommentLecturer
1212

1313

14-
router = APIRouter(prefix="/lecturer/{lecturer_id}/comment", tags=["Lecturer: Comment Review"])
14+
router = APIRouter(prefix="/lecturer/{lecturer_id}/comment", tags=["Lecturer: Comment Review"], deprecated=True)
1515

1616

1717
@router.get("/review/", response_model=list[CommentLecturer])

calendar_backend/routes/lecturer/photo.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from fastapi import APIRouter, File, UploadFile
1+
from auth_lib.fastapi import UnionAuth
2+
from fastapi import APIRouter, Depends, File, UploadFile
23
from fastapi_sqlalchemy import db
34

45
from calendar_backend.exceptions import ObjectNotFound
@@ -14,7 +15,11 @@
1415

1516

1617
@router.post("/photo", response_model=Photo)
17-
async def upload_photo(lecturer_id: int, photo: UploadFile = File(...)) -> Photo:
18+
async def upload_photo(
19+
lecturer_id: int,
20+
photo: UploadFile = File(...),
21+
_=Depends(UnionAuth(scopes=["timetable.lecturer.photo.create"])),
22+
) -> Photo:
1823
"""Загрузить фотографию преподавателя из локального файла
1924
2025
Пример загрузки файла на питоне
@@ -50,7 +55,11 @@ async def get_lecturer_photos(lecturer_id: int, limit: int = 10, offset: int = 0
5055

5156

5257
@router.delete("/photo/{id}", response_model=None)
53-
async def delete_photo(id: int, lecturer_id: int) -> None:
58+
async def delete_photo(
59+
id: int,
60+
lecturer_id: int,
61+
_=Depends(UnionAuth(scopes=["timetable.lecturer.photo.delete"])),
62+
) -> None:
5463
photo = DbPhoto.get(id, only_approved=False, session=db.session)
5564
if photo.lecturer_id != lecturer_id:
5665
raise ObjectNotFound(DbPhoto, id)

0 commit comments

Comments
 (0)