Commit 5b9b6c8f467daa30db79447b40785bdbf7308022

Authored by Joenio Costa
1 parent 3f54dc4f

New kind of article RawHTMLArticle

(ActionItem2056)
app/controllers/my_profile/cms_controller.rb
@@ -52,6 +52,9 @@ class CmsController < MyProfileController @@ -52,6 +52,9 @@ class CmsController < MyProfileController
52 if @parent && @parent.blog? 52 if @parent && @parent.blog?
53 articles -= Article.folder_types.map(&:constantize) 53 articles -= Article.folder_types.map(&:constantize)
54 end 54 end
  55 + if user.is_admin?(profile.environment)
  56 + articles << RawHTMLArticle
  57 + end
55 articles 58 articles
56 end 59 end
57 60
app/models/raw_html_article.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class RawHTMLArticle < TextArticle
  2 +
  3 + def self.short_description
  4 + _('Raw HTML text article.')
  5 + end
  6 +
  7 + def self.description
  8 + _('Allows HTML without filter (only for admins)')
  9 + end
  10 +
  11 + xss_terminate :only => [ ]
  12 +
  13 +end
app/views/cms/_raw_html_article.rhtml 0 → 100644
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +<%= required_fields_message %>
  2 +
  3 +<%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>
  4 +
  5 +<%= render :partial => 'translatable' %>
  6 +<%= render :partial => 'shared/lead_and_body' %>
test/functional/cms_controller_test.rb
@@ -1618,4 +1618,11 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -1618,4 +1618,11 @@ class CmsControllerTest &lt; Test::Unit::TestCase
1618 end 1618 end
1619 end 1619 end
1620 1620
  1621 + should 'make RawHTMLArticle available only to environment admins' do
  1622 + @controller.stubs(:profile).returns(profile)
  1623 + assert_not_includes @controller.available_article_types, RawHTMLArticle
  1624 + profile.environment.add_admin(profile)
  1625 + assert_includes @controller.available_article_types, RawHTMLArticle
  1626 + end
  1627 +
1621 end 1628 end
test/unit/raw_html_article_test.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class RawHTMLArticleTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = create_user('testing').person
  7 + end
  8 +
  9 + should 'not filter HTML' do
  10 + article = RawHTMLArticle.create!(
  11 + :name => 'Raw HTML',
  12 + :body => '<strong>HTML!</strong><form action="#"></form>',
  13 + :profile => @profile
  14 + )
  15 + assert_equal '<strong>HTML!</strong><form action="#"></form>', article.body
  16 + end
  17 +
  18 +end