forked from OCA/server-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] impersonate_login: migration to V17
- Loading branch information
Showing
22 changed files
with
508 additions
and
234 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 |
---|---|---|
|
@@ -28,23 +28,41 @@ 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** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
The impersonating user must belong to group "Impersonate Users". | ||
|
||
Usage | ||
===== | ||
|
||
1. On the top right corner, click my user and "switch login" | ||
2. Same place to "return to my login" | ||
1. 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" to | ||
impersonate another user. | ||
2. On the top-right corner, the button "Back to Original User" is | ||
displayed in case the current user is being impersonated. | ||
|
||
Bug Tracker | ||
=========== | ||
|
@@ -68,6 +86,9 @@ Contributors | |
------------ | ||
|
||
- 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
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(env): | ||
""" | ||
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") | ||
env.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
The impersonating user must belong to group "Impersonate Users". |
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]>\> | ||
- [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,6 +1,11 @@ | ||
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,4 @@ | ||
1. On the top right corner, click my user and "switch login" | ||
2. Same place to "return to my login" | ||
1. 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" to impersonate another user. | ||
2. 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.