-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
450 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ Impersonate Login | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:1fca331cbc5f2dcb804e5612e5669a9ab4998d80f22d46d6683266580f9ca40f | ||
!! source digest: sha256:a9d881ab6f6e5777204c45f152c0af22753629ca4b46ac913fe8da3792573ca8 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
|
@@ -28,13 +28,22 @@ Impersonate Login | |
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to login as another user. | ||
In the chatter, the user who is logged as another user is displayed. | ||
The mails and messages are sent from the orignal user. | ||
A table diplays the impersonated logins in technical. | ||
The user can return to his own user by clicking on the button "Return to my user". | ||
This module is very useful for the support team. | ||
An alternative module will be auth_admin_passkey. | ||
This module allows one user (for example, a member of the support team) | ||
to log in as another user. The impersonation session can be exited by | ||
clicking on the button "Back to Original User". | ||
|
||
To ensure that any abuse of this feature will not go unnoticed, the | ||
following measures are in place: | ||
|
||
- In the chatter, it is displayed who is the user that is logged as | ||
another user. | ||
- Mails and messages are sent from the original user. | ||
- Impersonated logins are logged and can be consulted through the | ||
Settings -> Technical menu. | ||
- | ||
|
||
There is an alternative module to allow logins as another user | ||
(auth_admin_passkey), but it does not support these security mechanisms. | ||
|
||
**Table of contents** | ||
|
||
|
@@ -44,8 +53,9 @@ An alternative module will be auth_admin_passkey. | |
Usage | ||
===== | ||
|
||
1. On the top right corner, click my user and "switch login" | ||
2. Same place to "return to my login" | ||
The impersonating user must belong to group "Impersonate Users". | ||
- In the menu that is displayed when clicking on the user avatar on the top right corner, or in the res.users list, click "Switch Login" toi mpersonate another user. | ||
- On the top-right corner, the button "Back to Original User" is displayed in case the current user is being impersonated. | ||
|
||
Bug Tracker | ||
=========== | ||
|
@@ -68,7 +78,9 @@ Authors | |
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Kévin Roche <[email protected]> | ||
- Kévin Roche <[email protected]> | ||
- [360ERP](https://www.360erp.com): | ||
- Andrea Stirpe | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from .hooks import pre_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ | |
"qweb": [ | ||
"static/src/xml/user_menu.xml", | ||
], | ||
"pre_init_hook": "pre_init_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 360ERP (<https://www.360erp.com>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
|
||
def pre_init_hook(cr): | ||
""" | ||
Pre-create the impersonated_author_id column in the mail_message table | ||
to prevent the ORM from invoking its compute method on a large volume | ||
of existing mail messages. | ||
""" | ||
logger = logging.getLogger(__name__) | ||
logger.info("Add mail_message.impersonated_author_id column if not exists") | ||
cr.execute( | ||
"ALTER TABLE mail_message " | ||
"ADD COLUMN IF NOT EXISTS " | ||
"impersonated_author_id INTEGER" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,31 @@ | |
# @author Kévin Roche <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
from odoo import models | ||
from odoo.http import request | ||
|
||
|
||
class BaseModel(models.AbstractModel): | ||
_inherit = "base" | ||
|
||
@api.model_create_multi | ||
def _create(self, data_list): | ||
res = super()._create(data_list) | ||
if request and request.session.impersonate_from_uid: | ||
for rec in res: | ||
rec.create_uid = request.session.impersonate_from_uid | ||
return res | ||
def _prepare_create_values(self, vals_list): | ||
result_vals_list = super()._prepare_create_values(vals_list) | ||
if ( | ||
request | ||
and request.session.impersonate_from_uid | ||
and "create_uid" in self._fields | ||
): | ||
for vals in result_vals_list: | ||
vals["create_uid"] = request.session.impersonate_from_uid | ||
return result_vals_list | ||
|
||
def write(self, vals): | ||
"""Overwrite the write_uid with the impersonating user""" | ||
res = super().write(vals) | ||
if request and request.session.impersonate_from_uid: | ||
self.write_uid = request.session.impersonate_from_uid | ||
if ( | ||
request | ||
and request.session.impersonate_from_uid | ||
and "write_uid" in self._fields | ||
): | ||
self._fields["write_uid"].write(self, request.session.impersonate_from_uid) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
* Kévin Roche <[email protected]> | ||
- Kévin Roche <[email protected]> | ||
- [360ERP](https://www.360erp.com): | ||
- Andrea Stirpe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
This module allows to login as another user. | ||
In the chatter, the user who is logged as another user is displayed. | ||
The mails and messages are sent from the orignal user. | ||
A table diplays the impersonated logins in technical. | ||
The user can return to his own user by clicking on the button "Return to my user". | ||
This module is very useful for the support team. | ||
An alternative module will be auth_admin_passkey. | ||
This module allows one user (for example, a member of the support team) | ||
to log in as another user. The impersonation session can be exited by | ||
clicking on the button "Back to Original User". | ||
|
||
To ensure that any abuse of this feature will not go unnoticed, the | ||
following measures are in place: | ||
|
||
- In the chatter, it is displayed who is the user that is logged as | ||
another user. | ||
- Mails and messages are sent from the original user. | ||
- Impersonated logins are logged and can be consulted through the | ||
Settings -> Technical menu. | ||
- | ||
|
||
There is an alternative module to allow logins as another user | ||
(auth_admin_passkey), but it does not support these security mechanisms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
1. On the top right corner, click my user and "switch login" | ||
2. Same place to "return to my login" | ||
The impersonating user must belong to group "Impersonate Users". | ||
- In the menu that is displayed when clicking on the user avatar on the top right corner, or in the res.users list, click "Switch Login" toi mpersonate another user. | ||
- On the top-right corner, the button "Back to Original User" is displayed in case the current user is being impersonated. |
Oops, something went wrong.