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

Rewrite the WeBWorK::Upload module. #2693

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Apr 3, 2025

This takes advantage of things available with Mojolicious.

This does not use Data::UUID anymore. A comment stated that it was overkill. It is and it was never a good idea to use that for this purpose. This just uses the Mojo::Asset::Memory::to_file method which converts to a Mojo::Asset::File object and saves the file to a temporary file using Mojo::File::tempfile (which uses File::Temp under the hood). That is guaranteed to give a safe filename that does not conflict with any existing files. Setting the environment variable MOJO_TMPDIR locally to be the passed in directory (which is $ce->{webworkDirs}{uploadCache}) ensures that the file is saved in the usual webwork2 upload location (although there is no need for that, and we could drop that configuration variable and just use the system temporary directory for this).

The info file that is written is now UTF-8 encoded and decoded. This fixes issue #2690.

The dir option which was previously required and the only "option" is now just a required argument. It doesn't make sense to use an "option" hash things that are required. Particularly if there is only one option and it is required.

Other than what is mentioned above the module behaves much the same.

@pstaabp pstaabp linked an issue Apr 8, 2025 that may be closed by this pull request
=over
An upload stored in the upload cache can be retrieved by supplying its temporary
file name and hash (accessible from the above C<tmpFile> and C<hash> methods,
respectively. The file can then be accessed by name or file handle, moved, and
Copy link
Member

Choose a reason for hiding this comment

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

minor thing: close the ) after 'respectively' ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. That is fixed.

@pstaabp
Copy link
Member

pstaabp commented Apr 8, 2025

Thinking about testing this. There's clearly the email that came from the issue, but does this get called for a file upload to through the File Manager? I notice the code in FileManager.pm, but unclear if that is enough to test.

@drgrice1
Copy link
Member Author

drgrice1 commented Apr 8, 2025

There are currently two places this is used, and you mentioned both of them.

@pstaabp
Copy link
Member

pstaabp commented Apr 8, 2025

We should also remove Data::UUID from check_modules.pl.

Copy link
Member

@pstaabp pstaabp left a comment

Choose a reason for hiding this comment

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

Tested with uploading to the File Manager. Didn't test with emails.

@drgrice1
Copy link
Member Author

drgrice1 commented Apr 8, 2025

I believe that the Data::UUID is still used elsewhere though.

This takes advantage of things available with Mojolicious.

This does not use `Data::UUID` anymore.  A comment stated that it was
overkill.  It is and it was never a good idea to use that for this
purpose.  This just uses the `Mojo::Asset::Memory::to_file` method which
converts to a `Mojo::Asset::File` object and saves the file to a
temporary file using `Mojo::File::tempfile` (which uses `File::Temp`
under the hood).  That is guaranteed to give a safe filename that does
not conflict with any existing files.  Setting the environment variable
`MOJO_TMPDIR` locally to be the passed in directory (which is
`$ce->{webworkDirs}{uploadCache}`) ensures that the file is saved in the
usual webwork2 upload location (although there is no need for that, and
we could drop that configuration variable and just use the system
temporary directory for this).

The info file that is written is now UTF-8 encoded and decoded.  This
fixes issue openwebwork#2690.

The `dir` option which was previously required and the only "option" is
now just a required argument.  It doesn't make sense to use an "option"
hash things that are required.  Particularly if there is only one option
and it is required.

Other than what is mentioned above the module behaves much the same.
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.

unusual characters in an uploaded file
2 participants