<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#    Copyright (C) 2010-2012 OpenERP SA (<http://openerp.com>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import base64
import re
import threading
from tools.safe_eval import safe_eval as eval
import tools
import openerp.modules
from osv import fields, osv
from tools.translate import _
from openerp import SUPERUSER_ID

def one_in(setA, setB):
    """Check the presence of an element of setA in setB
    """
    for x in setA:
        if x in setB:
            return True
    return False

class ir_ui_menu(osv.osv):
    _name = 'ir.ui.menu'

    def __init__(self, *args, **kwargs):
        self.cache_lock = threading.RLock()
        self._cache = {}
        r = super(ir_ui_menu, self).__init__(*args, **kwargs)
        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
            if self._cache:
                # Normally this is done by openerp.tools.ormcache
                # but since we do not use it, set it by ourself.
                self.pool._any_cache_cleared = True
            self._cache = {}

    def _filter_visible_menus(self, cr, uid, ids, context=None):
        """Filters the give menu ids to only keep the menu items that should be
           visible in the menu hierarchy of 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, SUPERUSER_ID, uid, ['groups_id'])['groups_id'])
            result = []
            for menu in self.browse(cr, SUPERUSER_ID, 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, menu.id, tuple(user_groups))
                if key in self._cache:
                    if self._cache[key]:
                        result.append(menu.id)
                    #elif not menu.groups_id and not menu.action:<commit_msg>[REVERT] Undo r.4617, introduced a bug in menu hierarchy retrieval<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#    Copyright (C) 2010-2012 OpenERP SA (<http://openerp.com>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import base64
import re
import threading
from tools.safe_eval import safe_eval as eval
import tools
import openerp.modules
from osv import fields, osv
from tools.translate import _
from openerp import SUPERUSER_ID

def one_in(setA, setB):
    """Check the presence of an element of setA in setB
    """
    for x in setA:
        if x in setB:
            return True
    return False

class ir_ui_menu(osv.osv):
    _name = 'ir.ui.menu'

    def __init__(self, *args, **kwargs):
        self.cache_lock = threading.RLock()
        self._cache = {}
        r = super(ir_ui_menu, self).__init__(*args, **kwargs)
        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
            if self._cache:
                # Normally this is done by openerp.tools.ormcache
                # but since we do not use it, set it by ourself.
                self.pool._any_cache_cleared = True
            self._cache = {}

    def _filter_visible_menus(self, cr, uid, ids, context=None):
        """Filters the give menu ids to only keep the menu items that should be
           visible in the menu hierarchy of 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, SUPERUSER_ID, uid, ['groups_id'])['groups_id'])
            result = []
            for menu 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, menu.id, tuple(user_groups))
                if key in self._cache:
                    if self._cache[key]:
                        result.append(menu.id)
                    #elif not menu.groups_id and not menu.action:
{'fraction_non_alphanumeric': 0.13294982422499202, 'fraction_numerical': 0.007031000319590924, 'mean_word_length': 2.607492795389049, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4423481', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1674, 'n_words': 632}