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

release: v0.12.0 #73

Merged
merged 56 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4bd13c4
[ci skip] chore(release): 0.0.4
shoriwe Aug 24, 2023
fca70d6
docs: OpenApi Specification (#9)
MiguelMRojas Sep 2, 2023
409ad31
chore: Update docker-compose (#12)
PedroChaparro Oct 1, 2023
22a84d2
ci: Linter and formatter (#14)
PedroChaparro Oct 3, 2023
4921ca1
feat: endpoint login (#15)
MiguelMRojas Oct 4, 2023
e0e1ea1
[ci skip] chore(release): 0.0.5
shoriwe Oct 4, 2023
ee78fb6
feat: endpoint challenge (#33)
MiguelMRojas Oct 8, 2023
8053b99
[ci skip] chore(release): 0.0.6
shoriwe Oct 8, 2023
556edf9
refactor: Update endpoints (#37)
PedroChaparro Oct 9, 2023
77e1bf2
[ci skip] chore(release): 0.0.7
shoriwe Oct 9, 2023
3e85e7e
Merge branch 'main' into dev
PedroChaparro Oct 9, 2023
d9b0805
[ci skip] chore(release): 0.0.8
shoriwe Oct 9, 2023
3ba394f
fix: Enable CORS (#40)
MiguelMRojas Oct 9, 2023
38392d4
feat: Register endpoint (#39)
AndreaVelasquezA Oct 9, 2023
d8d3871
[ci skip] chore(release): 0.0.9
shoriwe Oct 9, 2023
c4bbd73
Merge branch 'main' into dev
MiguelMRojas Oct 10, 2023
9f8ad6a
fix: Enable all CORS origins (#44)
PedroChaparro Oct 11, 2023
5292585
[ci skip] chore(release): 0.0.10
shoriwe Oct 11, 2023
221c004
Merge branch 'main' into dev
PedroChaparro Oct 11, 2023
b268821
[ci skip] chore(release): 0.0.11
shoriwe Oct 11, 2023
7da7a7c
ci: Fix tagging pipeline (#48)
PedroChaparro Oct 12, 2023
a32f442
ci: Fix typo
PedroChaparro Oct 12, 2023
9dc6959
feat: update docs openapi (#41)
MiguelMRojas Oct 12, 2023
ba8ff15
[ci skip] chore(release): v0.1.0 [skip ci]
shoriwe Oct 12, 2023
af95070
feat: Endpoint to get the file status (#49)
PedroChaparro Oct 12, 2023
7345e45
[ci skip] chore(release): v0.4.0 [skip ci]
shoriwe Oct 12, 2023
b1e93fc
feat: Endpoint to rename a file (#50)
MiguelMRojas Oct 13, 2023
724cc9e
[ci skip] chore(release): v0.5.0 [skip ci]
shoriwe Oct 13, 2023
395b44b
feat: Update password (#51)
AndreaVelasquezA Oct 13, 2023
38a395e
[ci skip] chore(release): v0.6.0 [skip ci]
shoriwe Oct 13, 2023
7aca7f2
feat: create a folder (#52)
MiguelMRojas Oct 14, 2023
3c408a9
[ci skip] chore(release): v0.7.0 [skip ci]
shoriwe Oct 14, 2023
097d026
feat: file upload (#53)
AndreaVelasquezA Oct 14, 2023
f335708
[ci skip] chore(release): v0.8.0 [skip ci]
shoriwe Oct 14, 2023
624cc06
fix(files): Keep files extension (#56)
PedroChaparro Oct 14, 2023
0c7acae
[ci skip] chore(release): v0.8.1 [skip ci]
shoriwe Oct 14, 2023
4de7711
test: Increment save file endpoint coverage (#54)
PedroChaparro Oct 14, 2023
d397a24
Merge branch 'main' into dev
PedroChaparro Oct 14, 2023
c30a733
test(files): Fix broken tests related to file upload (#58)
PedroChaparro Oct 14, 2023
371075b
Merge branch 'main' into dev
PedroChaparro Oct 14, 2023
7c41c70
fix: Add extra validations for UUIDs (#65)
PedroChaparro Oct 15, 2023
4b26239
[ci skip] chore(release): v0.8.2 [skip ci]
shoriwe Oct 15, 2023
a6f7074
feat: share a file with another user (#61)
AndreaVelasquezA Oct 15, 2023
9bf0cdb
feat: download file (#60)
AndreaVelasquezA Oct 15, 2023
1e09c26
[ci skip] chore(release): v0.9.0 [skip ci]
shoriwe Oct 15, 2023
6daf51f
feat: list user files (#64)
MiguelMRojas Oct 15, 2023
62fa02d
[ci skip] chore(release): v0.10.0 [skip ci]
shoriwe Oct 15, 2023
b292621
feat: Get file by UUID (#66)
PedroChaparro Oct 15, 2023
d999d86
[ci skip] chore(release): v0.11.0 [skip ci]
shoriwe Oct 15, 2023
b0a585c
feat: move a file (#68)
MiguelMRojas Oct 16, 2023
079d755
refactor: Create delete file controller (#69)
AndreaVelasquezA Oct 18, 2023
eb70124
refactor: Unshare file (#70)
AndreaVelasquezA Oct 18, 2023
a30478b
refactor: Shared files (#71)
AndreaVelasquezA Oct 19, 2023
9373052
refactor: Get the users with whom a file is being shared (#72)
AndreaVelasquezA Oct 19, 2023
3a285ce
[ci skip] chore(release): v0.12.0 [skip ci]
shoriwe Oct 20, 2023
1ebf944
Merge branch 'main' into dev
PedroChaparro Oct 20, 2023
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
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [0.12.0](https://github.com/hawks-atlanta/proxy-python/compare/v0.11.0...v0.12.0) (2023-10-20)


### Features

* move a file ([#68](https://github.com/hawks-atlanta/proxy-python/issues/68)) ([b0a585c](https://github.com/hawks-atlanta/proxy-python/commit/b0a585c89c8ae09a49fa0549858d73f51ea6976a))



# [0.11.0](https://github.com/hawks-atlanta/proxy-python/compare/v0.10.0...v0.11.0) (2023-10-15)


Expand Down Expand Up @@ -35,12 +44,3 @@



## [0.8.1](https://github.com/hawks-atlanta/proxy-python/compare/v0.8.0...v0.8.1) (2023-10-14)


### Bug Fixes

* **files:** Keep files extension ([#56](https://github.com/hawks-atlanta/proxy-python/issues/56)) ([624cc06](https://github.com/hawks-atlanta/proxy-python/commit/624cc06af6443602bc9b946c8fc7ee5376dbea2c))



2 changes: 1 addition & 1 deletion docs/spec.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ paths:
schema:
$ref: "#/components/schemas/statusResponse"

/file/shared-with-who:
/file/{fileUUID}/shared-with-who:
get:
tags:
- Files
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .list_files._handler import list_files_handler
from .download_file._handler import download_file_handler
from .share_file._handler import share_handler
from .move_a_file._handler import file_move_handler

FILES_HANDLERS = {
"CHECK_STATE": check_state_handler,
Expand All @@ -16,4 +17,5 @@
"FILE_LIST": list_files_handler,
"DOWNLOAD_FILE": download_file_handler,
"SHARE": share_handler,
"MOVE_FILE": file_move_handler,
}
36 changes: 36 additions & 0 deletions src/controllers/files/move_a_file/_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
from flask import request
from src.config.soap_client import soap_client
from src.lib.helpers import is_valid_uuid


def file_move_handler(token, file_uuid):
try:
data = json.loads(request.data)
target_directory_uuid = data.get("targetDirectoryUUID")

not_valid_target_directory = not target_directory_uuid or not is_valid_uuid(
target_directory_uuid
)
if not_valid_target_directory:
return {"msg": "The target directory is not valid or was not provided"}, 400

request_data = {
"token": token,
"fileUUID": file_uuid,
"targetDirectoryUUID": target_directory_uuid,
}

response = soap_client.service.file_move(request_data)

if response["error"] is True:
return {"msg": response["msg"]}, response["code"]
else:
return {"msg": "The file has been moved"}, 200

except ValueError:
return {"msg": "Not valid JSON data provided in the request"}, 400

except Exception as e:
print("[Exception] file_move_handler ->", e)
return {"msg": "There was an error moving the file"}, 500
133 changes: 133 additions & 0 deletions src/controllers/files/move_a_file/_move_file_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import json
from random import randbytes
from uuid import uuid4

from main import app
from src.config.soap_client import soap_client
from src.lib.faker import fake_username, fake_password

# MOVE FILE TESTS
move_file_test_data = {
"username": fake_username(),
"password": fake_password(),
"file": {
"uuid": None,
"targetDirectoryUUID": None,
"name": "test.txt",
"content": randbytes(1024),
},
}


def test_move_file_success():
# Register a user
register_response = soap_client.service.account_register(
{
"username": move_file_test_data["username"],
"password": move_file_test_data["password"],
}
)
assert register_response.error is False

# Login with the user
login_response = soap_client.service.auth_login(
{
"username": move_file_test_data["username"],
"password": move_file_test_data["password"],
}
)
assert login_response.error is False
token = login_response.auth.token

# Create a new directory
new_directory_name = "test_directory"
create_dir_response = soap_client.service.file_new_dir(
{
"directoryName": new_directory_name,
"location": None,
"token": token,
}
)
assert create_dir_response["code"] == 201
directory_uuid = create_dir_response["fileUUID"]
move_file_test_data["file"]["targetDirectoryUUID"] = directory_uuid

# Upload a file
create_file_response = soap_client.service.file_upload(
{
"token": token,
"fileName": move_file_test_data["file"]["name"],
"fileContent": move_file_test_data["file"]["content"],
"location": None,
}
)
assert create_file_response.error is False
move_file_test_data["file"]["uuid"] = create_file_response.fileUUID

# Move the file to the target directory
response = app.test_client().patch(
f"/file/{move_file_test_data['file']['uuid']}/move",
json={"targetDirectoryUUID": directory_uuid},
headers={"Authorization": f"Bearer {token}"},
)

json_response = json.loads(response.data)
assert response.status_code == 200
assert json_response["msg"].startswith("The file has been moved")


def test_move_file_bad_request():
# Login with the user
login_response = soap_client.service.auth_login(
{
"username": move_file_test_data["username"],
"password": move_file_test_data["password"],
}
)
assert login_response.error is False
token = login_response.auth.token

# Missing JSON data
response = app.test_client().patch(
f"/file/{move_file_test_data['file']['uuid']}/move",
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 400

# Not valid target directory UUID
response = app.test_client().patch(
f"/file/{move_file_test_data['file']['uuid']}/move",
json={"targetDirectoryUUID": "not_valid_uuid"},
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 400

# Non existent file UUID
response = app.test_client().patch(
f"/file/{uuid4()}/move",
json={"targetDirectoryUUID": uuid4()},
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 404


def test_move_file_conflict():
# Login with the user
login_response = soap_client.service.auth_login(
{
"username": move_file_test_data["username"],
"password": move_file_test_data["password"],
}
)
assert login_response.error is False
token = login_response.auth.token

# Try to move the file to the same directory
response = app.test_client().patch(
f"/file/{move_file_test_data['file']['uuid']}/move",
json={
"targetDirectoryUUID": move_file_test_data["file"]["targetDirectoryUUID"]
},
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 409
16 changes: 16 additions & 0 deletions src/controllers/files/remove_file/_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from src.config.soap_client import soap_client


def remove_file_handler(token, file_uuid):
try:
request_data = {"fileUUID": file_uuid, "token": token}
response = soap_client.service.file_delete(request_data)

if response["error"] is True:
return {"msg": response["msg"]}, response["code"]
else:
return {"msg": "File successfully deleted"}, 200

except Exception as e:
print("[Exception] remove_file_handler ->", e)
return {"msg": "There was an error deleting the file"}, 500
Empty file.
30 changes: 30 additions & 0 deletions src/controllers/files/shared_file/_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from src.config.soap_client import soap_client


def shared_files_handler(token):
try:
request_data = {"token": token}
response = soap_client.service.share_list(request_data)

if response["error"] is True:
return {"msg": response["msg"]}, response["code"]

files = [
{
"name": file.name,
"size": file.size,
"isFile": file.isFile,
"extension": file.extension,
"uuid": file.uuid,
"ownerusername": file.ownerusername,
}
for file in response.files
]

return {
"files": files,
"msg": "List of shared files obtained",
}, 200
except Exception as e:
print("[Exception] shared_files_handler ->", e)
return {"msg": "There was an error listing the shared files"}, 500
29 changes: 29 additions & 0 deletions src/controllers/files/shared_with_who/_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from src.config.soap_client import soap_client
from src.lib.helpers import is_valid_uuid


def shared_with_who_handler(token, file_uuid):
try:
if not is_valid_uuid(file_uuid):
return {"msg": "Not valid file UUID provided"}, 400

request_data = {"fileUUID": file_uuid, "token": token}
response = soap_client.service.share_list_with_who(request_data)

if response.usernames is None:
return {"msg": response["msg"]}, response["code"]

usernames = [
{
"users": usernames,
}
for usernames in response.usernames
]

return {
"users": usernames,
"msg": "List of users the file is shared with",
}, 200
except Exception as e:
print("[Exception] shared_with_who_handler ->", e)
return {"msg": "There was an error listing the shared with"}, 500
39 changes: 39 additions & 0 deletions src/controllers/files/unshare_file/_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
from flask import request
from src.config.soap_client import soap_client
from src.lib.helpers import is_valid_uuid


def unshare_handler(token):
try:
data = json.loads(request.data)
fileUUID = data["fileUUID"]
otherUsername = data["otherUsername"]

# Check if required fields are empty
empty_file_uuid = not fileUUID or len(fileUUID) == 0
empty_other_username = not otherUsername or len(otherUsername) == 0
if empty_file_uuid or empty_other_username:
return {"msg": "Required fields are missing in form data"}, 400

# Check if file UUID is valid
if not is_valid_uuid(fileUUID):
return {"msg": "Not valid file UUID provided"}, 400

request_data = {
"fileUUID": fileUUID,
"otherUsername": otherUsername,
"token": token,
}
response = soap_client.service.unshare_file(request_data)

if response["error"] is True:
return {"msg": response["msg"]}, response["code"]
else:
return {"msg": "File unshared successfully"}, 200

except ValueError:
return {"msg": "Invalid JSON data provided in the request"}, 400

except Exception:
return {"msg": "There was an error unsharing the file"}, 500
Empty file.
6 changes: 6 additions & 0 deletions src/views/_file_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ def file_download(token, file_uuid):
@auth_middlewares.token_required
def file_share(token):
return FILES_HANDLERS["SHARE"](token)


@views.route("/file/<string:file_uuid>/move", methods=["PATCH"])
@auth_middlewares.token_required
def move_file(token, file_uuid):
return FILES_HANDLERS["MOVE_FILE"](token, file_uuid)
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.11.0"
"version": "0.12.0"
}