Skip to content

Commit

Permalink
release: v0.14.0 (#81)
Browse files Browse the repository at this point in the history
* feat: Endpoint to get the files shared with the user (#80)

* feat: Shared list endpoint

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

* 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 bcf8e3c commit c55cb24
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 14 deletions.
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -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))



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)
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.13.0"
"version": "0.14.0"
}

0 comments on commit c55cb24

Please sign in to comment.