From 5b9b6c8f467daa30db79447b40785bdbf7308022 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Mon, 8 Aug 2011 14:49:44 -0300 Subject: [PATCH] New kind of article RawHTMLArticle --- app/controllers/my_profile/cms_controller.rb | 3 +++ app/models/raw_html_article.rb | 13 +++++++++++++ app/views/cms/_raw_html_article.rhtml | 6 ++++++ test/functional/cms_controller_test.rb | 7 +++++++ test/unit/raw_html_article_test.rb | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 0 deletions(-) create mode 100644 app/models/raw_html_article.rb create mode 100644 app/views/cms/_raw_html_article.rhtml create mode 100644 test/unit/raw_html_article_test.rb diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index a7bfcf2..00a2c1d 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -52,6 +52,9 @@ class CmsController < MyProfileController if @parent && @parent.blog? articles -= Article.folder_types.map(&:constantize) end + if user.is_admin?(profile.environment) + articles << RawHTMLArticle + end articles end diff --git a/app/models/raw_html_article.rb b/app/models/raw_html_article.rb new file mode 100644 index 0000000..7da3671 --- /dev/null +++ b/app/models/raw_html_article.rb @@ -0,0 +1,13 @@ +class RawHTMLArticle < TextArticle + + def self.short_description + _('Raw HTML text article.') + end + + def self.description + _('Allows HTML without filter (only for admins)') + end + + xss_terminate :only => [ ] + +end diff --git a/app/views/cms/_raw_html_article.rhtml b/app/views/cms/_raw_html_article.rhtml new file mode 100644 index 0000000..07d81f0 --- /dev/null +++ b/app/views/cms/_raw_html_article.rhtml @@ -0,0 +1,6 @@ +<%= required_fields_message %> + +<%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> + +<%= render :partial => 'translatable' %> +<%= render :partial => 'shared/lead_and_body' %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 850bf8b..5c23a39 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1618,4 +1618,11 @@ class CmsControllerTest < Test::Unit::TestCase end end + should 'make RawHTMLArticle available only to environment admins' do + @controller.stubs(:profile).returns(profile) + assert_not_includes @controller.available_article_types, RawHTMLArticle + profile.environment.add_admin(profile) + assert_includes @controller.available_article_types, RawHTMLArticle + end + end diff --git a/test/unit/raw_html_article_test.rb b/test/unit/raw_html_article_test.rb new file mode 100644 index 0000000..577e544 --- /dev/null +++ b/test/unit/raw_html_article_test.rb @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class RawHTMLArticleTest < ActiveSupport::TestCase + + def setup + @profile = create_user('testing').person + end + + should 'not filter HTML' do + article = RawHTMLArticle.create!( + :name => 'Raw HTML', + :body => 'HTML!
', + :profile => @profile + ) + assert_equal 'HTML!
', article.body + end + +end -- libgit2 0.21.2