diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc3179..1c60af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# [0.14.0](https://github.com/hawks-atlanta/proxy-python/compare/v0.13.0...v0.14.0) (2023-10-24) + + +### Features + +* Endpoint to get the files shared with the user ([#80](https://github.com/hawks-atlanta/proxy-python/issues/80)) ([9fe3011](https://github.com/hawks-atlanta/proxy-python/commit/9fe3011c447ccc482ff1c67aec56bdd95ff5e30c)) + + + # [0.13.0](https://github.com/hawks-atlanta/proxy-python/compare/v0.12.1...v0.13.0) (2023-10-20) @@ -34,12 +43,3 @@ -# [0.10.0](https://github.com/hawks-atlanta/proxy-python/compare/v0.9.0...v0.10.0) (2023-10-15) - - -### Features - -* list user files ([#64](https://github.com/hawks-atlanta/proxy-python/issues/64)) ([6daf51f](https://github.com/hawks-atlanta/proxy-python/commit/6daf51f7860e49bdd5d48c2878a525e14bb08c9a)) - - - diff --git a/docs/bruno/files/get-shared-with-me.bru b/docs/bruno/files/get-shared-with-me.bru new file mode 100644 index 0000000..fcb1dfa --- /dev/null +++ b/docs/bruno/files/get-shared-with-me.bru @@ -0,0 +1,15 @@ +meta { + name: get-shared-with-me + type: http + seq: 15 +} + +get { + url: {{API_BASE_URL}}/file/shared + body: none + auth: bearer +} + +auth:bearer { + token: {{AUTH_TOKEN}} +} diff --git a/src/controllers/files/__init__.py b/src/controllers/files/__init__.py index 266ca98..141dd5a 100644 --- a/src/controllers/files/__init__.py +++ b/src/controllers/files/__init__.py @@ -8,6 +8,7 @@ from .share_file._handler import share_handler from .move_a_file._handler import file_move_handler from .shared_with_who._handler import shared_with_who_handler +from .shared_file._handler import shared_files_handler FILES_HANDLERS = { "CHECK_STATE": check_state_handler, @@ -20,4 +21,5 @@ "SHARE": share_handler, "MOVE_FILE": file_move_handler, "SHARED_WITH_WHO": shared_with_who_handler, + "SHARED_FILES": shared_files_handler, } diff --git a/src/controllers/files/shared_file/_handler.py b/src/controllers/files/shared_file/_handler.py index c22716f..9db67e3 100644 --- a/src/controllers/files/shared_file/_handler.py +++ b/src/controllers/files/shared_file/_handler.py @@ -11,14 +11,13 @@ def shared_files_handler(token): files = [ { + "extension": file.extension, "name": file.name, - "size": file.size, "isFile": file.isFile, - "extension": file.extension, "uuid": file.uuid, - "ownerusername": file.ownerusername, + "size": file.size, } - for file in response.files + for file in response.sharedFiles ] return { diff --git a/src/controllers/files/shared_file/_shared_file_test.py b/src/controllers/files/shared_file/_shared_file_test.py new file mode 100644 index 0000000..906b10f --- /dev/null +++ b/src/controllers/files/shared_file/_shared_file_test.py @@ -0,0 +1,98 @@ +from random import randbytes +from main import app +from src.config.soap_client import soap_client +from src.lib.faker import fake_username, fake_password + +# SHARED WITH FILE TESTS +shared_files_data = { + "username": fake_username(), + "password": fake_password(), + "otherUsername": fake_username(), + "file": { + "uuid": None, + "name": "picture.jpeg", + "content": randbytes(1024), + }, +} + + +def test_shared_bad_request(): + # Register an user + register_response = soap_client.service.account_register( + { + "username": shared_files_data["username"], + "password": shared_files_data["password"], + } + ) + assert register_response.error is False + + # Login with the user + login_response = soap_client.service.auth_login( + { + "username": shared_files_data["username"], + "password": shared_files_data["password"], + } + ) + assert login_response.error is False + + # NO TOKEN + response = app.test_client().get("/file/shared") + assert response.status_code == 401 + + +def test_shared_success_request(): + # Register the second user + register_response2 = soap_client.service.account_register( + { + "username": shared_files_data["otherUsername"], + "password": shared_files_data["password"], + } + ) + assert register_response2.error is False + + # Login with the user + login_response = soap_client.service.auth_login( + { + "username": shared_files_data["username"], + "password": shared_files_data["password"], + } + ) + assert login_response.error is False + token = login_response.auth.token + + # Upload a file as the first user + upload_response = soap_client.service.file_upload( + { + "token": token, + "fileName": shared_files_data["file"]["name"], + "fileContent": shared_files_data["file"]["content"], + "location": None, + } + ) + assert upload_response.error is False + shared_files_data["file"]["uuid"] = upload_response.fileUUID + + # share a file + create_share_response = soap_client.service.share_file( + { + "fileUUID": shared_files_data["file"]["uuid"], + "otherUsername": shared_files_data["otherUsername"], + "token": token, + } + ) + assert create_share_response.error is False + + login_response2 = soap_client.service.auth_login( + { + "username": shared_files_data["otherUsername"], + "password": shared_files_data["password"], + } + ) + assert login_response2.error is False + token2 = login_response2.auth.token + + # list users + file_response = app.test_client().get( + "/file/shared", headers={"Authorization": f"Bearer {token2}"} + ) + assert file_response.status_code == 200 diff --git a/src/views/_file_views.py b/src/views/_file_views.py index 6c44a7c..552ceb2 100644 --- a/src/views/_file_views.py +++ b/src/views/_file_views.py @@ -64,3 +64,9 @@ def move_file(token, file_uuid): @auth_middlewares.token_required def shared_with_who(token, file_uuid): return FILES_HANDLERS["SHARED_WITH_WHO"](token, file_uuid) + + +@views.route("/file/shared", methods=["GET"]) +@auth_middlewares.token_required +def shared_files(token): + return FILES_HANDLERS["SHARED_FILES"](token) diff --git a/version.json b/version.json index 3c6f435..b15e340 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "0.13.0" + "version": "0.14.0" } \ No newline at end of file