From 9b5c2cb636f97d3a8e09f195c70cf666fd3e6df9 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 17 Oct 2017 23:07:12 +0200 Subject: [PATCH] [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 --- base_mixin_restrict_field_access/__init__.py | 1 - .../controllers/__init__.py | 4 ---- .../controllers/main.py | 21 ------------------- .../test_base_mixin_restrict_field_access.py | 4 ++-- 4 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 base_mixin_restrict_field_access/controllers/__init__.py delete mode 100644 base_mixin_restrict_field_access/controllers/main.py diff --git a/base_mixin_restrict_field_access/__init__.py b/base_mixin_restrict_field_access/__init__.py index 0188fced6..7eda98a23 100644 --- a/base_mixin_restrict_field_access/__init__.py +++ b/base_mixin_restrict_field_access/__init__.py @@ -2,4 +2,3 @@ # © 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models -from . import controllers diff --git a/base_mixin_restrict_field_access/controllers/__init__.py b/base_mixin_restrict_field_access/controllers/__init__.py deleted file mode 100644 index 1b21ddd33..000000000 --- a/base_mixin_restrict_field_access/controllers/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Therp BV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import main diff --git a/base_mixin_restrict_field_access/controllers/main.py b/base_mixin_restrict_field_access/controllers/main.py deleted file mode 100644 index f2632e1bf..000000000 --- a/base_mixin_restrict_field_access/controllers/main.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Therp BV -# 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 diff --git a/base_mixin_restrict_field_access/tests/test_base_mixin_restrict_field_access.py b/base_mixin_restrict_field_access/tests/test_base_mixin_restrict_field_access.py index abef5b343..6d7d181d4 100644 --- a/base_mixin_restrict_field_access/tests/test_base_mixin_restrict_field_access.py +++ b/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')) )