Skip to content
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

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

toita86
Copy link

@toita86 toita86 commented Oct 31, 2024

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.

@toita86 toita86 marked this pull request as ready for review October 31, 2024 11:12
@toita86
Copy link
Author

toita86 commented Oct 31, 2024

@Kev-Roche @astirpe, can you please checkout my implementation for the _create() method?
It is the only way i found to guarantee the correct assignment for create_uid and to get the tests passing.
If you have any concerns or suggestions for improvement, please let me know.

Copy link

@aleuffre aleuffre left a 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

class BaseModel(models.AbstractModel):
_inherit = "base"

@api.model_create_multi
Copy link

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

Comment on lines 21 to 28
for rec in res:
self.env.cr.execute(
"""
UPDATE "%s" SET create_uid = %%s WHERE id = %%s
"""
% self._table,
(impersonator_id, rec.id),
)
Copy link

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?

Copy link
Author

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.

Copy link

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)

Copy link

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

Copy link
Author

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
Copy link

@aleuffre aleuffre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review, LGTM

Copy link
Contributor

@francesco-ooops francesco-ooops left a 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?

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@francesco-ooops
Copy link
Contributor

@OCA/tools-maintainers @simahawk good for merge?

@thomaspaulb
Copy link
Contributor

/ocabot migration impersonate_login

/ocabot merge nobump

@OCA-git-bot OCA-git-bot added this to the 14.0 milestone Nov 13, 2024
@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 14.0-ocabot-merge-pr-722-by-thomaspaulb-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot mentioned this pull request Nov 13, 2024
17 tasks
@OCA-git-bot OCA-git-bot merged commit cfb79e7 into OCA:14.0 Nov 13, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at cf67a5b. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants