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

Files list end point refactor #1529

Open
wants to merge 9 commits into
base: data-folder
Choose a base branch
from
Open

Files list end point refactor #1529

wants to merge 9 commits into from

Conversation

Tansito
Copy link
Member

@Tansito Tansito commented Oct 29, 2024

Summary

This PR is part of an effort to stabilize files API end-points in #1509

This PR focuses on files/ and files/provider/ end-points to be able to list the files in the working directories for the user and for the provider.

Details and comments

  • files/ end-point was separated in two:
    • files/ now contains the paths: username/ and username/provider/function with the purpose to separated files from functions from the user's root folder
    • files/provider/ to manage the path provider/function so now each function will have its own folder in the provider directory.
  • A new service FileStorage was created to manage the logic of access to this storage for providers and users with the purpose to simplify the view.

@Tansito Tansito marked this pull request as draft October 29, 2024 15:38
@Tansito Tansito marked this pull request as ready for review October 29, 2024 15:50
@Tansito Tansito requested a review from a team October 29, 2024 15:50
@Tansito Tansito changed the title List end point refactor Files list end point refactor Oct 29, 2024
Copy link
Collaborator

@korgan00 korgan00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, just minor comments

Comment on lines +159 to +178
if provider_name:
function = self.get_provider_function(
provider_name=provider_name, function_title=function_title
)
if not function:
return Response(
{
"message": f"Qiskit Function {provider_name}/{function_title} doesn't exist." # pylint: disable=line-too-long
},
status=status.HTTP_404_NOT_FOUND,
)

if function:
if not self.user_has_access_to_provider_function(
request.user, function
):
return Response(
{"message": "You don't have access to this Qiskit Function."},
status=status.HTTP_403_FORBIDDEN,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if provider_name:
function = self.get_provider_function(
provider_name=provider_name, function_title=function_title
)
if not function:
return Response(
{
"message": f"Qiskit Function {provider_name}/{function_title} doesn't exist." # pylint: disable=line-too-long
},
status=status.HTTP_404_NOT_FOUND,
)
if function:
if not self.user_has_access_to_provider_function(
request.user, function
):
return Response(
{"message": "You don't have access to this Qiskit Function."},
status=status.HTTP_403_FORBIDDEN,
)
if provider_name:
function = self.get_provider_function(
provider_name=provider_name, function_title=function_title
)
if not function:
return Response(
{
"message": f"Qiskit Function {provider_name}/{function_title} doesn't exist." # pylint: disable=line-too-long
},
status=status.HTTP_404_NOT_FOUND,
)
if not self.user_has_access_to_provider_function(
request.user, function
):
return Response(
{"message": "You don't have access to this Qiskit Function."},
status=status.HTTP_403_FORBIDDEN,
)

Since the function is only set inside if provider_name: I think it doesn't make sense to check the function out of the if.

def __init__(
self,
username: str,
working_dir: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +46 to +48
def __get_user_path(
self, username: str, function_title: str | None, provider_name: str | None
) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __get_user_path(
self, username: str, function_title: str | None, provider_name: str | None
) -> str:
def __get_user_path(
self, function_title: str | None, provider_name: str | None
) -> str:

self contains username, it can be omitted.

Comment on lines +66 to +73
if provider_name is None:
path = username
else:
path = f"{username}/{provider_name}/{function_title}"
return os.path.join(
sanitize_file_path(settings.MEDIA_ROOT),
sanitize_file_path(path),
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if provider_name is None:
path = username
else:
path = f"{username}/{provider_name}/{function_title}"
return os.path.join(
sanitize_file_path(settings.MEDIA_ROOT),
sanitize_file_path(path),
)
path = os.path.join(settings.MEDIA_ROOT, username)
if provider_name:
path = os.path.join(path, provider_name, function_title)
return sanitize_file_path(path)

How about join everyone with the path.join and sanitize at the end.

if provider_name is None:
path = username
else:
path = f"{username}/{provider_name}/{function_title}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not checking if function_title is none

Comment on lines +88 to +92
path = f"{provider_name}/{function_title}"
return os.path.join(
sanitize_file_path(settings.MEDIA_ROOT),
sanitize_file_path(path),
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path = f"{provider_name}/{function_title}"
return os.path.join(
sanitize_file_path(settings.MEDIA_ROOT),
sanitize_file_path(path),
)
path = os.path.join(
settings.MEDIA_ROOT, provider_name, function_title
)
return sanitize_file_path(path)

Comment on lines +39 to +44
if working_dir == USER_STORAGE:
self.file_path = self.__get_user_path(
username, function_title, provider_name
)
elif working_dir == PROVIDER_STORAGE:
self.file_path = self.__get_provider_path(function_title, provider_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if working dir is not user or provider?

@Tansito
Copy link
Member Author

Tansito commented Nov 7, 2024

Thank you so much @korgan00 , as soon as I return from vacations I will take a look 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants