From 23ffc7f5b61c852a84c2cc8e8f9a97aeb54fbd3b Mon Sep 17 00:00:00 2001 From: Hiral Bhavsar Date: Wed, 7 Oct 2020 11:11:25 +0000 Subject: [PATCH] [FIX] mail, website_slides: fix while accept the request from the new attendee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: We have a new feature that if the course is private, and attendee make the request to access the course it will create an activity for 'course responsible'. Currently, after accepting the invitation request from the new user, it is still not considered the user as an attendee and not displaying like 'You're enrolled' to the respective users After this commit: The features of access invitation on courses will be workable. Task-2328389 closes odoo/odoo#60135 X-original-commit: becf051f38fcf08d4a0aea758cb2758ad0f25bc3 Signed-off-by: Alexandre Kühn (aku) --- .../static/src/models/activity/activity.js | 20 +++ .../src/components/activity/activity_tests.js | 124 ++++++++++++++++++ .../website_slides/static/src/js/activity.js | 44 ++++++- .../static/src/xml/activity.xml | 18 ++- addons/website_slides/views/assets.xml | 5 + 5 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 addons/website_slides/static/src/components/activity/activity_tests.js diff --git a/addons/mail/static/src/models/activity/activity.js b/addons/mail/static/src/models/activity/activity.js index d30d9e6d1a6..b88c4b335d2 100644 --- a/addons/mail/static/src/models/activity/activity.js +++ b/addons/mail/static/src/models/activity/activity.js @@ -114,6 +114,18 @@ function factory(dependencies) { ]; } } + if ('request_partner_id' in data) { + if (!data.request_partner_id) { + data2.requestingPartner = [['unlink']]; + } else { + data2.requestingPartner = [ + ['insert', { + id: data.request_partner_id[0], + display_name: data.request_partner_id[1], + }], + ]; + } + } return data2; } @@ -292,6 +304,14 @@ function factory(dependencies) { 'note', ], }), + /** + * Determines that an activity is linked to a requesting partner or not. + * It will be used notably in website slides to know who triggered the + * "request access" activity. + * Also, be useful when the assigned user is different from the + * "source" or "requesting" partner. + */ + requestingPartner: many2one('mail.partner'), state: attr(), summary: attr(), /** diff --git a/addons/website_slides/static/src/components/activity/activity_tests.js b/addons/website_slides/static/src/components/activity/activity_tests.js new file mode 100644 index 00000000000..d8e465a4237 --- /dev/null +++ b/addons/website_slides/static/src/components/activity/activity_tests.js @@ -0,0 +1,124 @@ +odoo.define('website_slides/static/src/tests/activity_tests.js', function (require) { +'use strict'; + +const components = { + Activity: require('mail/static/src/components/activity/activity.js'), +}; + +const { + afterEach, + beforeEach, + createRootComponent, + start, +} = require('mail/static/src/utils/test_utils.js'); + +QUnit.module('website_slides', {}, function () { +QUnit.module('components', {}, function () { +QUnit.module('activity', {}, function () { +QUnit.module('activity_tests.js', { + beforeEach() { + beforeEach(this); + + this.createActivityComponent = async activity => { + await createRootComponent(this, components.Activity, { + props: { activityLocalId: activity.localId }, + target: this.widget.el, + }); + }; + + this.start = async params => { + const { env, widget } = await start(Object.assign({}, params, { + data: this.data, + })); + this.env = env; + this.widget = widget; + }; + }, + afterEach() { + afterEach(this); + }, +}); + +QUnit.test('grant course access', async function (assert) { + assert.expect(8); + + await this.start({ + async mockRPC(route, args) { + if (args.method === 'action_grant_access') { + assert.strictEqual(args.args.length, 1); + assert.strictEqual(args.args[0].length, 1); + assert.strictEqual(args.args[0][0], 100); + assert.strictEqual(args.kwargs.partner_id, 5); + assert.step('access_grant'); + } + return this._super(...arguments); + }, + }); + const activity = this.env.models['mail.activity'].create({ + canWrite: true, + thread: [['insert', { + id: 100, + model: 'slide.channel', + }]], + requestingPartner: [['insert', { + id: 5, + displayName: "Pauvre pomme", + }]], + type: [['insert', { + id: 1, + displayName: "Access Request", + }]], + }); + await this.createActivityComponent(activity); + + assert.containsOnce(document.body, '.o_Activity', "should have activity component"); + assert.containsOnce(document.body, '.o_Activity_grantAccessButton', "should have grant access button"); + + document.querySelector('.o_Activity_grantAccessButton').click(); + assert.verifySteps(['access_grant'], "Grant button should trigger the right rpc call"); +}); + +QUnit.test('refuse course access', async function (assert) { + assert.expect(8); + + await this.start({ + async mockRPC(route, args) { + if (args.method === 'action_refuse_access') { + assert.strictEqual(args.args.length, 1); + assert.strictEqual(args.args[0].length, 1); + assert.strictEqual(args.args[0][0], 100); + assert.strictEqual(args.kwargs.partner_id, 5); + assert.step('access_refuse'); + } + return this._super(...arguments); + }, + }); + const activity = this.env.models['mail.activity'].create({ + canWrite: true, + thread: [['insert', { + id: 100, + model: 'slide.channel', + }]], + requestingPartner: [['insert', { + id: 5, + displayName: "Pauvre pomme", + }]], + type: [['insert', { + id: 1, + displayName: "Access Request", + }]], + }); + await this.createActivityComponent(activity); + + assert.containsOnce(document.body, '.o_Activity', "should have activity component"); + assert.containsOnce(document.body, '.o_Activity_refuseAccessButton', "should have refuse access button"); + + document.querySelector('.o_Activity_refuseAccessButton').click(); + assert.verifySteps(['access_refuse'], "refuse button should trigger the right rpc call"); +}); + +}); +}); +}); + +}); diff --git a/addons/website_slides/static/src/js/activity.js b/addons/website_slides/static/src/js/activity.js index 64b5ead87f9..ac0ae3cdc99 100644 --- a/addons/website_slides/static/src/js/activity.js +++ b/addons/website_slides/static/src/js/activity.js @@ -42,4 +42,46 @@ function applyInclude(Activity) { applyInclude(KanbanActivity); -}); \ No newline at end of file +}); + +odoo.define('website_slides/static/src/components/activity/activity.js', function (require) { +'use strict'; + +const components = { + Activity: require('mail/static/src/components/activity/activity.js'), +}; +const { patch } = require('web.utils'); + +patch(components.Activity, 'website_slides/static/src/components/activity/activity.js', { + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + async _onGrantAccess(ev) { + await this.env.services.rpc({ + model: 'slide.channel', + method: 'action_grant_access', + args: [[this.activity.thread.id]], + kwargs: { partner_id: this.activity.requestingPartner.id }, + }); + this.trigger('reload'); + }, + /** + * @private + */ + async _onRefuseAccess(ev) { + await this.env.services.rpc({ + model: 'slide.channel', + method: 'action_refuse_access', + args: [[this.activity.thread.id]], + kwargs: { partner_id: this.activity.requestingPartner.id }, + }); + this.trigger('reload'); + }, +}); + +}); diff --git a/addons/website_slides/static/src/xml/activity.xml b/addons/website_slides/static/src/xml/activity.xml index 20c683ab3c4..a2f5b2c015b 100644 --- a/addons/website_slides/static/src/xml/activity.xml +++ b/addons/website_slides/static/src/xml/activity.xml @@ -19,4 +19,20 @@ - \ No newline at end of file + + + + +
+ + +
+
+ $0 +
+
+ diff --git a/addons/website_slides/views/assets.xml b/addons/website_slides/views/assets.xml index be74235eae8..1577fe08c0f 100644 --- a/addons/website_slides/views/assets.xml +++ b/addons/website_slides/views/assets.xml @@ -65,6 +65,11 @@ +