-
-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][IMP] impersonate_login #722
Conversation
@Kev-Roche @astirpe, can you please checkout my implementation for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review, mostly looks ok, a couple of questions
impersonate_login/models/model.py
Outdated
class BaseModel(models.AbstractModel): | ||
_inherit = "base" | ||
|
||
@api.model_create_multi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: This is an api.model
, not a model_create_multi
in base Odoo v14
impersonate_login/models/model.py
Outdated
for rec in res: | ||
self.env.cr.execute( | ||
""" | ||
UPDATE "%s" SET create_uid = %%s WHERE id = %%s | ||
""" | ||
% self._table, | ||
(impersonator_id, rec.id), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Prefer %(varname)
syntax if possible please. https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#33idioms
question: Is there a strong reason for running a query directly instead of doing it like in the original commit?
for rec in res:
rec["create_uid"] = request.session.impersonate_from_uid
If we have to run the query directly, can we at least run a single query for all records in res
instead of a separate query for each?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have used the preferred syntax now.
question: Is there a strong reason for running a query directly instead of doing it like in the original commit?
I was not able to get it working in the way was done in the original commit because the assignment of rec["create_uid"]
doesn't not happen for some reason.
I think has something to do with the method _create
that in the following version of this module is changed with _prepare_create_values
but I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to get it working in the way was done in the original commit because the assignment of
rec["create_uid"]
doesn't not happen for some reason.
Normal write operations can't update create_uid
. Excerpts from https://github.com/odoo/odoo/blob/14.0/odoo/models.py:
LOG_ACCESS_COLUMNS = ['create_uid', 'create_date', 'write_uid', 'write_date']
bad_names = {'id', 'parent_path'}
if self._log_access:
# the superuser can set log_access fields while loading registry
if not(self.env.uid == SUPERUSER_ID and not self.pool.ready):
bad_names.update(LOG_ACCESS_COLUMNS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good to know, thank you so much @amh-mw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amh-mw Thanks for the explanation!
…eation - Ensure impersonation is properly reflected in record creation - Update related tests to verify correct impersonation behavior
d7c55c2
to
79f2454
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional ok!
@Kev-Roche @astirpe what do you think?
This PR has the |
@OCA/tools-maintainers @simahawk good for merge? |
/ocabot migration impersonate_login /ocabot merge nobump |
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at cf67a5b. Thanks a lot for contributing to OCA. ❤️ |
MIG/ADD of #637
I have decided to adopt the approach from the original PR and adjust the tests, rather than
backporting from v16 which would have required too many rollbacks to make it compatible with v14.