From 725bfbac65d9023183919b26fdcadb72647701fe Mon Sep 17 00:00:00 2001 From: Godefroid Chapelle Date: Thu, 14 Dec 2023 17:26:02 +0100 Subject: [PATCH] can't save resolveuid link if protocol is not other --- docs/HISTORY.txt | 3 ++ .../ckeditor/browser/ckeditorview.py | 2 +- .../browser/statics/ckeditor_plone.js | 46 +++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 494036ca..b7442ccb 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -4,6 +4,9 @@ Changelog 5.0.0b4 (unreleased) -------------------- +- Add validation for "other" as link protocol when "resolveuid" + [gotcha] + - Set "other" as default link protocol, to lessen the chances that https://resolveuid/xxxxx are setup with plonefinder. [gotcha] diff --git a/src/collective/ckeditor/browser/ckeditorview.py b/src/collective/ckeditor/browser/ckeditorview.py index ebdea6be..9a5b10ab 100644 --- a/src/collective/ckeditor/browser/ckeditorview.py +++ b/src/collective/ckeditor/browser/ckeditorview.py @@ -380,7 +380,7 @@ def getCK_plone_config(self): config.%s = %s; """ % (k, v) - ids = [] + ids = ['plone'] for line in get_registry_value('plugins', []): # ignore the rest so we get no error if len(line.split(';')) == 2: diff --git a/src/collective/ckeditor/browser/statics/ckeditor_plone.js b/src/collective/ckeditor/browser/statics/ckeditor_plone.js index 1da71b28..c1059202 100644 --- a/src/collective/ckeditor/browser/statics/ckeditor_plone.js +++ b/src/collective/ckeditor/browser/statics/ckeditor_plone.js @@ -113,12 +113,14 @@ jQuery(document).on('after-render.plone-modal.patterns', launchCKInstances); (function() { var format = function format(msg) { - return '

Actual URL

'+msg+'

'; + var ploneLang = editor.lang.plone; + return '

'+ploneLang.actual_url+'

'+msg+'

'; }; var showActualUrl = function showActualUrl(domElement, url) { + var ploneLang = editor.lang.plone; if (url.indexOf('resolveuid') !== -1) { - domElement.setHtml(format('Loading...')); + domElement.setHtml(format(ploneLang.loading)); var current_uid = url.split('resolveuid/')[1]; var new_url = CKEDITOR_PLONE_PORTALPATH + '/convert_uid_to_url/' + current_uid; var settings = { @@ -128,11 +130,11 @@ jQuery(document).on('after-render.plone-modal.patterns', launchCKInstances); if (jqXHR.status == 200) { domElement.setHtml(format(data)); } else { - domElement.setHtml(format('Could not be resolved.')); + domElement.setHtml(format(ploneLang.could_not_be_resolved)); } }, error: function(jqXHR, textStatus){ - domElement.setHtml(format('Could not be resolved.')); + domElement.setHtml(format(ploneLang.could_not_be_resolved)); } }; $.ajax(settings); @@ -141,6 +143,27 @@ jQuery(document).on('after-render.plone-modal.patterns', launchCKInstances); domElement.setHtml('

'); }; +CKEDITOR.plugins.add('plone', {name: 'plone', path: 'plone'}); +CKEDITOR.plugins.setLang('plone', 'en', { + invalid_ruid_protocol: 'When using internal link that contains "resolveuid", the value of the "Protocol" field needs to be "".', + actual_url: 'Actual URL', + loading: 'Loading...', + could_not_be_resolved: 'Could not be resolved.', +}); +CKEDITOR.plugins.setLang('plone', 'fr', { + invalid_ruid_protocol: 'Quand vous utilisez un lien interne qui contient "resolveuid", la valeur du champs "Protocole" doit être "".', + actual_url: 'URL finale', + loading: 'En cours...', + could_not_be_resolved: "Ne peut être déterminée.", +}); +CKEDITOR.plugins.setLang('plone', 'nl', { + invalid_ruid_protocol: 'Als je een interne link met "resolveuid" erin gebruikt, moet het "Protocol" veld "" zijn.', + actual_url: 'Feitelijke URL', + loading: 'Laden...', + could_not_be_resolved: "Kan niet berekend worden.", +}); + + CKEDITOR.on( 'dialogDefinition', function( ev ) { // Take the dialog name and its definition from the event // data. @@ -177,6 +200,21 @@ CKEDITOR.on( 'dialogDefinition', function( ev ) { showActualUrl(domElement, url); default_onKeyUp.apply(this); }; + + var default_validate = url.validate; + url.validate = function() { + var ploneLang = editor.lang.plone; + if ( this.getValue().includes('resolveuid') ) { + var dialog = this.getDialog(); + var protocol = dialog.getValueOf('info', 'protocol'); + console.log("protocol: " + protocol); + if ( protocol != '') { + alert( ploneLang.invalid_ruid_protocol ); + return false; + } + } + return default_validate.apply(this); + }; } // Check if the definition is from the dialog we're