-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: data-folder
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
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, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about Literal
type or Enum
?
https://stackoverflow.com/questions/58114837/python-3-type-hint-for-string-options
def __get_user_path( | ||
self, username: str, function_title: str | None, provider_name: str | None | ||
) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}" |
There was a problem hiding this comment.
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
path = f"{provider_name}/{function_title}" | ||
return os.path.join( | ||
sanitize_file_path(settings.MEDIA_ROOT), | ||
sanitize_file_path(path), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
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) |
There was a problem hiding this comment.
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?
Thank you so much @korgan00 , as soon as I return from vacations I will take a look 🙏 |
Summary
This PR is part of an effort to stabilize
files
API end-points in #1509This PR focuses on
files/
andfiles/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/
andusername/provider/function
with the purpose to separated files from functions from the user's root folderfiles/provider/
to manage the pathprovider/function
so now each function will have its own folder in the provider directory.FileStorage
was created to manage the logic of access to this storage for providers and users with the purpose to simplify the view.