Skip to content

Commit

Permalink
[IMP] impersonate_login: Update create_uid for impersonated record cr…
Browse files Browse the repository at this point in the history
…eation

- Ensure impersonation is properly reflected in record creation
- Update related tests to verify correct impersonation behavior
  • Loading branch information
toita86 committed Oct 31, 2024
1 parent f997464 commit d7c55c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion impersonate_login/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ def _create(self, data_list):
and request.session.impersonate_from_uid
and "create_uid" in self._fields
):
impersonator_id = request.session.impersonate_from_uid
for rec in res:
rec["create_uid"] = request.session.impersonate_from_uid
self.env.cr.execute(
"""
UPDATE "%s" SET create_uid = %%s WHERE id = %%s
"""
% self._table,
(impersonator_id, rec.id),
)
return res

def write(self, vals):
Expand Down
4 changes: 4 additions & 0 deletions impersonate_login/tests/test_impersonate_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def test_01_admin_impersonates_user_demo(self):

# Check impersonate log
log2 = self.env["impersonate.log"].search([], order="id desc", limit=1)
# Refresh the log1 after the attribute date_end is updated
log1.refresh()
self.assertEqual(log1, log2)
self.assertTrue(log1.date_start)
self.assertTrue(log1.date_end)
Expand Down Expand Up @@ -254,6 +256,8 @@ def test_04_write_uid(self):
data = response.json()
result = data["result"]

# Refresh contact to reflect changes in the database
self.assertEqual(result, True)
contact.invalidate_cache()
self.assertEqual(contact.ref, "abc")
self.assertEqual(contact.write_uid, self.admin_user)

0 comments on commit d7c55c2

Please sign in to comment.