Merge pull request #3633 from chrisi51/autolink-settings

Added autolinking settings in admin backend - tbc
This commit is contained in:
Lauri Ojansivu 2021-03-05 20:52:13 +02:00 committed by GitHub
commit 0ccdbdcbe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 11 deletions

View file

@ -211,6 +211,10 @@ template(name='layoutSettings')
.title {{_ 'custom-top-left-corner-logo-height'}} .title {{_ 'custom-top-left-corner-logo-height'}}
.form-group .form-group
input.wekan-form-control#custom-top-left-corner-logo-height(type="text", placeholder="" value="{{currentSetting.customTopLeftCornerLogoHeight}}") input.wekan-form-control#custom-top-left-corner-logo-height(type="text", placeholder="" value="{{currentSetting.customTopLeftCornerLogoHeight}}")
li.layout-form
.title {{_ 'automatic-linked-url-schemes'}}
.form-group
textarea#automatic-linked-url-schemes.wekan-form-control= currentSetting.automaticLinkedUrlSchemes
li li
button.js-save-layout.primary {{_ 'save'}} button.js-save-layout.primary {{_ 'save'}}

View file

@ -176,6 +176,9 @@ BlazeComponent.extendComponent({
const textBelowCustomLoginLogo = $('#text-below-custom-login-logo') const textBelowCustomLoginLogo = $('#text-below-custom-login-logo')
.val() .val()
.trim(); .trim();
const automaticLinkedUrlSchemes = $('#automatic-linked-url-schemes')
.val()
.trim();
const customTopLeftCornerLogoImageUrl = $( const customTopLeftCornerLogoImageUrl = $(
'#custom-top-left-corner-logo-image-url', '#custom-top-left-corner-logo-image-url',
) )
@ -209,6 +212,7 @@ BlazeComponent.extendComponent({
customTopLeftCornerLogoHeight, customTopLeftCornerLogoHeight,
displayAuthenticationMethod, displayAuthenticationMethod,
defaultAuthenticationMethod, defaultAuthenticationMethod,
automaticLinkedUrlSchemes,
}, },
}); });
} catch (e) { } catch (e) {

View file

@ -532,6 +532,7 @@
"custom-login-logo-image-url": "Custom Login Logo Image URL", "custom-login-logo-image-url": "Custom Login Logo Image URL",
"custom-login-logo-link-url": "Custom Login Logo Link URL", "custom-login-logo-link-url": "Custom Login Logo Link URL",
"text-below-custom-login-logo": "Text below Custom Login Logo", "text-below-custom-login-logo": "Text below Custom Login Logo",
"automatic-linked-url-schemes": "Custom URL Schemes which should automatically be clickable. One URL Scheme per line",
"username": "Username", "username": "Username",
"import-usernames": "Import Usernames", "import-usernames": "Import Usernames",
"view-it": "View it", "view-it": "View it",

View file

@ -62,6 +62,10 @@ Settings.attachSchema(
type: String, type: String,
optional: true, optional: true,
}, },
automaticLinkedUrlSchemes: {
type: String,
optional: true,
},
customTopLeftCornerLogoImageUrl: { customTopLeftCornerLogoImageUrl: {
type: String, type: String,
optional: true, optional: true,

View file

@ -6,23 +6,40 @@ var Markdown = require('markdown-it')({
breaks: true, breaks: true,
}); });
// Static URL Scheme Listing
var urlschemes = [
"aodroplink",
"thunderlink",
"cbthunderlink",
"onenote",
"file",
"abasurl",
"conisio",
"mailspring"
];
// Better would be a field in the admin backend to set this dynamically
// instead of putting all known or wanted url schemes here hard into code
// but i was not able to access those settings
// var urlschemes = currentSetting.automaticLinkedUrlSchemes.split('\n');
// put all url schemes into the linkify configuration to automatically make it clickable
for(var i=0; i<urlschemes.length;i++){
//console.log("adding autolink for "+urlschemes[i]);
Markdown.linkify.add(urlschemes[i]+":",'http:');
}
// Additional safeAttrValue function to allow for other specific protocols // Additional safeAttrValue function to allow for other specific protocols
// See https://github.com/leizongmin/js-xss/issues/52#issuecomment-241354114 // See https://github.com/leizongmin/js-xss/issues/52#issuecomment-241354114
function mySafeAttrValue(tag, name, value, cssFilter) { function mySafeAttrValue(tag, name, value, cssFilter) {
// only when the tag is 'a' and attribute is 'href' // only when the tag is 'a' and attribute is 'href'
// then use your custom function // then use your custom function
if (tag === 'a' && name === 'href') { if (tag === 'a' && name === 'href') {
// only filter the value if starts with 'cbthunderlink:' or 'aodroplink' // only filter the value if starts with an registered url scheme
if (/^thunderlink:/ig.test(value) || urlscheme = value.split(/:\/\//);
/^cbthunderlink:/ig.test(value) || //console.log("validating "+urlscheme[0]);
/^aodroplink:/ig.test(value) || if(urlschemes.includes(urlscheme[0])) return value;
/^onenote:/ig.test(value) ||
/^file:/ig.test(value) ||
/^abasurl:/ig.test(value) ||
/^conisio:/ig.test(value) ||
/^mailspring:/ig.test(value)) {
return value;
}
else { else {
// use the default safeAttrValue function to process all non cbthunderlinks // use the default safeAttrValue function to process all non cbthunderlinks
return sanitizeXss.safeAttrValue(tag, name, value, cssFilter); return sanitizeXss.safeAttrValue(tag, name, value, cssFilter);

View file

@ -15,6 +15,7 @@ Meteor.publish('setting', () => {
customLoginLogoImageUrl: 1, customLoginLogoImageUrl: 1,
customLoginLogoLinkUrl: 1, customLoginLogoLinkUrl: 1,
textBelowCustomLoginLogo: 1, textBelowCustomLoginLogo: 1,
automaticLinkedUrlSchemes: 1,
customTopLeftCornerLogoImageUrl: 1, customTopLeftCornerLogoImageUrl: 1,
customTopLeftCornerLogoLinkUrl: 1, customTopLeftCornerLogoLinkUrl: 1,
customTopLeftCornerLogoHeight: 1, customTopLeftCornerLogoHeight: 1,