diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 232c35bc8a6..6092c1da083 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -230,8 +230,6 @@ class Web_Editor(http.Controller): def video_url_data(self, video_url, autoplay=False, loop=False, hide_controls=False, hide_fullscreen=False, hide_yt_logo=False, hide_dm_logo=False, hide_dm_share=False): - if not request.env.user._is_internal(): - raise werkzeug.exceptions.Forbidden() return get_video_url_data( video_url, autoplay=autoplay, loop=loop, hide_controls=hide_controls, hide_fullscreen=hide_fullscreen, diff --git a/addons/web_editor/static/src/components/media_dialog/video_selector.js b/addons/web_editor/static/src/components/media_dialog/video_selector.js index c2e9985f52d..cf5960d53d0 100644 --- a/addons/web_editor/static/src/components/media_dialog/video_selector.js +++ b/addons/web_editor/static/src/components/media_dialog/video_selector.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { _t } from "@web/core/l10n/translation"; -import { useService } from '@web/core/utils/hooks'; +import { useAutofocus, useService } from '@web/core/utils/hooks'; import { debounce } from '@web/core/utils/timing'; import { Component, useState, useRef, onMounted, onWillStart } from "@odoo/owl"; @@ -9,6 +9,13 @@ import { Component, useState, useRef, onMounted, onWillStart } from "@odoo/owl"; class VideoOption extends Component {} VideoOption.template = 'web_editor.VideoOption'; +class VideoIframe extends Component { + static template = 'web_editor.VideoIframe'; + static props = { + src: { type: String }, + }; +} + export class VideoSelector extends Component { setup() { this.rpc = useService('rpc'); @@ -98,6 +105,8 @@ export class VideoSelector extends Component { })); }); + useAutofocus(); + this.onChangeUrl = debounce((ev) => this.updateVideo(ev.target.value), 500); } @@ -130,6 +139,12 @@ export class VideoSelector extends Component { this.state.options = []; this.state.platform = null; this.state.errorMessage = ''; + /** + * When the url input is emptied, we need to call the `selectMedia` + * callback function to notify the other components that the media + * has changed. + */ + this.props.selectMedia({}); return; } @@ -150,7 +165,13 @@ export class VideoSelector extends Component { options[option.id] = option.value; } } - const { embed_url: src, platform } = await this._getVideoURLData(url, options); + + const { + embed_url: src, + video_id: videoId, + params, + platform + } = await this._getVideoURLData(url, options); if (!src) { this.state.errorMessage = _t("The provided url is not valid"); @@ -173,7 +194,13 @@ export class VideoSelector extends Component { } this.state.src = src; - this.props.selectMedia({ id: src, src }); + this.props.selectMedia({ + id: src, + src, + platform, + videoId, + params + }); if (platform !== this.state.platform) { this.state.platform = platform; this.state.options = newOptions; @@ -213,6 +240,7 @@ VideoSelector.mediaExtraClasses = []; VideoSelector.tagNames = ['IFRAME', 'DIV']; VideoSelector.template = 'web_editor.VideoSelector'; VideoSelector.components = { + VideoIframe, VideoOption, }; VideoSelector.defaultProps = { diff --git a/addons/web_editor/static/src/components/media_dialog/video_selector.xml b/addons/web_editor/static/src/components/media_dialog/video_selector.xml index d43e275cbf2..d97e1273947 100644 --- a/addons/web_editor/static/src/components/media_dialog/video_selector.xml +++ b/addons/web_editor/static/src/components/media_dialog/video_selector.xml @@ -3,27 +3,37 @@ - - + + + + + - + + + + + - + Video code (URL or Embed) Accepts Youtube, Vimeo, Dailymotion and Youku videos - + - + Preview - + diff --git a/addons/web_editor/tests/test_tools.py b/addons/web_editor/tests/test_tools.py index c5da933445e..9c95883cfde 100644 --- a/addons/web_editor/tests/test_tools.py +++ b/addons/web_editor/tests/test_tools.py @@ -68,7 +68,7 @@ class TestVideoUtils(common.BaseCase): self.assertEqual('B6dXGTxggTG', tools.get_video_source_data(TestVideoUtils.urls['instagram'])[1]) def test_get_video_url_data(self): - self.assertEqual(2, len(tools.get_video_url_data(TestVideoUtils.urls['youtube']))) + self.assertEqual(4, len(tools.get_video_url_data(TestVideoUtils.urls['youtube']))) #youtube self.assertEqual('youtube', tools.get_video_url_data(TestVideoUtils.urls['youtube'])['platform']) #vimeo diff --git a/addons/web_editor/tools.py b/addons/web_editor/tools.py index f9da1b9a8bc..9b3a844fb9d 100644 --- a/addons/web_editor/tools.py +++ b/addons/web_editor/tools.py @@ -52,7 +52,7 @@ def get_video_source_data(video_url): def get_video_url_data(video_url, autoplay=False, loop=False, hide_controls=False, hide_fullscreen=False, hide_yt_logo=False, hide_dm_logo=False, hide_dm_share=False): - """ Computes the platform name and embed_url from given URL + """ Computes the platform name, the embed_url, the video id and the video params of the given URL (or error message in case of invalid URL). """ source = get_video_source_data(video_url) @@ -115,7 +115,12 @@ def get_video_url_data(video_url, autoplay=False, loop=False, hide_controls=Fals if params: embed_url = f'{embed_url}?{url_encode(params)}' - return {'platform': platform, 'embed_url': embed_url} + return { + 'platform': platform, + 'embed_url': embed_url, + 'video_id': video_id, + 'params': params + } def get_video_embed_code(video_url):