diff --git a/.gitignore b/.gitignore index 7761dba2a..0413aaa36 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ public/sitemap.xml public/system/ +/public/ckeditor_assets/ diff --git a/app/assets/javascripts/ckeditor/config.js b/app/assets/javascripts/ckeditor/config.js index 8d6edd348..1ec099fc0 100644 --- a/app/assets/javascripts/ckeditor/config.js +++ b/app/assets/javascripts/ckeditor/config.js @@ -5,33 +5,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.editorConfig = function( config ) { - // Define changes to default configuration here. For example: - // config.language = 'fr'; - // config.uiColor = '#AADC6E'; - - /* Filebrowser routes */ - // The location of an external file browser, that should be launched when "Browse Server" button is pressed. config.filebrowserBrowseUrl = "/ckeditor/attachment_files"; - - // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog. config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files"; - - // The location of a script that handles file uploads in the Flash dialog. config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files"; - - // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog. config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures"; - - // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog. config.filebrowserImageBrowseUrl = "/ckeditor/pictures"; - - // The location of a script that handles file uploads in the Image dialog. config.filebrowserImageUploadUrl = "/ckeditor/pictures"; - - // The location of a script that handles file uploads. config.filebrowserUploadUrl = "/ckeditor/attachment_files"; config.allowedContent = true; + config.format_tags = "p;h2;h3"; // Rails CSRF token config.filebrowserParams = function(){ @@ -109,7 +92,14 @@ CKEDITOR.editorConfig = function( config ) config.toolbar_mini = [ { name: 'paragraph', groups: [ 'list' ], items: [ 'NumberedList', 'BulletedList' ] }, + { name: 'links', items: [ 'Link', 'Unlink' ] }, + { name: 'styles', items: [ 'Format' ] }, { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike' ] } ]; + + config.toolbar_admin = config.toolbar_mini.concat([ + { name: 'insert', items: [ 'Image' ] } + ]); + config.toolbar = "mini"; }; diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 40e951326..a761f7abc 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -79,6 +79,9 @@ module Abilities can :manage, SiteCustomization::Image can :manage, SiteCustomization::ContentBlock + can :access, :ckeditor + can :manage, Ckeditor::Picture + can [:manage], ::Legislation::Process can [:manage], ::Legislation::DraftVersion can [:manage], ::Legislation::Question diff --git a/app/models/ckeditor/asset.rb b/app/models/ckeditor/asset.rb new file mode 100644 index 000000000..cf636ed19 --- /dev/null +++ b/app/models/ckeditor/asset.rb @@ -0,0 +1,4 @@ +class Ckeditor::Asset < ActiveRecord::Base + include Ckeditor::Orm::ActiveRecord::AssetBase + include Ckeditor::Backend::Paperclip +end diff --git a/app/models/ckeditor/picture.rb b/app/models/ckeditor/picture.rb new file mode 100644 index 000000000..445c2bbd9 --- /dev/null +++ b/app/models/ckeditor/picture.rb @@ -0,0 +1,14 @@ +class Ckeditor::Picture < Ckeditor::Asset + has_attached_file :data, + url: '/ckeditor_assets/pictures/:id/:style_:basename.:extension', + path: ':rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension', + styles: { content: '800>', thumb: '118x100#' } + + validates_attachment_presence :data + validates_attachment_size :data, less_than: 2.megabytes + validates_attachment_content_type :data, content_type: /\Aimage/ + + def url_content + url(:content) + end +end diff --git a/app/views/admin/site_customization/pages/_form.html.erb b/app/views/admin/site_customization/pages/_form.html.erb index 88c2288b1..6d0416b6e 100644 --- a/app/views/admin/site_customization/pages/_form.html.erb +++ b/app/views/admin/site_customization/pages/_form.html.erb @@ -50,7 +50,8 @@
image'
+ expect(sanitizer.sanitize(html)).to eq(html)
+ end
+ end
+end
diff --git a/spec/lib/wysiwyg_sanitizer_spec.rb b/spec/lib/wysiwyg_sanitizer_spec.rb
index 17236aa03..e86c351ef 100644
--- a/spec/lib/wysiwyg_sanitizer_spec.rb
+++ b/spec/lib/wysiwyg_sanitizer_spec.rb
@@ -15,10 +15,25 @@ describe WYSIWYGSanitizer do
expect(subject.sanitize(html)).to eq(html)
end
+ it 'allows links' do
+ html = ''
+ expect(subject.sanitize(html)).to eq(html)
+ end
+
+ it 'allows headings' do
+ html = 'Fix flaky specs
This is
' expect(subject.sanitize(html)).to eq('This is alert("dangerous");
') end + + it 'filters images' do + html = 'Dangerous
image'
+ expect(subject.sanitize(html)).to eq('Dangerous image')
+ end
end
end
diff --git a/spec/models/budget/phase_spec.rb b/spec/models/budget/phase_spec.rb
index 1fe39c20f..34b99e26f 100644
--- a/spec/models/budget/phase_spec.rb
+++ b/spec/models/budget/phase_spec.rb
@@ -223,10 +223,10 @@ describe Budget::Phase do
end
describe "#sanitize_description" do
- it "removes html entities from the description" do
+ it "removes not allowed html entities from the description" do
expect{
- first_phase.update_attributes(description: "a