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

feat: Added proper scopes to media routes #118

Merged
merged 4 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/app/api/routes/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ async def create_media_from_device(payload: BaseMedia,


@router.get("/{media_id}/", response_model=MediaOut, summary="Get information about a specific media")
async def get_media(media_id: int = Path(..., gt=0)):
async def get_media(media_id: int = Path(..., gt=0), _=Security(get_current_access, scopes=["admin"])):
"""
Based on a media_id, retrieves information about the specified media
"""
return await crud.get_entry(media, media_id)


@router.get("/", response_model=List[MediaOut], summary="Get the list of all media")
async def fetch_media():
async def fetch_media(_=Security(get_current_access, scopes=["admin"])):
"""
Retrieves the list of all media and their information
"""
Expand Down Expand Up @@ -94,7 +94,7 @@ async def delete_media(media_id: int = Path(..., gt=0), _=Security(get_current_a


@router.post("/{media_id}/upload", response_model=MediaOut, status_code=200)
async def upload_media(
async def upload_media_from_device(
background_tasks: BackgroundTasks,
media_id: int = Path(..., gt=0),
file: UploadFile = File(...),
Expand Down
24 changes: 11 additions & 13 deletions src/tests/routes/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
{"id": 2, "login": "connected_user", "access_id": 2, "created_at": "2020-11-13T08:18:45.447773"},
]

DEVICE_TABLE = [{"id": 1, "login": "connected_device", "owner_id": 1,
"access_id": 3, "specs": "raspberry", "elevation": None, "lat": None,
"lon": None, "yaw": None, "pitch": None,
"last_ping": None, "created_at": "2020-10-13T08:18:45.447773"},
{"id": 2, "login": "second_device", "owner_id": 2,
"access_id": 4, "specs": "v0.1", "elevation": None, "lat": None,
"lon": None, "yaw": None, "pitch": None,
"last_ping": None, "created_at": "2020-10-13T08:18:45.447773"},
{"id": 3, "login": "third_device", "owner_id": 1,
"access_id": 5, "specs": "v0.1", "elevation": None,
"lat": None, "lon": None, "yaw": None, "pitch": None, "last_ping": None,
"created_at": "2020-10-13T08:18:45.447773"}
]
DEVICE_TABLE = [
{"id": 1, "login": "connected_device", "owner_id": 1, "access_id": 3, "specs": "raspberry",
"elevation": None, "lat": None, "lon": None, "yaw": None, "pitch": None, "last_ping": None,
"created_at": "2020-10-13T08:18:45.447773"},
{"id": 2, "login": "second_device", "owner_id": 2, "access_id": 4, "specs": "v0.1",
"elevation": None, "lat": None, "lon": None, "yaw": None, "pitch": None, "last_ping": None,
"created_at": "2020-10-13T08:18:45.447773"},
{"id": 3, "login": "third_device", "owner_id": 1, "access_id": 5, "specs": "v0.1",
"elevation": None, "lat": None, "lon": None, "yaw": None, "pitch": None, "last_ping": None,
"created_at": "2020-10-13T08:18:45.447773"},
]

CONNECTED_DEVICE_ID = 3

Expand Down