[ADD] web: ability to become superuser (uid=1)
* requires that current user has group_system * only visible in debug mode (?debug) * available at login or via debug menu * special systray color in superuser sessions Closes #27254
This commit is contained in:
@@ -22,6 +22,7 @@ import time
|
||||
import zlib
|
||||
|
||||
import werkzeug
|
||||
import werkzeug.exceptions
|
||||
import werkzeug.utils
|
||||
import werkzeug.wrappers
|
||||
import werkzeug.wsgi
|
||||
@@ -44,7 +45,7 @@ from odoo.http import content_disposition, dispatch_rpc, request, \
|
||||
serialize_exception as _serialize_exception, Response
|
||||
from odoo.exceptions import AccessError, UserError, AccessDenied
|
||||
from odoo.models import check_method_name
|
||||
from odoo.service import db
|
||||
from odoo.service import db, security
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -505,11 +506,25 @@ class Home(http.Controller):
|
||||
if not odoo.tools.config['list_db']:
|
||||
values['disable_database_manager'] = True
|
||||
|
||||
# otherwise no real way to test debug mode in template as ?debug =>
|
||||
# values['debug'] = '' but that's also the fallback value when
|
||||
# missing variables in qweb
|
||||
if 'debug' in values:
|
||||
values['debug'] = True
|
||||
|
||||
response = request.render('web.login', values)
|
||||
response.headers['X-Frame-Options'] = 'DENY'
|
||||
return response
|
||||
|
||||
@http.route('/web/become', type='http', auth='user', sitemap=False)
|
||||
def switch_to_admin(self):
|
||||
uid = request.env.user.id
|
||||
if request.env.user._is_system():
|
||||
uid = request.session.uid = odoo.SUPERUSER_ID
|
||||
request.env['res.users']._invalidate_session_cache()
|
||||
request.session.session_token = security.compute_session_token(request.session, request.env)
|
||||
|
||||
return http.redirect_with_hash(self._login_redirect(uid))
|
||||
|
||||
class WebClient(http.Controller):
|
||||
|
||||
|
||||
@@ -132,6 +132,9 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi
|
||||
self.action_manager.$el.on('scroll', core.bus.trigger.bind(core.bus, 'scroll'));
|
||||
core.bus.trigger('web_client_ready');
|
||||
odoo.isReady = true;
|
||||
if (session.uid === 1) {
|
||||
self.$el.addClass('o_is_superuser');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -1,4 +1,23 @@
|
||||
body.o_is_superuser .o_menu_systray {
|
||||
background: repeating-linear-gradient(
|
||||
135deg,
|
||||
#d9b904, #d9b904 10px,
|
||||
#373435 10px, #373435 20px
|
||||
);
|
||||
border-bottom-left-radius: 20px;
|
||||
|
||||
> li {
|
||||
> a, > label {
|
||||
&:hover {
|
||||
background-color: fade_out($o-navbar-inverse-link-hover-bg, 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.show .dropdown-toggle {
|
||||
background-color: fade_out($o-navbar-inverse-link-hover-bg, 0.5);
|
||||
}
|
||||
}
|
||||
.o_main_navbar {
|
||||
position: relative;
|
||||
height: $o-navbar-height;
|
||||
|
||||
@@ -247,6 +247,7 @@
|
||||
<div class="dropdown-divider o_debug_leave_section" role="separator"/>
|
||||
<a role="menuitem" href="#" data-action="split_assets" class="dropdown-item">Activate Assets Debugging</a>
|
||||
<a role="menuitem" href="#" data-action="regenerateAssets" class="dropdown-item">Regenerate Assets Bundles</a>
|
||||
<a t-if="manager._is_admin" role="menuitem" href="/web/become" class="dropdown-item">Become Superuser</a>
|
||||
<a role="menuitem" href="#" data-action="leave_debug_mode" class="dropdown-item">Leave the Developer Tools</a>
|
||||
</t>
|
||||
<t t-name="WebClient.DebugManager.Action">
|
||||
|
||||
@@ -409,11 +409,15 @@
|
||||
<t t-esc="message"/>
|
||||
</p>
|
||||
|
||||
<input type="hidden" name="redirect" t-att-value="redirect"/>
|
||||
<div t-attf-class="clearfix oe_login_buttons text-center mb-1 {{'pt-2' if form_small else 'pt-3'}}">
|
||||
<button type="submit" class="btn btn-primary btn-block">Log in</button>
|
||||
<t t-if="debug">
|
||||
<button type="submit" name="redirect" value="/web/become" class="btn btn-link btn-sm btn-block">Log in as superuser</button>
|
||||
</t>
|
||||
<div class="o_login_auth"/>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="redirect" t-att-value="redirect"/>
|
||||
</form>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user