mirror of https://github.com/OCA/web.git
[FIX] bug if the current user doesn't have access to a model of a tile;
parent
4aec073b11
commit
f291de5255
|
@ -30,6 +30,10 @@
|
||||||
"description": """
|
"description": """
|
||||||
module to give you a dashboard where you can configure tile from any view
|
module to give you a dashboard where you can configure tile from any view
|
||||||
and add them as short cut.
|
and add them as short cut.
|
||||||
|
Tile can be:
|
||||||
|
* affected to a user;
|
||||||
|
* be global for all users (In that case, some tiles will be hidden if
|
||||||
|
the current user doesn't have access to the given model);
|
||||||
|
|
||||||
Kown issues/limits:
|
Kown issues/limits:
|
||||||
* change color picks wrong color
|
* change color picks wrong color
|
||||||
|
|
|
@ -28,14 +28,36 @@ import random
|
||||||
class tile(orm.Model):
|
class tile(orm.Model):
|
||||||
_name = 'tile.tile'
|
_name = 'tile.tile'
|
||||||
|
|
||||||
def _get_tile_count(self, cr, uid, ids, field_name, field_value,
|
def _get_tile_info(self, cr, uid, ids, fields, args, context=None):
|
||||||
arg, context=None):
|
ima_obj = self.pool['ir.model.access']
|
||||||
result = {}
|
res = {}
|
||||||
records = self.browse(cr, uid, ids)
|
records = self.browse(cr, uid, ids, context=context)
|
||||||
for r in records:
|
for r in records:
|
||||||
|
if ima_obj.check(
|
||||||
|
cr, uid, r.model_id.model, 'read', False, context):
|
||||||
model = self.pool.get(r.model_id.model)
|
model = self.pool.get(r.model_id.model)
|
||||||
result[r.id] = model.search_count(cr, uid, eval(r.domain), context)
|
res[r.id] = {
|
||||||
return result
|
'active': True,
|
||||||
|
'count': model.search_count(
|
||||||
|
cr, uid, eval(r.domain), context),
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
res[r.id] = {'active': False, 'count': 0}
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _search_active(self, cr, uid, obj, name, arg, context=None):
|
||||||
|
ima_obj = self.pool['ir.model.access']
|
||||||
|
ids = []
|
||||||
|
cr.execute("""
|
||||||
|
SELECT tt.id, im.model
|
||||||
|
FROM tile_tile tt
|
||||||
|
INNER JOIN ir_model im
|
||||||
|
ON tt.model_id = im.id""")
|
||||||
|
for result in cr.fetchall():
|
||||||
|
if (ima_obj.check(cr, uid, result[1], 'read', False) ==
|
||||||
|
arg[0][2]):
|
||||||
|
ids.append(result[0])
|
||||||
|
return [('id', 'in', ids)]
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Tile Name'),
|
'name': fields.char('Tile Name'),
|
||||||
|
@ -43,9 +65,13 @@ class tile(orm.Model):
|
||||||
'user_id': fields.many2one('res.users', 'User'),
|
'user_id': fields.many2one('res.users', 'User'),
|
||||||
'domain': fields.text('Domain'),
|
'domain': fields.text('Domain'),
|
||||||
'action_id': fields.many2one('ir.actions.act_window', 'Action'),
|
'action_id': fields.many2one('ir.actions.act_window', 'Action'),
|
||||||
'count': fields.function(_get_tile_count, type='int', String='Count',
|
'count': fields.function(
|
||||||
readonly=True),
|
_get_tile_info, type='int', string='Count',
|
||||||
'color': fields.char('Kanban Color')
|
multi='tile_info', readonly=True),
|
||||||
|
'active': fields.function(
|
||||||
|
_get_tile_info, type='boolean', string='Active',
|
||||||
|
multi='tile_info', readonly=True, fnct_search=_search_active),
|
||||||
|
'color': fields.char('Kanban Color'),
|
||||||
}
|
}
|
||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
|
|
Loading…
Reference in New Issue