Browse Source

Merge pull request #922 from osiell/8.0-base_user_role_backport_features

[8.0] base_user_role: backport features from 9.0 + Fix from 10.0
pull/1072/head
Stefan Rijnhart (Opener) 7 years ago
committed by GitHub
parent
commit
f0a9607ecf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      base_user_role/__openerp__.py
  2. 12
      base_user_role/data/ir_module_category.xml
  3. 20
      base_user_role/models/role.py
  4. 4
      base_user_role/views/user.xml

1
base_user_role/__openerp__.py

@ -15,6 +15,7 @@
], ],
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'data/ir_module_category.xml',
'data/ir_cron.xml', 'data/ir_cron.xml',
'views/role.xml', 'views/role.xml',
'views/user.xml', 'views/user.xml',

12
base_user_role/data/ir_module_category.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 ABF OSIELL <http://osiell.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data>
<record model="ir.module.category" id="ir_module_category_role">
<field name='name'>User roles</field>
</record>
</data>
</openerp>

20
base_user_role/models/role.py

@ -24,6 +24,12 @@ class ResUsersRole(models.Model):
user_ids = fields.One2many( user_ids = fields.One2many(
'res.users', string=u"Users", compute='_compute_user_ids') 'res.users', string=u"Users", compute='_compute_user_ids')
_defaults = { # pylint: disable=attribute-deprecated
'category_id': api.model(
lambda cls: cls.env.ref(
'base_user_role.ir_module_category_role').id),
}
@api.multi @api.multi
@api.depends('line_ids.user_id') @api.depends('line_ids.user_id')
def _compute_user_ids(self): def _compute_user_ids(self):
@ -42,6 +48,13 @@ class ResUsersRole(models.Model):
self.update_users() self.update_users()
return res return res
@api.multi
def unlink(self):
users = self.mapped('user_id')
res = super(ResUsersRole, self).unlink()
users.set_groups_from_roles()
return res
@api.multi @api.multi
def update_users(self): def update_users(self):
"""Update all the users concerned by the roles identified by `ids`.""" """Update all the users concerned by the roles identified by `ids`."""
@ -81,3 +94,10 @@ class ResUsersRoleLine(models.Model):
date_to = fields.Date.from_string(role_line.date_to) date_to = fields.Date.from_string(role_line.date_to)
if today > date_to: if today > date_to:
role_line.is_enabled = False role_line.is_enabled = False
@api.multi
def unlink(self):
users = self.mapped('user_id')
res = super(ResUsersRoleLine, self).unlink()
users.set_groups_from_roles()
return res

4
base_user_role/views/user.xml

@ -9,7 +9,7 @@
<field name="model">res.users</field> <field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/> <field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<notebook position="inside">
<xpath expr="//notebook/page[1]" position="before">
<page string="Roles"> <page string="Roles">
<field name="role_line_ids" nolabel="1"> <field name="role_line_ids" nolabel="1">
<tree editable="bottom" colors="grey: not is_enabled;"> <tree editable="bottom" colors="grey: not is_enabled;">
@ -20,7 +20,7 @@
</tree> </tree>
</field> </field>
</page> </page>
</notebook>
</xpath>
</field> </field>
</record> </record>

Loading…
Cancel
Save