Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When resolveuid in link, refuse to save if protocol is not <other> #90

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/collective/ckeditor/browser/ckeditorview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
46 changes: 42 additions & 4 deletions src/collective/ckeditor/browser/statics/ckeditor_plone.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ jQuery(document).on('after-render.plone-modal.patterns', launchCKInstances);
(function() {

var format = function format(msg) {
return '<p>Actual URL</p><p>'+msg+'</p>';
var ploneLang = editor.lang.plone;
return '<p>'+ploneLang.actual_url+'</p><p>'+msg+'</p>';
};

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 = {
Expand All @@ -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);
Expand All @@ -141,6 +143,27 @@ jQuery(document).on('after-render.plone-modal.patterns', launchCKInstances);
domElement.setHtml('<p></p>');
};

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 "<other>".',
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 "<autre>".',
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 "<ander>" 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.
Expand Down Expand Up @@ -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
Expand Down
Loading