Browse Source

[FIX] don't restrict all fields to export, only restrict export itself (#1019)

* [FIX] don't restrict all fields to export, only restrict export itself

* [FIX] don't fail tests when new partners are added
pull/1030/head
Holger Brunn 7 years ago
committed by Dave Lasley
parent
commit
9b5c2cb636
  1. 1
      base_mixin_restrict_field_access/__init__.py
  2. 4
      base_mixin_restrict_field_access/controllers/__init__.py
  3. 21
      base_mixin_restrict_field_access/controllers/main.py
  4. 4
      base_mixin_restrict_field_access/tests/test_base_mixin_restrict_field_access.py

1
base_mixin_restrict_field_access/__init__.py

@ -2,4 +2,3 @@
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from . import controllers

4
base_mixin_restrict_field_access/controllers/__init__.py

@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import main

21
base_mixin_restrict_field_access/controllers/main.py

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.http import request
from openerp.addons.web.controllers.main import Export
from ..models.restrict_field_access_mixin import RestrictFieldAccessMixin
class RestrictedExport(Export):
"""Don't (even offer to) export inaccessible fields"""
def fields_get(self, model):
fields = super(RestrictedExport, self).fields_get(model)
model = request.env[model]
if isinstance(model, RestrictFieldAccessMixin):
sanitised_fields = {
k: fields[k] for k in fields
if model._restrict_field_access_is_field_accessible(k)
}
return sanitised_fields
else:
return fields

4
base_mixin_restrict_field_access/tests/test_base_mixin_restrict_field_access.py

@ -95,12 +95,12 @@ class TestBaseMixinRestrictFieldAccess(TransactionCase):
data = partner_model.read_group(
[], [], ['user_id']
)
self.assertEqual(data[0]['credit_limit'], 41)
self.assertEqual(sum(d['credit_limit'] for d in data), 41)
# but users with permissions should see the sum for all records
data = partner_model.sudo().read_group(
[], [], ['user_id']
)
self.assertEqual(
data[0]['credit_limit'],
sum(d['credit_limit'] for d in data),
sum(partner_model.sudo().search([]).mapped('credit_limit'))
)
Loading…
Cancel
Save