[ADD] base_mixin_restrict_field_access - #396
Conversation
|
travis' complaint is a false positive discussed here: OCA/maintainer-quality-tools#307 |
|
You can add a comment for disabling the check on that line: |
|
@pedrobaeza thanks |
|
Almost done: |
|
saw it, thanks. Weird nothing complained about this one before. Anyways |
| Known issues / Roadmap | ||
| ====================== | ||
|
|
||
| * the code contains some TODOs which should be done |
There was a problem hiding this comment.
Better to specify here the big issues: read_group, not so secure call and the rest of possible operations not covered.
|
Little comment, but 👍 |
|
👍 |
|
This doesn't seem to apply to CSV exports? To reproduce please see this code: ` class hr_employee(osv.osv): ` (in the full code I work with two lists FIELDS_ONLY_SELF_OR_MANAGER and FIELDS_ONLY_MANAGER corresponding to the web interface's "Public Information"/"Personal Information"/"HR Settings" tabs) So birthdate should always be inaccessible. And indeed, "Date of birth" on the form shows no value although there is one (even for the admin user). However, CSV export doesn't seem to care, and will always happily contain it. When I click "Export To File" then _restrict_field_access_is_field_accessible() gets called with field_name 'birthday' and action 'read' but I assume that's just a side effect of reading the full record somewhere along the line. I briefly looked at odoo.openerp.fields.convert_to_export() see also related odoo/odoo#12077 |
|
thanks for the pointer, I updated https://github.com/OCA/server-tools/pull/396/files#diff-9797ae3b8487be8a1f1cd8e6faea9ad8R14 accordingly. The solution will be to check field access in https://github.com/OCA/OCB/blob/8.0/openerp/models.py#L859 and drop fields from the list as appropriate. As the project for which I started this got suspended for a while, I won't be working on this any time soon, but I'll be happy to merge your PRs on this branch. As it seems you need this to be air tight, don't forget to also fix |
|
PS: The list of fields to export is compiled in https://github.com/OCA/OCB/blob/8.0/addons/web/controllers/main.py#L1291 if you want to change it |
|
Thanks Holger, I monkeypatched web.ExportFormat.base to drop the fields. get_fields() looks like a cleaner location, and seems to have everything that's needed (model, request's user). Hadn't noticed the read_group() issue until now, thanks for mentioning this. I'm going to Germany for a month after next week so this won't go in production here either anytime soon. :-) |
|
Took me also a while to get back to this. |
|
@guewen @pedrobaeza you've thumbed this up, can we merge if there's a green runbot? |
|
Do you plan to squash a bit the commit history? |
* Add implementation for restricted exporting and grouping * Use original __export_rows() for models not using the mixin * Assume all fields if not specified, like in original read_group() * Return inaccessible fields in read_group() with null values * No need to remove 'restrict_field_access'
e40394a to
ad02c34
Compare
|
I did not, but you're right, that should happen. Done |
Syncing from upstream OCA/server-tools (10.0)
This is the result of #332:
Restrict field access
This module was written to help developers restricting access to fields in a
secure and flexible manner.
If you're not a developer, this module is not for you as you need to write code
in order to actually use it.
Usage
To use this module, you need to:
The example code here will allow only reading a few fields for partners of
which the current user is neither the sales person nor in this partner's sales
team.