You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.1 KiB

  1. from odoo.tests.common import SavepointCase
  2. class TestUserRestriction(SavepointCase):
  3. @classmethod
  4. def setUpClass(cls):
  5. super().setUpClass()
  6. cls.env = cls.env(context=dict(
  7. cls.env.context,
  8. tracking_disable=True,
  9. no_reset_password=True,
  10. ))
  11. cls.pos_user = cls.env['res.users'].create({
  12. 'login': 'pos_user',
  13. 'name': 'pos_user',
  14. 'groups_id': [(6, 0, [cls.env.ref('point_of_sale.group_pos_user').id])]
  15. })
  16. cls.pos_user_assigned_pos = cls.env['res.users'].create({
  17. 'login': 'pos_user_assigned_pos',
  18. 'name': 'pos_user_assigned_pos',
  19. 'groups_id': [(6, 0, [cls.env.ref(
  20. 'pos_user_restriction.group_assigned_points_of_sale_user').id])]
  21. })
  22. cls.pos_config_main = cls.env.ref('point_of_sale.pos_config_main')
  23. cls.pos_config_model = cls.env['pos.config']
  24. def test_access_pos(self):
  25. # assigned_user_ids is not set: both users can read
  26. pos_configs = self.pos_config_model.sudo(self.pos_user.id).search([])
  27. self.assertTrue(pos_configs)
  28. pos_configs = self.pos_config_model.sudo(
  29. self.pos_user_assigned_pos.id).search([])
  30. self.assertTrue(pos_configs)
  31. self.pos_config_main.assigned_user_ids = [
  32. (6, 0, [self.pos_user_assigned_pos.id])]
  33. # assigned_user_ids is set with pos_user_assigned_pos: both users can read
  34. pos_configs = self.pos_config_model.sudo(self.pos_user.id).search([])
  35. self.assertTrue(pos_configs)
  36. pos_configs = self.pos_config_model.sudo(
  37. self.pos_user_assigned_pos.id).search([])
  38. self.assertTrue(pos_configs)
  39. self.pos_config_main.assigned_user_ids = [
  40. (6, 0, [self.pos_user.id])]
  41. # assigned_user_ids is set with pos_user: only pos_user can read
  42. pos_configs = self.pos_config_model.sudo(self.pos_user.id).search([])
  43. self.assertTrue(pos_configs)
  44. pos_configs = self.pos_config_model.sudo(
  45. self.pos_user_assigned_pos.id).search([])
  46. self.assertFalse(pos_configs)