Skip to content

Commit

Permalink
feat: Added proper scopes to media routes (#118)
Browse files Browse the repository at this point in the history
* feat: Updated media scopes

* refactor: Renamed route function

* test: Reindented properly table

* style: Fixed lint
  • Loading branch information
frgfm authored Mar 18, 2021
1 parent 301965c commit 3587cdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
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

0 comments on commit 3587cdf

Please sign in to comment.