[Git][noosfero/noosfero][master] 2 commits: Allow article types to define when media panel should be displayed
Victor Costa
gitlab at gitlab.com
Fri Aug 21 16:25:02 BRT 2015
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
16b6f59f by Victor Costa at 2015-08-21T15:58:04Z
Allow article types to define when media panel should be displayed
- - - - -
950a0708 by Victor Costa at 2015-08-21T19:24:44Z
Merge branch 'article_display_media_panel' into 'master'
Allow article types to define when media panel should be displayed
See merge request !633
- - - - -
11 changed files:
- app/models/article.rb
- app/models/enterprise_homepage.rb
- app/models/event.rb
- app/models/textile_article.rb
- app/models/tiny_mce_article.rb
- app/views/cms/edit.html.erb
- test/unit/article_test.rb
- test/unit/enterprise_homepage_test.rb
- test/unit/event_test.rb
- test/unit/textile_article_test.rb
- test/unit/tiny_mce_article_test.rb
Changes:
=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -635,6 +635,14 @@ class Article < ActiveRecord::Base
can_display_hits? && display_hits
end
+ def display_media_panel?
+ can_display_media_panel? && environment.enabled?('media_panel')
+ end
+
+ def can_display_media_panel?
+ false
+ end
+
def image?
false
end
=====================================
app/models/enterprise_homepage.rb
=====================================
--- a/app/models/enterprise_homepage.rb
+++ b/app/models/enterprise_homepage.rb
@@ -35,4 +35,8 @@ class EnterpriseHomepage < Article
false
end
+ def can_display_media_panel?
+ true
+ end
+
end
=====================================
app/models/event.rb
=====================================
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -134,6 +134,10 @@ class Event < Article
true
end
+ def can_display_media_panel?
+ true
+ end
+
include Noosfero::TranslatableContent
include MaybeAddHttp
=====================================
app/models/textile_article.rb
=====================================
--- a/app/models/textile_article.rb
+++ b/app/models/textile_article.rb
@@ -24,6 +24,10 @@ class TextileArticle < TextArticle
true
end
+ def can_display_media_panel?
+ true
+ end
+
protected
def convert_to_html(textile)
=====================================
app/models/tiny_mce_article.rb
=====================================
--- a/app/models/tiny_mce_article.rb
+++ b/app/models/tiny_mce_article.rb
@@ -28,4 +28,8 @@ class TinyMceArticle < TextArticle
true
end
+ def can_display_media_panel?
+ true
+ end
+
end
=====================================
app/views/cms/edit.html.erb
=====================================
--- a/app/views/cms/edit.html.erb
+++ b/app/views/cms/edit.html.erb
@@ -1,8 +1,6 @@
<%= error_messages_for 'article' %>
-<% show_media_panel = environment.enabled?('media_panel') && [TinyMceArticle, TextileArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %>
-
-<div class='<%= (show_media_panel ? 'with_media_panel' : 'no_media_panel') %>'>
+<div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'>
<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
<%= hidden_field_tag("type", @type) if @type %>
@@ -68,7 +66,7 @@
<% end %>
</div>
-<% if show_media_panel %>
+<% if @article.display_media_panel? %>
<%= render :partial => 'text_editor_sidebar' %>
<% end %>
=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -2191,4 +2191,27 @@ class ArticleTest < ActiveSupport::TestCase
article.destroy
end
+ should 'have can_display_media_panel with default false' do
+ a = Article.new
+ assert !a.can_display_media_panel?
+ end
+
+ should 'display media panel when allowed by the environment' do
+ a = Article.new
+ a.expects(:can_display_media_panel?).returns(true)
+ environment = mock
+ a.expects(:environment).returns(environment)
+ environment.expects(:enabled?).with('media_panel').returns(true)
+ assert a.display_media_panel?
+ end
+
+ should 'not display media panel when not allowed by the environment' do
+ a = Article.new
+ a.expects(:can_display_media_panel?).returns(true)
+ environment = mock
+ a.expects(:environment).returns(environment)
+ environment.expects(:enabled?).with('media_panel').returns(false)
+ assert !a.display_media_panel?
+ end
+
end
=====================================
test/unit/enterprise_homepage_test.rb
=====================================
--- a/test/unit/enterprise_homepage_test.rb
+++ b/test/unit/enterprise_homepage_test.rb
@@ -26,4 +26,9 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase
assert_equal false, a.can_display_hits?
end
+ should 'have can_display_media_panel with default true' do
+ a = EnterpriseHomepage.new
+ assert a.can_display_media_panel?
+ end
+
end
=====================================
test/unit/event_test.rb
=====================================
--- a/test/unit/event_test.rb
+++ b/test/unit/event_test.rb
@@ -346,4 +346,9 @@ class EventTest < ActiveSupport::TestCase
assert event.translatable?
end
+ should 'have can_display_media_panel with default true' do
+ a = Event.new
+ assert a.can_display_media_panel?
+ end
+
end
=====================================
test/unit/textile_article_test.rb
=====================================
--- a/test/unit/textile_article_test.rb
+++ b/test/unit/textile_article_test.rb
@@ -174,6 +174,11 @@ class TextileArticleTest < ActiveSupport::TestCase
assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html
end
+ should 'have can_display_media_panel with default true' do
+ a = TextileArticle.new
+ assert a.can_display_media_panel?
+ end
+
protected
def build_article(input = nil, options = {})
=====================================
test/unit/tiny_mce_article_test.rb
=====================================
--- a/test/unit/tiny_mce_article_test.rb
+++ b/test/unit/tiny_mce_article_test.rb
@@ -235,4 +235,9 @@ end
:attributes => { :colspan => 2, :rowspan => 3 }
end
+ should 'have can_display_media_panel with default true' do
+ a = TinyMceArticle.new
+ assert a.can_display_media_panel?
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/03e838f138fcd04e08ff22d9e2863f1a24e72203...950a07082d85808991b63c99f0c30386af945a86
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150821/5f78f77a/attachment-0001.html>
More information about the Noosfero-dev
mailing list