Skip to content

Commit

Permalink
feat: Endpoint to get the files shared with the user (#80)
Browse files Browse the repository at this point in the history
* feat: Endpoint to obtain the list of shares, the tests are not yet implemented

Receives the user's token and returns the list of shared files/folders and the user they were shared with.

* feat: Shared list endpoint

Receives the user's token and returns the list of shared files/folders that have been shared with them

* fix: check-format

* refactor: Added the missing "extension" field

Added the missing "extension" field in addition to changing sharedFile to files

* refactor: init file and file_views

The endpoint is complemented by adding the handler to the init file, in addition to adding the path in the file_views file

* feat: Tests for shared_files endpoint

The endpoint shared files is completed, adding the tests, which exceed 70%

* docs(http): Add new request to bruno collection

---------

Co-authored-by: Andvelavi <[email protected]>
Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2023
1 parent 79773f6 commit 9fe3011
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
15 changes: 15 additions & 0 deletions docs/bruno/files/get-shared-with-me.bru
Original file line number Diff line number Diff line change
@@ -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}}
}
2 changes: 2 additions & 0 deletions src/controllers/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,4 +21,5 @@
"SHARE": share_handler,
"MOVE_FILE": file_move_handler,
"SHARED_WITH_WHO": shared_with_who_handler,
"SHARED_FILES": shared_files_handler,
}
7 changes: 3 additions & 4 deletions src/controllers/files/shared_file/_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
98 changes: 98 additions & 0 deletions src/controllers/files/shared_file/_shared_file_test.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions src/views/_file_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9fe3011

Please sign in to comment.