예제 #1
0
파일: res_users.py 프로젝트: LiberTang0/5
 def _search_group(self, cr, uid, obj, name, args, context=None):
     operand = args[0][2]
     operator = args[0][1]
     lst = True
     if isinstance(operand, bool):
         domains = [[('name', operator, operand)], [('category_id.name', operator, operand)]]
         if operator in expression.NEGATIVE_TERM_OPERATORS == (not operand):
             return expression.AND(domains)
         else:
             return expression.OR(domains)
     if isinstance(operand, basestring):
         lst = False
         operand = [operand]
     where = []
     for group in operand:
         values = filter(bool, group.split('/'))
         group_name = values.pop().strip()
         category_name = values and '/'.join(values).strip() or group_name
         group_domain = [('name', operator, lst and [group_name] or group_name)]
         category_domain = [('category_id.name', operator, lst and [category_name] or category_name)]
         if operator in expression.NEGATIVE_TERM_OPERATORS and not values:
             category_domain = expression.OR([category_domain, [('category_id', '=', False)]])
         if (operator in expression.NEGATIVE_TERM_OPERATORS) == (not values):
             sub_where = expression.AND([group_domain, category_domain])
         else:
             sub_where = expression.OR([group_domain, category_domain])
         if operator in expression.NEGATIVE_TERM_OPERATORS:
             where = expression.AND([where, sub_where])
         else:
             where = expression.OR([where, sub_where])
     return where
예제 #2
0
    def _search(self,
                cr,
                uid,
                args,
                offset=0,
                limit=None,
                order=None,
                context=None,
                count=False,
                access_rights_uid=None):
        """ Override that adds specific access rights of mail.message, to restrict
        messages to published messages for public users. """
        if uid != SUPERUSER_ID:
            group_ids = self.pool.get('res.users').browse(
                cr, uid, uid, context=context).groups_id
            group_user_id = self.pool.get(
                "ir.model.data").get_object_reference(cr, uid, 'base',
                                                      'group_public')[1]
            if group_user_id in [group.id for group in group_ids]:
                args = expression.AND([[('website_published', '=', True)],
                                       list(args)])

        return super(MailMessage,
                     self)._search(cr,
                                   uid,
                                   args,
                                   offset=offset,
                                   limit=limit,
                                   order=order,
                                   context=context,
                                   count=count,
                                   access_rights_uid=access_rights_uid)
예제 #3
0
 def channel_search_to_join(self, name=None, domain=None):
     """ Return the channel info of the channel the current partner can join
         :param name : the name of the researched channels
         :param domain : the base domain of the research
         :returns dict : channel dict
     """
     if not domain:
         domain = []
     domain = expression.AND([
         [('channel_type', '=', 'channel')],
         [('channel_partner_ids', 'not in', [self.env.user.partner_id.id])],
         [('public', '!=', 'private')],
         domain
     ])
     if name:
         domain = expression.AND([domain, [('name', 'ilike', '%'+name+'%')]])
     return self.search(domain).read(['name', 'public', 'uuid', 'channel_type'])
예제 #4
0
    def test_40_negating_long_expression(self):
        source = ['!','&',('user_id','=',4),('partner_id','in',[1,2])]
        expect = ['|',('user_id','!=',4),('partner_id','not in',[1,2])]
        self.assertEqual(expression.distribute_not(source), expect,
            "distribute_not on expression applied wrongly")

        pos_leaves = [[('a', 'in', [])], [('d', '!=', 3)]]
        neg_leaves = [[('a', 'not in', [])], [('d', '=', 3)]]

        source = expression.OR([expression.AND(pos_leaves)] * 1000)
        expect = source
        self.assertEqual(expression.distribute_not(source), expect,
            "distribute_not on long expression without negation operator should not alter it")

        source = ['!'] + source
        expect = expression.AND([expression.OR(neg_leaves)] * 1000)
        self.assertEqual(expression.distribute_not(source), expect,
            "distribute_not on long expression applied wrongly")
예제 #5
0
 def get_mention_suggestions(self, search, limit=8):
     """ Return 'limit'-first channels' id, name and public fields such that the name matches a
         'search' string. Exclude channels of type chat (DM), and private channels the current
         user isn't registered to. """
     domain = expression.AND([
                     [('name', 'ilike', search)],
                     [('channel_type', '=', 'channel')],
                     expression.OR([
                         [('public', '!=', 'private')],
                         [('channel_partner_ids', 'in', [self.env.user.partner_id.id])]
                     ])
                 ])
     return self.search_read(domain, ['id', 'name', 'public'], limit=limit)
예제 #6
0
 def name_search(self, name, args=None, operator='ilike', limit=80):
     """ Returns a list of tupples containing id, name, as internally it is called {def name_get}
         result format: {[(id, name), (id, name), ...]}
     """
     args = args or []
     if operator in expression.NEGATIVE_TERM_OPERATORS:
         domain = [('description', operator, name),
                   ('name', operator, name)]
     else:
         domain = [
             '|', ('description', operator, name), ('name', operator, name)
         ]
     taxes = self.search(expression.AND([domain, args]), limit=limit)
     return taxes.name_get()
예제 #7
0
파일: res_partner.py 프로젝트: LiberTang0/5
    def get_mention_suggestions(self, search, limit=8):
        """ Return 'limit'-first partners' id, name and email such that the name or email matches a
            'search' string. Prioritize users, and then extend the research to all partners. """
        search_dom = expression.OR([[('name', 'ilike', search)], [('email', 'ilike', search)]])
        fields = ['id', 'name', 'email']

        # Search users
        domain = expression.AND([[('user_ids.id', '!=', False)], search_dom])
        users = self.search_read(domain, fields, limit=limit)

        # Search partners if less than 'limit' users found
        partners = []
        if len(users) < limit:
            partners = self.search_read(search_dom, fields, limit=limit)
            # Remove duplicates
            partners = [p for p in partners if not len([u for u in users if u['id'] == p['id']])] 

        return [users, partners]
예제 #8
0
    def _compute_domain(self, cr, uid, model_name, mode="read"):
        if mode not in self._MODES:
            raise ValueError('Invalid mode: %r' % (mode, ))

        if uid == SUPERUSER_ID:
            return None
        cr.execute(
            """SELECT r.id
                FROM ir_rule r
                JOIN ir_model m ON (r.model_id = m.id)
                WHERE m.model = %s
                AND r.active is True
                AND r.perm_""" + mode + """
                AND (r.id IN (SELECT rule_group_id FROM rule_group_rel g_rel
                            JOIN res_groups_users_rel u_rel ON (g_rel.group_id = u_rel.gid)
                            WHERE u_rel.uid = %s) OR r.global)""",
            (model_name, uid))
        rule_ids = [x[0] for x in cr.fetchall()]
        if rule_ids:
            # browse user as super-admin root to avoid access errors!
            user = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid)
            global_domains = []  # list of domains
            group_domains = {}  # map: group -> list of domains
            for rule in self.browse(cr, SUPERUSER_ID, rule_ids):
                # read 'domain' as UID to have the correct eval context for the rule.
                rule_domain = self.read(cr, uid, [rule.id],
                                        ['domain'])[0]['domain']
                dom = expression.normalize_domain(rule_domain)
                for group in rule.groups:
                    if group in user.groups_id:
                        group_domains.setdefault(group, []).append(dom)
                if not rule.groups:
                    global_domains.append(dom)
            # combine global domains and group domains
            if group_domains:
                group_domain = expression.OR(
                    map(expression.OR, group_domains.values()))
            else:
                group_domain = []
            domain = expression.AND(global_domains + [group_domain])
            return domain
        return []