Skip to content

Commit

Permalink
Merge branch 'MDL-78903-402' of https://github.com/meirzamoodle/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_402_STABLE
  • Loading branch information
HuongNV13 committed Nov 2, 2023
2 parents f4e322a + 90408b2 commit 467a6be
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 68 deletions.
4 changes: 2 additions & 2 deletions lib/editor/tiny/plugins/h5p/amd/build/ui.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/editor/tiny/plugins/h5p/amd/build/ui.min.js.map

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions lib/editor/tiny/plugins/h5p/amd/src/ui.js
Expand Up @@ -32,6 +32,7 @@ import Modal from 'tiny_h5p/modal';
import ModalEvents from 'core/modal_events';
import ModalFactory from 'core/modal_factory';
import Pending from 'core/pending';
import {getFilePicker} from 'editor_tiny/options';

let openingSelection = null;

Expand All @@ -50,7 +51,8 @@ export const handleAction = (editor) => {
const getTemplateContext = (editor, data) => {
const permissions = getPermissions(editor);

const canUpload = permissions.upload ?? false;
const canShowFilePicker = typeof getFilePicker(editor, 'h5p') !== 'undefined';
const canUpload = (permissions.upload && canShowFilePicker) ?? false;
const canEmbed = permissions.embed ?? false;
const canUploadAndEmbed = canUpload && canEmbed;

Expand All @@ -69,29 +71,28 @@ const getTemplateContext = (editor, data) => {
*
* @param {FormNode} form
* @param {string} submittedUrl
* @param {object} permissions
* @returns {URL|null}
*/
const getUrlFromSubmission = (form, submittedUrl, permissions) => {
const getUrlFromSubmission = (form, submittedUrl) => {
if (!submittedUrl || (!submittedUrl.startsWith(Config.wwwroot) && !isValidUrl(submittedUrl))) {
return null;
}

// Generate a URL Object for the submitted URL.
const url = new URL(submittedUrl);

if (permissions?.upload) {
if (form.querySelector('[name="download"]').checked) {
url.searchParams.append('export', 1);
}
const downloadElement = form.querySelector('[name="download"]');
if (downloadElement?.checked) {
url.searchParams.append('export', 1);
}

if (permissions?.embed) {
if (form.querySelector('[name="embed"]').checked) {
url.searchParams.append('embed', 1);
}
const embedElement = form.querySelector('[name="embed"]');
if (embedElement?.checked) {
url.searchParams.append('embed', 1);
}
if (form.querySelector('[name="copyright"]').checked) {

const copyrightElement = form.querySelector('[name="copyright"]');
if (copyrightElement?.checked) {
url.searchParams.append('copyright', 1);
}

Expand Down Expand Up @@ -128,7 +129,7 @@ const handleDialogueSubmission = async(editor, modal, data) => {

// Get the URL from the submitted form.
const submittedUrl = form.querySelector('input[name="url"]').value;
const url = getUrlFromSubmission(form, submittedUrl, getPermissions(editor));
const url = getUrlFromSubmission(form, submittedUrl);

if (!url) {
// The URL is invalid.
Expand Down

0 comments on commit 467a6be

Please sign in to comment.