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

Use as course-field: Access to files is forbidden #4

Open
bytesparrow opened this issue Oct 26, 2022 · 8 comments
Open

Use as course-field: Access to files is forbidden #4

bytesparrow opened this issue Oct 26, 2022 · 8 comments

Comments

@bytesparrow
Copy link

bytesparrow commented Oct 26, 2022

Hi,
thank you for the plugin. But there is a problem regarding the context:
If you add a coursefield of type "File", any file uploaded will give a "404".

How I tested:

  • download Moodle 4.0.4
  • extract this module to moodle-root/customfield/field/file
  • install moodle
  • on /course/customfield.php add a field "testfile"
  • create a new course "testcourse"
  • upload a file "myfile.jpg" in field "testfile"
  • goto /?redirect=0
  • see the course "testcourse" with the field "testfile" and the entry "myfile.jpg"
  • click on "myfile.jpg"
  • you are on the url /pluginfile.php/1/customfield_file/value/1/myfile.jpg and see "404"

This is because in function customfield_file_pluginfile / line 56 a send_file_not_found(); is returned

And this is because the contexts don't match - if you add
die("Context: ".$data->get_context()->id . " VS " .$context->id);
before
send_file_not_found(); in customfield_file_pluginfile/56
it will output
Context: 14 VS 1
on a new installation.

You can see in the database that they really don't match:

SELECT contextid, component, filename FROM files WHERE id = 33;
contextid | component | filename |  
1 | customfield_file | myfile.jpg

VS

SELECT fieldid, instanceid, timemodified,contextid FROM customfield_data;
fieldid | instanceid | timemodified | contextid |  
1 | 2 | 1666780996 | 14

Or did I do something wrong?
I'm on Ubuntu 22.04.1 LTS / PHP 7.4.32

Thanks for your efforts!

@andrewhancox
Copy link
Owner

andrewhancox commented Oct 31, 2022 via email

@bytesparrow
Copy link
Author

bytesparrow commented Nov 2, 2022

Thanks a lot for your input.
I'll have a try.. May I ask, for which kind of objects do you use this plugin?

@andrewhancox
Copy link
Owner

andrewhancox commented Nov 2, 2022 via email

@bytesparrow
Copy link
Author

I understand. I'll get the fix done (and maybe some other features if you agree) and commit the changes

@andrewhancox
Copy link
Owner

andrewhancox commented Nov 4, 2022 via email

@bytesparrow
Copy link
Author

bytesparrow commented Apr 18, 2024

Hi,
I apologize for the delay, as the project was unexpectedly postponed. Now we're on track again.

As frumbert found out too, this is the solution to the 403-problem:
grafik

Are you ok with this solution?

@bytesparrow bytesparrow reopened this Apr 18, 2024
bytesparrow added a commit to bytesparrow/moodle-customfield_file that referenced this issue Apr 24, 2024
@dmitriim
Copy link

Looks like #10 is a duplicate of this one.

TomoTsuyuki added a commit to TomoTsuyuki/moodle-customfield_file that referenced this issue Dec 12, 2024
TomoTsuyuki added a commit to TomoTsuyuki/moodle-customfield_file that referenced this issue Dec 12, 2024
@TomoTsuyuki
Copy link

Hi @andrewhancox / @bytesparrow

I made PR #11 using the code from @bytesparrow above.
I added an upgrade script to update existing records in the PR.

Can you review and merge the PR if it's ok?

Thanks

TomoTsuyuki added a commit to TomoTsuyuki/moodle-customfield_file that referenced this issue Dec 16, 2024
TomoTsuyuki added a commit to TomoTsuyuki/moodle-customfield_file that referenced this issue Dec 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

No branches or pull requests

4 participants