diff options
| author | xO-Tx <mou@odoo.com> | 2020-11-17 14:18:47 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2020-12-28 14:29:15 +0000 |
| commit | 3da25b8a3b97d01025ace11db449ca4768cdfa25 (patch) | |
| tree | 983cc5b65e6c164dd812b6d1f97d7cd5abc0774a /addons/website_mail_channel | |
| parent | 38c5bd45c450bf04e7cc0a53d2051522332e97ed (diff) | |
[FIX] website_mail_channel: fix discussion group snippet without group
Prevent crash while trying to subscribe to a non existing channel from
a misconfigured snippet.
Also now let the user create the channel linked to the discussion group
directly on snippet drop if no channel is available to select
automatically.
task-2356955
closes odoo/odoo#60608
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/website_mail_channel')
3 files changed, 42 insertions, 7 deletions
diff --git a/addons/website_mail_channel/controllers/main.py b/addons/website_mail_channel/controllers/main.py index dd7de5fce26..37dd899b3fc 100644 --- a/addons/website_mail_channel/controllers/main.py +++ b/addons/website_mail_channel/controllers/main.py @@ -94,6 +94,9 @@ class MailGroup(http.Controller): """ unsubscribe = subscription == 'on' channel = request.env['mail.channel'].browse(int(channel_id)) + if not channel.exists(): + return False + partner_ids = [] # search partner_id diff --git a/addons/website_mail_channel/static/src/snippets/s_channel/options.js b/addons/website_mail_channel/static/src/snippets/s_channel/options.js index b6d89d8928f..5b51bb6afc2 100644 --- a/addons/website_mail_channel/static/src/snippets/s_channel/options.js +++ b/addons/website_mail_channel/static/src/snippets/s_channel/options.js @@ -11,9 +11,30 @@ options.registry.Channel = options.Class.extend({ /** * @override */ + async start() { + await this._super(...arguments); + this.publicChannels = await this._getPublicChannels(); + }, + /** + * @override + */ cleanForSave: function () { this.$target.addClass('d-none'); }, + /** + * If we have already created channels => select the first one + * else => modal prompt (create a new channel) + * + * @override + */ + onBuilt() { + if (this.publicChannels.length) { + this.$target[0].dataset.id = this.publicChannels[0][0]; + } else { + const widget = this._requestUserValueWidgets('create_mail_channel_opt')[0]; + widget.$el.click(); + } + }, //-------------------------------------------------------------------------- // Options @@ -56,12 +77,12 @@ options.registry.Channel = options.Class.extend({ /** * @override */ - _renderCustomXML: function (uiFragment) { - return this._rpc({ - model: 'mail.channel', - method: 'name_search', - args: ['', [['public', '=', 'public']]], - }).then(channels => { + _renderCustomXML(uiFragment) { + // TODO remove this part in master + const createChannelEl = uiFragment.querySelector('we-button[data-create-channel]'); + createChannelEl.dataset.name = 'create_mail_channel_opt'; + + return this._getPublicChannels().then(channels => { const menuEl = uiFragment.querySelector('.select_discussion_list'); for (const channel of channels) { const el = document.createElement('we-button'); @@ -71,5 +92,16 @@ options.registry.Channel = options.Class.extend({ } }); }, + /** + * @private + * @return {Promise} + */ + _getPublicChannels() { + return this._rpc({ + model: 'mail.channel', + method: 'name_search', + args: ['', [['public', '=', 'public']]], + }); + }, }); }); diff --git a/addons/website_mail_channel/views/snippets/s_channel.xml b/addons/website_mail_channel/views/snippets/s_channel.xml index bd38a8d1aad..78217040d6c 100644 --- a/addons/website_mail_channel/views/snippets/s_channel.xml +++ b/addons/website_mail_channel/views/snippets/s_channel.xml @@ -32,7 +32,7 @@ <!-- 'we-button' added programmatically with DB data --> </we-select> <we-button class="fa fa-fw fa-plus" title="Create a public discussion group in your backend" - data-create-channel="" data-no-preview="true"/> + data-create-channel="" data-no-preview="true" data-name="create_mail_channel_opt"/> </we-row> </div> </xpath> |
