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] Missing sudo for technical models. Basic users not able to add attachments #289

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

adrienpeiffer
Copy link
Contributor

Basics users without settings access are not able to upload attachment

@OCA-git-bot
Copy link
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

@@ -163,7 +163,7 @@ def write(self, vals):
@tools.ormcache()
def get_id_by_code_map(self):
"""Return a dictionary with the code as key and the id as value."""
return {rec.code: rec.id for rec in self.search([])}
return {rec.code: rec.id for rec in self.sudo().search([])}
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

@adrienpeiffer It's strange to have a sudo here but not in others methods. We should add tests to be sure that we cover all the cases.

Copy link
Sponsor Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

@adrienpeiffer Thank you for the fix. It would be nice to have unittest for such cases. Can you also add a file named 289.bugfix into the fs_attachment/readme/newsfragment and fs_storage/readme/newsfragment directories and describe the change and why this change. These files are used to maintain a human readable history of changes between versions.

Copy link
Sponsor Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

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

Code and functional review

@@ -340,3 +340,40 @@ def test_storage_use_filename_obfuscation(self):
self.assertEqual(attachment.checksum, attachment.store_fname.split("/")[-1])
self.assertEqual(attachment.checksum, attachment.fs_url.split("/")[-1])
self.assertEqual(attachment.mimetype, "text/plain")

def test_create_attachments_basic_user(self):
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Sponsor Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

Thank you @adrienpeiffer for the fix and the test.

Can you squash the commit into one and rewrite the commit message. Since a lot of addons are managed into the same repo, it's a good habit to start the commit with the name of the impacted modules. Something like:

[FIX] fs_storage, fs_attachement: Missing sudo for technical models

Before this change, users with basic access rights was no more able to create an attachment. The problem was caused by the need to access system information to determine in which file system the attachment should be created, when this sensitive information is not accessible to everyone. The change consists of reading this information in sudo to bypass this security restriction in this specific context.

Before this change, users with basic access rights was no more able to create an attachment. The problem was caused by the need to access system information to determine in which file system the attachment should be created, when this sensitive information is not accessible to everyone. The change consists of reading this information in sudo to bypass this security restriction in this specific context.
@lmignon
Copy link
Sponsor Contributor

lmignon commented Oct 17, 2023

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-289-by-lmignon-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit a387538 into OCA:16.0 Oct 17, 2023
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 0396c9a. Thanks a lot for contributing to OCA. ❤️

@lmignon lmignon deleted the 16.0-fix-sudo-fs-storage-ape branch October 17, 2023 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants