[IMP] mail, bus: move "admin" password warning into bus notification
Remove complex dependency on discuss.channel for this simple warning. closes odoo/odoo#119252 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import home
|
||||
from . import main
|
||||
from . import websocket
|
||||
|
||||
@@ -5,14 +5,8 @@ from odoo import _, SUPERUSER_ID
|
||||
from odoo.http import request
|
||||
from odoo.addons.web.controllers.home import Home as WebHome
|
||||
|
||||
|
||||
def _admin_password_warn(uid):
|
||||
""" Admin still has `admin` password, flash a message via chatter.
|
||||
|
||||
Uses a private discuss.channel from the system (/ odoobot) to the user, as
|
||||
using a more generic mail.thread could send an email which is undesirable
|
||||
|
||||
Uses discuss.channel directly because using mail.thread might send an email instead.
|
||||
"""
|
||||
if request.params['password'] != 'admin':
|
||||
return
|
||||
if ipaddress.ip_address(request.httprequest.remote_addr).is_private:
|
||||
@@ -24,19 +18,16 @@ def _admin_password_warn(uid):
|
||||
has_demo = bool(env['ir.module.module'].search_count([('demo', '=', True)]))
|
||||
if has_demo:
|
||||
return
|
||||
|
||||
user = request.env(user=uid)['res.users']
|
||||
DiscussChannel = env(context=user.context_get())['discuss.channel']
|
||||
DiscussChannel.browse(DiscussChannel.channel_get([admin.id])['id'])\
|
||||
.message_post(
|
||||
body=_("Your password is the default (admin)! If this system is exposed to untrusted users it is important to change it immediately for security reasons. I will keep nagging you about it!"),
|
||||
message_type='comment',
|
||||
subtype_xmlid='mail.mt_comment'
|
||||
)
|
||||
env(context=user.context_get())['bus.bus']._sendone(admin, 'simple_notification', {
|
||||
'type': 'danger',
|
||||
'message': _("Your password is the default (admin)! If this system is exposed to untrusted users it is important to change it immediately for security reasons. I will keep nagging you about it!"),
|
||||
'sticky': True,
|
||||
})
|
||||
|
||||
|
||||
class Home(WebHome):
|
||||
def _login_redirect(self, uid, redirect=None):
|
||||
if request.params.get('login_success'):
|
||||
_admin_password_warn(uid)
|
||||
|
||||
return super()._login_redirect(uid, redirect)
|
||||
@@ -1,5 +1,5 @@
|
||||
from odoo import models
|
||||
from odoo.http import SessionExpiredException
|
||||
from odoo.http import request, SessionExpiredException
|
||||
from odoo.service import security
|
||||
from ..models.bus import dispatch
|
||||
from ..websocket import wsrequest
|
||||
@@ -26,7 +26,10 @@ class IrWebsocket(models.AbstractModel):
|
||||
|
||||
:param channels: The channel list sent by the client.
|
||||
"""
|
||||
req = request or wsrequest
|
||||
channels.append('broadcast')
|
||||
if req.session.uid:
|
||||
channels.append(self.env.user.partner_id)
|
||||
return channels
|
||||
|
||||
def _subscribe(self, data):
|
||||
|
||||
@@ -3,5 +3,4 @@
|
||||
|
||||
from . import bus
|
||||
from . import discuss
|
||||
from . import home
|
||||
from . import mail
|
||||
|
||||
@@ -25,9 +25,7 @@ class IrWebsocket(models.AbstractModel):
|
||||
guest_sudo = self.env['mail.guest']._get_guest_from_request(req).sudo()
|
||||
discuss_channels = self.env['discuss.channel']
|
||||
if req.session.uid:
|
||||
partner = self.env.user.partner_id
|
||||
discuss_channels = partner.channel_ids
|
||||
channels.append(partner)
|
||||
discuss_channels = self.env.user.partner_id.channel_ids
|
||||
elif guest_sudo:
|
||||
discuss_channels = guest_sudo.channel_ids
|
||||
channels.append(guest_sudo)
|
||||
|
||||
Reference in New Issue
Block a user