From d66e662492185f742bebd9ec95bfc6bf6379cd9a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 27 Sep 2018 14:07:48 +0200 Subject: [PATCH] Compile handlebars template for AuthTokenView Fixes #11032 For https://github.com/orgs/nextcloud/projects/18 Compile the default authtoken handlebars view. This avoids runtime compilations (speed) and avoids unsafe eval calls thus allowing a stricter CSP. Signed-off-by: Roeland Jago Douma --- settings/js/authtoken.handlebars | 26 ++++++++++++ settings/js/authtoken_view.js | 33 +-------------- settings/js/templates.js | 41 +++++++++++++++++++ .../templates/settings/personal/security.php | 1 + 4 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 settings/js/authtoken.handlebars create mode 100644 settings/js/templates.js diff --git a/settings/js/authtoken.handlebars b/settings/js/authtoken.handlebars new file mode 100644 index 0000000000..ab3405c889 --- /dev/null +++ b/settings/js/authtoken.handlebars @@ -0,0 +1,26 @@ + + +
+ + + {{name}} + + + {{lastActivity}} + + {{#if showMore}}{{/if}} + + + diff --git a/settings/js/authtoken_view.js b/settings/js/authtoken_view.js index 523d548f20..0ab5ebe2b6 100644 --- a/settings/js/authtoken_view.js +++ b/settings/js/authtoken_view.js @@ -25,44 +25,13 @@ OC.Settings = OC.Settings || {}; - var TEMPLATE_TOKEN = - '' - + '' - + '
' - + '' - + '' - + '{{name}}' - + '' - + '{{lastActivity}}' - + '' - + '{{#if showMore}}{{/if}}' - + '' - + '' - + ''; - var SubView = OC.Backbone.View.extend({ collection: null, _template: undefined, template: function (data) { - if (_.isUndefined(this._template)) { - this._template = Handlebars.compile(TEMPLATE_TOKEN); - } - - return this._template(data); + return OC.Settings.Templates['authtoken'](data); }, initialize: function (options) { diff --git a/settings/js/templates.js b/settings/js/templates.js new file mode 100644 index 0000000000..b45b788351 --- /dev/null +++ b/settings/js/templates.js @@ -0,0 +1,41 @@ +(function() { + var template = Handlebars.template, templates = OC.Settings.Templates = OC.Settings.Templates || {}; +templates['authtoken'] = template({"1":function(container,depth0,helpers,partials,data) { + return ""; +},"3":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=helpers.helperMissing, alias2="function", alias3=container.escapeExpression; + + return "
  • \n \n
    \n
  • \n"; +},"4":function(container,depth0,helpers,partials,data) { + return "checked"; +},"6":function(container,depth0,helpers,partials,data) { + return "
  • \n ' + t('settings', 'Revoke') +'\n
  • \n"; +},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { + var stack1, helper, alias1=helpers.helperMissing, alias2="function", alias3=container.escapeExpression; + + return "\n \n
    \n \n \n " + + alias3(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"name","hash":{},"data":data}) : helper))) + + "\n \n \n " + + alias3(((helper = (helper = helpers.lastActivity || (depth0 != null ? depth0.lastActivity : depth0)) != null ? helper : alias1),(typeof helper === alias2 ? helper.call(depth0,{"name":"lastActivity","hash":{},"data":data}) : helper))) + + "\n \n " + + ((stack1 = helpers["if"].call(depth0,(depth0 != null ? depth0.showMore : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n
    \n" + + ((stack1 = helpers["if"].call(depth0,(depth0 != null ? depth0.canScope : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(depth0,(depth0 != null ? depth0.canDelete : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
    \n \n\n"; +},"useData":true}); +})(); \ No newline at end of file diff --git a/settings/templates/settings/personal/security.php b/settings/templates/settings/personal/security.php index 253f20c0a2..6dd0e8d3ce 100644 --- a/settings/templates/settings/personal/security.php +++ b/settings/templates/settings/personal/security.php @@ -24,6 +24,7 @@ script('settings', [ 'authtoken', 'authtoken_collection', + 'templates', 'authtoken_view', 'settings/authtoken-init' ]);