impersonate_user: add unimpersonate systray button
This commit is contained in:
parent
aed5ad9aed
commit
8d9fc7db46
9 changed files with 74 additions and 4 deletions
|
|
@ -1 +1,2 @@
|
||||||
from . import models
|
from . import models
|
||||||
|
from . import controllers
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,16 @@
|
||||||
"author": "Bemade Inc.",
|
"author": "Bemade Inc.",
|
||||||
"website": "http://www.bemade.org",
|
"website": "http://www.bemade.org",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"depends": ["base"],
|
"depends": ["web"],
|
||||||
"data": [
|
"data": [
|
||||||
"views/impersonation_views.xml",
|
"views/impersonation_views.xml",
|
||||||
],
|
],
|
||||||
"assets": {},
|
"assets": {
|
||||||
|
"web.assets_backend": [
|
||||||
|
"impersonate_user/static/src/**/*.js",
|
||||||
|
"impersonate_user/static/src/**/*.xml",
|
||||||
|
]
|
||||||
|
},
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"auto_install": False,
|
"auto_install": False,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
impersonate_user/controllers/__init__.py
Normal file
1
impersonate_user/controllers/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import main
|
||||||
9
impersonate_user/controllers/main.py
Normal file
9
impersonate_user/controllers/main.py
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
from odoo import http
|
||||||
|
from odoo.http import request
|
||||||
|
|
||||||
|
|
||||||
|
class UserImpersonationController(http.Controller):
|
||||||
|
|
||||||
|
@http.route("/unimpersonate", type="json", auth="user")
|
||||||
|
def unimpersonate(self):
|
||||||
|
return request.env["res.users"].sudo().unimpersonate()
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
from . import res_users
|
from . import res_users
|
||||||
|
from . import ir_http
|
||||||
|
|
|
||||||
11
impersonate_user/models/ir_http.py
Normal file
11
impersonate_user/models/ir_http.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from odoo import models
|
||||||
|
from odoo.http import request
|
||||||
|
|
||||||
|
|
||||||
|
class IrHttp(models.AbstractModel):
|
||||||
|
_inherit = "ir.http"
|
||||||
|
|
||||||
|
def session_info(self):
|
||||||
|
result = super().session_info()
|
||||||
|
result["user_impersonated"] = bool(request.session.get("original_uid", False))
|
||||||
|
return result
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from odoo import models, fields
|
from odoo import models, fields, _, api
|
||||||
from odoo.exceptions import AccessError
|
from odoo.exceptions import AccessError
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
|
|
@ -22,8 +22,8 @@ class ResUsers(models.Model):
|
||||||
"target": "self",
|
"target": "self",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@api.model
|
||||||
def unimpersonate(self):
|
def unimpersonate(self):
|
||||||
self.ensure_one()
|
|
||||||
original_uid = request.session.pop("original_uid", False)
|
original_uid = request.session.pop("original_uid", False)
|
||||||
if original_uid:
|
if original_uid:
|
||||||
request.session.uid = original_uid
|
request.session.uid = original_uid
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import {Component} from "@odoo/owl";
|
||||||
|
import {useService} from "@web/core/utils/hooks";
|
||||||
|
import {session} from "@web/session";
|
||||||
|
import {registry} from "@web/core/registry";
|
||||||
|
|
||||||
|
export class SystrayUnimpersonateButton extends Component {
|
||||||
|
setup() {
|
||||||
|
this.rpc = useService("rpc");
|
||||||
|
this.action = useService("action");
|
||||||
|
}
|
||||||
|
|
||||||
|
async unimpersonate() {
|
||||||
|
this.rpc("/unimpersonate", {}).then((result) => this.action.doAction(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
get isVisible() {
|
||||||
|
return session.user_impersonated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SystrayUnimpersonateButton.props = {};
|
||||||
|
SystrayUnimpersonateButton.template = "impersonate_user.SystrayUnimpersonateButton";
|
||||||
|
registry.category("systray").add("unimpersonate_button", {
|
||||||
|
Component: SystrayUnimpersonateButton,
|
||||||
|
});
|
||||||
15
impersonate_user/static/src/systray_unimpersonate_button.xml
Normal file
15
impersonate_user/static/src/systray_unimpersonate_button.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<templates xml:space="preserve">
|
||||||
|
<t t-name="impersonate_user.SystrayUnimpersonateButton">
|
||||||
|
<div t-if="isVisible" class="o-dropdown dropdown o-dropdown--no-caret">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
t-on-click="unimpersonate"
|
||||||
|
class="dropdown-toggle o-dropdown--narrow"
|
||||||
|
title="Unimpersonate"
|
||||||
|
>
|
||||||
|
<i class="oi oi-close" role="img" aria-label="Unimpersonate" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
Loading…
Reference in a new issue