mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] base_user_role_history: black, isort
This commit is contained in:
@@ -2,28 +2,25 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Base User Role History',
|
"name": "Base User Role History",
|
||||||
'summary': """
|
"summary": """
|
||||||
This module allows to track the changes on users roles.""",
|
This module allows to track the changes on users roles.""",
|
||||||
'version': '12.0.1.0.0',
|
"version": "12.0.1.0.0",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'author': 'ACSONE SA/NV, '
|
"author": "ACSONE SA/NV, " "Odoo Community Association (OCA)",
|
||||||
'Odoo Community Association (OCA)',
|
"website": "https://github.com/OCA/server-tools",
|
||||||
'website': 'https://github.com/OCA/server-tools',
|
"depends": [
|
||||||
'depends': [
|
|
||||||
# Odoo
|
# Odoo
|
||||||
'mail',
|
"mail",
|
||||||
# OCA
|
# OCA
|
||||||
'base_user_role',
|
"base_user_role",
|
||||||
'base_suspend_security',
|
"base_suspend_security",
|
||||||
],
|
],
|
||||||
'data': [
|
"data": [
|
||||||
'security/base_user_role_line_history.xml',
|
"security/base_user_role_line_history.xml",
|
||||||
'views/base_user_role_line_history.xml',
|
"views/base_user_role_line_history.xml",
|
||||||
'views/res_users.xml',
|
"views/res_users.xml",
|
||||||
],
|
|
||||||
'development_status': 'Beta',
|
|
||||||
'maintainers': [
|
|
||||||
'ThomasBinsfeld'
|
|
||||||
],
|
],
|
||||||
|
"development_status": "Beta",
|
||||||
|
"maintainers": ["ThomasBinsfeld"],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,71 +5,47 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
|
|
||||||
class BaseUserRoleLineHistory(models.Model):
|
class BaseUserRoleLineHistory(models.Model):
|
||||||
_name = 'base.user.role.line.history'
|
_name = "base.user.role.line.history"
|
||||||
_description = "History of user roles"
|
_description = "History of user roles"
|
||||||
_order = 'id desc'
|
_order = "id desc"
|
||||||
|
|
||||||
performed_action = fields.Selection(
|
performed_action = fields.Selection(
|
||||||
string="Action",
|
string="Action",
|
||||||
selection=[
|
selection=[("add", "Add"), ("unlink", "Delete"), ("edit", "Edit")],
|
||||||
('add', 'Add'),
|
|
||||||
('unlink', 'Delete'),
|
|
||||||
('edit', 'Edit')
|
|
||||||
],
|
|
||||||
required=True,
|
required=True,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
string="User",
|
string="User",
|
||||||
comodel_name='res.users',
|
comodel_name="res.users",
|
||||||
ondelete='cascade',
|
ondelete="cascade",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
index=True,
|
index=True,
|
||||||
)
|
)
|
||||||
old_role_id = fields.Many2one(
|
old_role_id = fields.Many2one(
|
||||||
string="Old role",
|
string="Old role",
|
||||||
comodel_name='res.users.role',
|
comodel_name="res.users.role",
|
||||||
ondelete='cascade',
|
ondelete="cascade",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
index=True,
|
index=True,
|
||||||
)
|
)
|
||||||
new_role_id = fields.Many2one(
|
new_role_id = fields.Many2one(
|
||||||
string="New role",
|
string="New role",
|
||||||
comodel_name='res.users.role',
|
comodel_name="res.users.role",
|
||||||
ondelete='cascade',
|
ondelete="cascade",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
index=True,
|
index=True,
|
||||||
)
|
)
|
||||||
old_date_from = fields.Date(
|
old_date_from = fields.Date(string="Old start date", readonly=True)
|
||||||
string="Old start date",
|
new_date_from = fields.Date(string="New start date", readonly=True)
|
||||||
readonly=True,
|
old_date_to = fields.Date(string="Old end date", readonly=True)
|
||||||
)
|
new_date_to = fields.Date(string="New end date", readonly=True)
|
||||||
new_date_from = fields.Date(
|
old_is_enabled = fields.Boolean(string="Active before edit", readonly=True)
|
||||||
string="New start date",
|
new_is_enabled = fields.Boolean(string="Active after edit", readonly=True)
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
old_date_to = fields.Date(
|
|
||||||
string="Old end date",
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
new_date_to = fields.Date(
|
|
||||||
string="New end date",
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
old_is_enabled = fields.Boolean(
|
|
||||||
string="Active before edit",
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
new_is_enabled = fields.Boolean(
|
|
||||||
string="Active after edit",
|
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_create_from_vals(
|
def _prepare_create_from_vals(
|
||||||
self,
|
self, old_role_line_values_by_user, new_role_line_values_by_user
|
||||||
old_role_line_values_by_user,
|
|
||||||
new_role_line_values_by_user
|
|
||||||
):
|
):
|
||||||
role_history_line_vals_by_role_line = {}
|
role_history_line_vals_by_role_line = {}
|
||||||
for key, value in new_role_line_values_by_user.items():
|
for key, value in new_role_line_values_by_user.items():
|
||||||
@@ -77,53 +53,51 @@ class BaseUserRoleLineHistory(models.Model):
|
|||||||
new_vals = value
|
new_vals = value
|
||||||
# Manage deletion of role lines and old values of modified lines
|
# Manage deletion of role lines and old values of modified lines
|
||||||
for role_line_id, role_line_vals in old_vals.items():
|
for role_line_id, role_line_vals in old_vals.items():
|
||||||
action = 'unlink' if role_line_id not in new_vals else 'edit'
|
action = "unlink" if role_line_id not in new_vals else "edit"
|
||||||
if action == 'edit':
|
if action == "edit":
|
||||||
# Skip if no change
|
# Skip if no change
|
||||||
if not any(
|
if not any(
|
||||||
role_line_vals[k] != new_vals[role_line_id][k]
|
role_line_vals[k] != new_vals[role_line_id][k]
|
||||||
for k in role_line_vals
|
for k in role_line_vals
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
role_history_line_vals_by_role_line.setdefault(
|
role_history_line_vals_by_role_line.setdefault(role_line_id, {})
|
||||||
role_line_id, {}
|
role_history_line_vals_by_role_line[role_line_id].update(
|
||||||
|
{
|
||||||
|
"performed_action": action,
|
||||||
|
"user_id": role_line_vals["user_id"],
|
||||||
|
"old_role_id": role_line_vals["role_id"],
|
||||||
|
"old_date_from": role_line_vals["date_from"],
|
||||||
|
"old_date_to": role_line_vals["date_to"],
|
||||||
|
"old_is_enabled": role_line_vals["is_enabled"],
|
||||||
|
}
|
||||||
)
|
)
|
||||||
role_history_line_vals_by_role_line[role_line_id].update({
|
|
||||||
'performed_action': action,
|
|
||||||
'user_id': role_line_vals['user_id'],
|
|
||||||
'old_role_id': role_line_vals['role_id'],
|
|
||||||
'old_date_from': role_line_vals['date_from'],
|
|
||||||
'old_date_to': role_line_vals['date_to'],
|
|
||||||
'old_is_enabled': role_line_vals['is_enabled'],
|
|
||||||
})
|
|
||||||
# Manage addition of role lines and new values of modified ones
|
# Manage addition of role lines and new values of modified ones
|
||||||
for role_line_id, role_line_vals in new_vals.items():
|
for role_line_id, role_line_vals in new_vals.items():
|
||||||
action = 'add' if role_line_id not in old_vals else 'edit'
|
action = "add" if role_line_id not in old_vals else "edit"
|
||||||
if action == 'edit':
|
if action == "edit":
|
||||||
# Skip if no change
|
# Skip if no change
|
||||||
if not any(
|
if not any(
|
||||||
role_line_vals[k] != old_vals[role_line_id][k]
|
role_line_vals[k] != old_vals[role_line_id][k]
|
||||||
for k in role_line_vals
|
for k in role_line_vals
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
role_history_line_vals_by_role_line.setdefault(
|
role_history_line_vals_by_role_line.setdefault(role_line_id, {})
|
||||||
role_line_id, {}
|
role_history_line_vals_by_role_line[role_line_id].update(
|
||||||
|
{
|
||||||
|
"performed_action": action,
|
||||||
|
"user_id": role_line_vals["user_id"],
|
||||||
|
"new_role_id": role_line_vals["role_id"],
|
||||||
|
"new_date_from": role_line_vals["date_from"],
|
||||||
|
"new_date_to": role_line_vals["date_to"],
|
||||||
|
"new_is_enabled": role_line_vals["is_enabled"],
|
||||||
|
}
|
||||||
)
|
)
|
||||||
role_history_line_vals_by_role_line[role_line_id].update({
|
|
||||||
'performed_action': action,
|
|
||||||
'user_id': role_line_vals['user_id'],
|
|
||||||
'new_role_id': role_line_vals['role_id'],
|
|
||||||
'new_date_from': role_line_vals['date_from'],
|
|
||||||
'new_date_to': role_line_vals['date_to'],
|
|
||||||
'new_is_enabled': role_line_vals['is_enabled'],
|
|
||||||
})
|
|
||||||
return role_history_line_vals_by_role_line
|
return role_history_line_vals_by_role_line
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create_from_vals(
|
def create_from_vals(
|
||||||
self,
|
self, old_role_line_values_by_user, new_role_line_values_by_user
|
||||||
old_role_line_values_by_user,
|
|
||||||
new_role_line_values_by_user
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
This method creates user role line history objects based on given
|
This method creates user role line history objects based on given
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
# Copyright 2019 ACSONE SA/NV
|
# Copyright 2019 ACSONE SA/NV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, fields, models, _
|
from odoo import _, api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class ResUsers(models.Model):
|
class ResUsers(models.Model):
|
||||||
_inherit = 'res.users'
|
_inherit = "res.users"
|
||||||
|
|
||||||
last_role_line_modification = fields.Datetime(
|
last_role_line_modification = fields.Datetime(
|
||||||
string="Last roles modification",
|
string="Last roles modification", readonly=True
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_role_line_history_dict(self, role_line):
|
def _prepare_role_line_history_dict(self, role_line):
|
||||||
return {
|
return {
|
||||||
'user_id': role_line.user_id.id,
|
"user_id": role_line.user_id.id,
|
||||||
'role_id': role_line.role_id.id,
|
"role_id": role_line.role_id.id,
|
||||||
'date_from': role_line.date_from,
|
"date_from": role_line.date_from,
|
||||||
'date_to': role_line.date_to,
|
"date_to": role_line.date_to,
|
||||||
'is_enabled': role_line.is_enabled,
|
"is_enabled": role_line.is_enabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -28,48 +27,45 @@ class ResUsers(models.Model):
|
|||||||
for rec in self:
|
for rec in self:
|
||||||
role_line_values_by_user.setdefault(rec, {})
|
role_line_values_by_user.setdefault(rec, {})
|
||||||
for role_line in rec.role_line_ids:
|
for role_line in rec.role_line_ids:
|
||||||
role_line_values_by_user[rec][role_line.id] = \
|
role_line_values_by_user[rec][
|
||||||
self._prepare_role_line_history_dict(role_line)
|
role_line.id
|
||||||
|
] = self._prepare_role_line_history_dict(role_line)
|
||||||
return role_line_values_by_user
|
return role_line_values_by_user
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
res = super().create(vals_list)
|
res = super().create(vals_list)
|
||||||
for vals in vals_list:
|
for vals in vals_list:
|
||||||
if 'role_line_ids' not in vals:
|
if "role_line_ids" not in vals:
|
||||||
return res
|
return res
|
||||||
new_role_line_values_by_user = res._get_role_line_values_by_user()
|
new_role_line_values_by_user = res._get_role_line_values_by_user()
|
||||||
self.env['base.user.role.line.history'].create_from_vals(
|
self.env["base.user.role.line.history"].create_from_vals(
|
||||||
{},
|
{}, new_role_line_values_by_user
|
||||||
new_role_line_values_by_user
|
|
||||||
)
|
)
|
||||||
res.last_role_line_modification = fields.Datetime.now()
|
res.last_role_line_modification = fields.Datetime.now()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
if 'role_line_ids' not in vals:
|
if "role_line_ids" not in vals:
|
||||||
return super().write(vals)
|
return super().write(vals)
|
||||||
old_role_line_values_by_user = self._get_role_line_values_by_user()
|
old_role_line_values_by_user = self._get_role_line_values_by_user()
|
||||||
res = super().write(vals)
|
res = super().write(vals)
|
||||||
new_role_line_values_by_user = self._get_role_line_values_by_user()
|
new_role_line_values_by_user = self._get_role_line_values_by_user()
|
||||||
self.env['base.user.role.line.history'].create_from_vals(
|
self.env["base.user.role.line.history"].create_from_vals(
|
||||||
old_role_line_values_by_user,
|
old_role_line_values_by_user, new_role_line_values_by_user
|
||||||
new_role_line_values_by_user
|
|
||||||
)
|
)
|
||||||
self.write({
|
self.write({"last_role_line_modification": fields.Datetime.now()})
|
||||||
'last_role_line_modification': fields.Datetime.now()
|
|
||||||
})
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def show_role_lines_history(self): # pragma: no cover
|
def show_role_lines_history(self): # pragma: no cover
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
domain = [('user_id', '=', self.id)]
|
domain = [("user_id", "=", self.id)]
|
||||||
return {
|
return {
|
||||||
'name': _("Roles history"),
|
"name": _("Roles history"),
|
||||||
'type': 'ir.actions.act_window',
|
"type": "ir.actions.act_window",
|
||||||
'view_mode': 'tree,form',
|
"view_mode": "tree,form",
|
||||||
'res_model': 'base.user.role.line.history',
|
"res_model": "base.user.role.line.history",
|
||||||
'domain': domain,
|
"domain": domain,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,25 +7,20 @@ from odoo.tests.common import SavepointCase
|
|||||||
|
|
||||||
|
|
||||||
class TestBaseUserRoleHistory(SavepointCase):
|
class TestBaseUserRoleHistory(SavepointCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestBaseUserRoleHistory, cls).setUpClass()
|
super(TestBaseUserRoleHistory, cls).setUpClass()
|
||||||
|
|
||||||
# MODELS
|
# MODELS
|
||||||
|
|
||||||
cls.history_line_model = cls.env['base.user.role.line.history']
|
cls.history_line_model = cls.env["base.user.role.line.history"]
|
||||||
cls.role_model = cls.env['res.users.role']
|
cls.role_model = cls.env["res.users.role"]
|
||||||
cls.user_model = cls.env['res.users']
|
cls.user_model = cls.env["res.users"]
|
||||||
|
|
||||||
# INSTANCE
|
# INSTANCE
|
||||||
|
|
||||||
cls.user_01 = cls.user_model.search([
|
cls.user_01 = cls.user_model.search([("id", "!=", cls.env.user.id)], limit=1)
|
||||||
('id', '!=', cls.env.user.id)
|
cls.role_01 = cls.role_model.create({"name": "Role test 01"})
|
||||||
], limit=1)
|
|
||||||
cls.role_01 = cls.role_model.create({
|
|
||||||
'name': "Role test 01",
|
|
||||||
})
|
|
||||||
|
|
||||||
def test_write_role_lines_on_user(self):
|
def test_write_role_lines_on_user(self):
|
||||||
"""
|
"""
|
||||||
@@ -43,80 +38,74 @@ class TestBaseUserRoleHistory(SavepointCase):
|
|||||||
4) new role history line created with performed_action == 'unlink'
|
4) new role history line created with performed_action == 'unlink'
|
||||||
"""
|
"""
|
||||||
# 1
|
# 1
|
||||||
history_lines_0 = self.history_line_model.search([
|
history_lines_0 = self.history_line_model.search(
|
||||||
('user_id', '=', self.user_01.id)
|
[("user_id", "=", self.user_01.id)]
|
||||||
])
|
)
|
||||||
self.assertFalse(history_lines_0)
|
self.assertFalse(history_lines_0)
|
||||||
self.user_01.write({
|
self.user_01.write({"role_line_ids": [(0, 0, {"role_id": self.role_01.id})]})
|
||||||
'role_line_ids': [
|
history_lines_1 = self.history_line_model.search(
|
||||||
(0, 0, {
|
[("user_id", "=", self.user_01.id)]
|
||||||
'role_id': self.role_01.id
|
)
|
||||||
})
|
|
||||||
]
|
|
||||||
})
|
|
||||||
history_lines_1 = self.history_line_model.search([
|
|
||||||
('user_id', '=', self.user_01.id)
|
|
||||||
])
|
|
||||||
self.assertTrue(history_lines_1)
|
self.assertTrue(history_lines_1)
|
||||||
self.assertEqual(len(history_lines_1), 1)
|
self.assertEqual(len(history_lines_1), 1)
|
||||||
self.assertEqual(history_lines_1.performed_action, 'add')
|
self.assertEqual(history_lines_1.performed_action, "add")
|
||||||
self.assertFalse(history_lines_1.old_role_id)
|
self.assertFalse(history_lines_1.old_role_id)
|
||||||
self.assertEqual(history_lines_1.new_role_id, self.role_01)
|
self.assertEqual(history_lines_1.new_role_id, self.role_01)
|
||||||
# 2
|
# 2
|
||||||
self.user_01.write({
|
self.user_01.write(
|
||||||
'role_line_ids': [
|
{
|
||||||
(1, self.user_01.role_line_ids[0].id, {
|
"role_line_ids": [
|
||||||
'date_from': date.today(),
|
(
|
||||||
'date_to': date.today() + timedelta(days=5),
|
1,
|
||||||
})
|
self.user_01.role_line_ids[0].id,
|
||||||
|
{
|
||||||
|
"date_from": date.today(),
|
||||||
|
"date_to": date.today() + timedelta(days=5),
|
||||||
|
},
|
||||||
|
)
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
history_lines_2 = self.history_line_model.search([
|
)
|
||||||
('user_id', '=', self.user_01.id),
|
history_lines_2 = self.history_line_model.search(
|
||||||
('id', 'not in', history_lines_1.ids)
|
[("user_id", "=", self.user_01.id), ("id", "not in", history_lines_1.ids)]
|
||||||
])
|
)
|
||||||
self.assertTrue(history_lines_2)
|
self.assertTrue(history_lines_2)
|
||||||
self.assertEqual(len(history_lines_2), 1)
|
self.assertEqual(len(history_lines_2), 1)
|
||||||
self.assertEqual(history_lines_2.performed_action, 'edit')
|
self.assertEqual(history_lines_2.performed_action, "edit")
|
||||||
self.assertEqual(history_lines_2.old_role_id, self.role_01)
|
self.assertEqual(history_lines_2.old_role_id, self.role_01)
|
||||||
self.assertEqual(history_lines_2.new_role_id, self.role_01)
|
self.assertEqual(history_lines_2.new_role_id, self.role_01)
|
||||||
self.assertFalse(history_lines_2.old_date_from)
|
self.assertFalse(history_lines_2.old_date_from)
|
||||||
self.assertEqual(history_lines_2.new_date_from, date.today())
|
self.assertEqual(history_lines_2.new_date_from, date.today())
|
||||||
self.assertFalse(history_lines_2.old_date_to)
|
self.assertFalse(history_lines_2.old_date_to)
|
||||||
self.assertEqual(
|
self.assertEqual(history_lines_2.new_date_to, date.today() + timedelta(days=5))
|
||||||
history_lines_2.new_date_to,
|
self.user_01.write(
|
||||||
date.today() + timedelta(days=5)
|
{"role_line_ids": [(1, self.user_01.role_line_ids[0].id, {})]}
|
||||||
|
)
|
||||||
|
history_lines_3 = self.history_line_model.search(
|
||||||
|
[
|
||||||
|
("user_id", "=", self.user_01.id),
|
||||||
|
("id", "not in", (history_lines_1 | history_lines_2).ids),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
self.user_01.write({
|
|
||||||
'role_line_ids': [(1, self.user_01.role_line_ids[0].id, {})]
|
|
||||||
})
|
|
||||||
history_lines_3 = self.history_line_model.search([
|
|
||||||
('user_id', '=', self.user_01.id),
|
|
||||||
('id', 'not in', (history_lines_1 | history_lines_2).ids)
|
|
||||||
])
|
|
||||||
self.assertFalse(history_lines_3)
|
self.assertFalse(history_lines_3)
|
||||||
# 4
|
# 4
|
||||||
self.user_01.write({
|
self.user_01.write(
|
||||||
'role_line_ids': [(2, self.user_01.role_line_ids[0].id, False)],
|
{"role_line_ids": [(2, self.user_01.role_line_ids[0].id, False)]}
|
||||||
})
|
)
|
||||||
history_lines_4 = self.history_line_model.search([
|
history_lines_4 = self.history_line_model.search(
|
||||||
('user_id', '=', self.user_01.id),
|
[
|
||||||
('id', 'not in', (history_lines_1 | history_lines_2).ids)
|
("user_id", "=", self.user_01.id),
|
||||||
])
|
("id", "not in", (history_lines_1 | history_lines_2).ids),
|
||||||
|
]
|
||||||
|
)
|
||||||
self.assertTrue(history_lines_4)
|
self.assertTrue(history_lines_4)
|
||||||
self.assertEqual(len(history_lines_4), 1)
|
self.assertEqual(len(history_lines_4), 1)
|
||||||
self.assertEqual(history_lines_4.performed_action, 'unlink')
|
self.assertEqual(history_lines_4.performed_action, "unlink")
|
||||||
self.assertEqual(history_lines_4.old_role_id, self.role_01)
|
self.assertEqual(history_lines_4.old_role_id, self.role_01)
|
||||||
self.assertFalse(history_lines_4.new_role_id)
|
self.assertFalse(history_lines_4.new_role_id)
|
||||||
self.assertEqual(
|
self.assertEqual(history_lines_4.old_date_from, date.today())
|
||||||
history_lines_4.old_date_from,
|
|
||||||
date.today()
|
|
||||||
)
|
|
||||||
self.assertFalse(history_lines_4.new_date_from)
|
self.assertFalse(history_lines_4.new_date_from)
|
||||||
self.assertEqual(
|
self.assertEqual(history_lines_4.old_date_to, date.today() + timedelta(days=5))
|
||||||
history_lines_4.old_date_to,
|
|
||||||
date.today() + timedelta(days=5)
|
|
||||||
)
|
|
||||||
self.assertFalse(history_lines_4.new_date_to)
|
self.assertFalse(history_lines_4.new_date_to)
|
||||||
|
|
||||||
def test_create_role_lines_on_new_user(self):
|
def test_create_role_lines_on_new_user(self):
|
||||||
@@ -127,21 +116,17 @@ class TestBaseUserRoleHistory(SavepointCase):
|
|||||||
Expected results :
|
Expected results :
|
||||||
- new role history line created with performed_action == 'add'
|
- new role history line created with performed_action == 'add'
|
||||||
"""
|
"""
|
||||||
new_user = self.user_model.create({
|
new_user = self.user_model.create(
|
||||||
'login': 'new_user',
|
{
|
||||||
'name': 'new_user',
|
"login": "new_user",
|
||||||
'role_line_ids': [
|
"name": "new_user",
|
||||||
(0, 0, {
|
"role_line_ids": [(0, 0, {"role_id": self.role_01.id})],
|
||||||
'role_id': self.role_01.id,
|
}
|
||||||
})
|
)
|
||||||
]
|
history_lines = self.history_line_model.search([("user_id", "=", new_user.id)])
|
||||||
})
|
|
||||||
history_lines = self.history_line_model.search([
|
|
||||||
('user_id', '=', new_user.id)
|
|
||||||
])
|
|
||||||
self.assertTrue(history_lines)
|
self.assertTrue(history_lines)
|
||||||
self.assertEqual(len(history_lines), 1)
|
self.assertEqual(len(history_lines), 1)
|
||||||
self.assertEqual(history_lines.performed_action, 'add')
|
self.assertEqual(history_lines.performed_action, "add")
|
||||||
|
|
||||||
def test_no_create_role_lines_on_new_user(self):
|
def test_no_create_role_lines_on_new_user(self):
|
||||||
"""
|
"""
|
||||||
@@ -151,11 +136,6 @@ class TestBaseUserRoleHistory(SavepointCase):
|
|||||||
Expected results :
|
Expected results :
|
||||||
- no role history line created
|
- no role history line created
|
||||||
"""
|
"""
|
||||||
new_user = self.user_model.create({
|
new_user = self.user_model.create({"login": "new_user", "name": "new_user"})
|
||||||
'login': 'new_user',
|
history_lines = self.history_line_model.search([("user_id", "=", new_user.id)])
|
||||||
'name': 'new_user',
|
|
||||||
})
|
|
||||||
history_lines = self.history_line_model.search([
|
|
||||||
('user_id', '=', new_user.id)
|
|
||||||
])
|
|
||||||
self.assertFalse(history_lines)
|
self.assertFalse(history_lines)
|
||||||
|
|||||||
Reference in New Issue
Block a user