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

Fix get auth number two #10614

Merged
merged 8 commits into from
May 13, 2024

Conversation

jwalz
Copy link
Collaborator

@jwalz jwalz commented May 13, 2024

Purpose

get_auth was checking for FileVersions on all osfstorage entities -- including folders. This was breaking access to osfstorage on projects. Fix that.

Changes

  • Rename get_file_node_from_wb and get_file_version_from_wb to _get_osfstorage_file_node and _get_osfstorage_file_version and only provide them the information they need from waterbutler_data.
  • Grab the OsfStorageFileNode before grabbing the version
  • Pass the OsfStorageFileNode to `get_osfstorage_file_version'. Short circuit when trying to retrieve a FileVersion for a non-"file" OsfStorageFileNode

QA Notes

Please make verification statements inspired by your code and what your code touches.

  • Verify
  • Verify

What are the areas of risk?

Any concerns/considerations/questions that development raised?

Documentation

Side Effects

Ticket

version = int(version_string) if version_string else file_node.versions.count()
try:
return FileVersion.objects.select_related('region').get(
basefilenode=file_node,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Historically, this was grabbed by basefilenode___id=file_id even though the filenode had already been loaded. I'm hoping that this was just an oversight:

basefilenode___id=file_id,

Copy link
Member

Choose a reason for hiding this comment

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

Likely oversight. It should be slightly more efficient to use foreign relations like this, rather than a JOIN querying on a text field.

Comment on lines 326 to 327
except OsfStorageFileNode.DoesNotExist:
raise HTTPError(http_status.HTTP_400_BAD_REQUEST, 'Requested File unavailable')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

load will return None, not Raise...should we be checking for that?

Suggested change
except OsfStorageFileNode.DoesNotExist:
raise HTTPError(http_status.HTTP_400_BAD_REQUEST, 'Requested File unavailable')

Co-authored-by: Jon Walz <jon@cos.io>
try:
return FileVersion.objects.select_related('region').get(
basefilenode=file_node,
identifier=version
Copy link
Member

Choose a reason for hiding this comment

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

Minor: identifier is a CharField, and this is being cast to an int above. It should get cast back to str somewhere in query planning or execution, though, so likely not a concern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually much nicer to cast an int to a string than a str | None to an int.

@jwalz jwalz merged commit 8483e57 into CenterForOpenScience:develop May 13, 2024
6 checks passed
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
Johnetordoff pushed a commit to Johnetordoff/osf.io that referenced this pull request May 16, 2024
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.

None yet

3 participants