Divyesh Makwana(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/trunk-ir_ui_view_access_rights-mdi into lp:~openerp-dev/openobject-server/trunk-editable_list.
Requested reviews: OpenERP R&D Team (openerp-dev) For more details, see: https://code.launchpad.net/~openerp-dev/openobject-server/trunk-ir_ui_view_access_rights-mdi/+merge/121858 Hello Sir, I have Filter the view on the user's groups and the access rights on objects linked to the view. Thanks, Divyesh -- https://code.launchpad.net/~openerp-dev/openobject-server/trunk-ir_ui_view_access_rights-mdi/+merge/121858 Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openobject-server/trunk-ir_ui_view_access_rights-mdi into lp:~openerp-dev/openobject-server/trunk-editable_list.
=== modified file 'openerp/addons/base/ir/ir_ui_view.py' --- openerp/addons/base/ir/ir_ui_view.py 2012-08-29 12:35:39 +0000 +++ openerp/addons/base/ir/ir_ui_view.py 2012-08-29 13:06:17 +0000 @@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## +import threading from osv import fields,osv from lxml import etree @@ -49,6 +50,68 @@ class view(osv.osv): _name = 'ir.ui.view' + def __init__(self, *args, **kwargs): + self.cache_lock = threading.RLock() + self.clear_cache() + r = super(view, self).__init__(*args, **kwargs) + aaa = self.pool.get('ir.model.access').register_cache_clearing_method(self._name, 'clear_cache') + return r + + def clear_cache(self): + with self.cache_lock: + # radical but this doesn't frequently happen + self._cache = {} + + def _filter_visible_views(self, cr, uid, ids, context=None): + """Filters the given view ids to only keep the views that should be + visible to the current user. + Uses a cache for speeding up the computation. + """ + with self.cache_lock: + modelaccess = self.pool.get('ir.model.access') + user_groups = set(self.pool.get('res.users').read(cr, 1, uid, ['groups_id'])['groups_id']) + result = [] + for view in self.browse(cr, uid, ids, context=context): + # this key works because user access rights are all based on user's groups (cfr ir_model_access.check) + key = (cr.dbname, view.id, tuple(user_groups)) + if key in self._cache: + if self._cache[key]: + result.append(view.id) + continue + + self._cache[key] = False + if view.groups_id: + restrict_to_groups = [g.id for g in view.groups_id] + if not user_groups.intersection(restrict_to_groups): + continue + + result.append(view.id) + self._cache[key] = True + return result + + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): + if context is None: + context = {} + + ids = super(view, self).search(cr, uid, args, offset=0, + limit=None, order=order, context=context, count=False) + + if not ids: + if count: + return 0 + return [] + + result = self._filter_visible_views(cr, uid, ids, context=context) + + if offset: + result = result[long(offset):] + if limit: + result = result[:long(limit)] + + if count: + return len(result) + return result + def _type_field(self, cr, uid, ids, name, args, context=None): result = {} for record in self.browse(cr, uid, ids, context):
_______________________________________________ Mailing list: https://launchpad.net/~openerp-dev-gtk Post to : [email protected] Unsubscribe : https://launchpad.net/~openerp-dev-gtk More help : https://help.launchpad.net/ListHelp

