[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#63854 X-original-commit: 5bb8821c0a78df5c03458a2c902e1a9c7a12f2f9 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -8,12 +8,33 @@ var wUtils = require('website.utils');
|
||||
var _t = core._t;
|
||||
|
||||
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,19 +77,25 @@ options.registry.Channel = options.Class.extend({
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_renderCustomXML: function (uiFragment) {
|
||||
async _renderCustomXML(uiFragment) {
|
||||
const channels = await this._getPublicChannels();
|
||||
const menuEl = uiFragment.querySelector('.select_discussion_list');
|
||||
for (const channel of channels) {
|
||||
const el = document.createElement('we-button');
|
||||
el.dataset.selectDataAttribute = channel[0];
|
||||
el.textContent = channel[1];
|
||||
menuEl.appendChild(el);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @return {Promise}
|
||||
*/
|
||||
_getPublicChannels() {
|
||||
return this._rpc({
|
||||
model: 'mail.channel',
|
||||
method: 'name_search',
|
||||
args: ['', [['public', '=', 'public']]],
|
||||
}).then(channels => {
|
||||
const menuEl = uiFragment.querySelector('.select_discussion_list');
|
||||
for (const channel of channels) {
|
||||
const el = document.createElement('we-button');
|
||||
el.dataset.selectDataAttribute = channel[0];
|
||||
el.textContent = channel[1];
|
||||
menuEl.appendChild(el);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user