Commit 1aef97f126c9abc4df05ebef838c80c2f1eccf81
Committed by
Antonio Terceiro
1 parent
074bf280
Exists in
master
and in
29 other branches
Fix Block display options to work with subdirectories
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: André Bernardes <andrebsguedes@gmail.com> Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Showing
2 changed files
with
25 additions
and
8 deletions
Show diff stats
app/models/block.rb
@@ -75,7 +75,7 @@ class Block < ActiveRecord::Base | @@ -75,7 +75,7 @@ class Block < ActiveRecord::Base | ||
75 | if context[:article] | 75 | if context[:article] |
76 | return context[:article] == owner.home_page | 76 | return context[:article] == owner.home_page |
77 | else | 77 | else |
78 | - return context[:request_path] == '/' | 78 | + return home_page_path?(context[:request_path]) |
79 | end | 79 | end |
80 | end | 80 | end |
81 | 81 | ||
@@ -83,7 +83,7 @@ class Block < ActiveRecord::Base | @@ -83,7 +83,7 @@ class Block < ActiveRecord::Base | ||
83 | if context[:article] | 83 | if context[:article] |
84 | return context[:article] != owner.home_page | 84 | return context[:article] != owner.home_page |
85 | else | 85 | else |
86 | - return context[:request_path] != '/' + (owner.kind_of?(Profile) ? owner.identifier : '') | 86 | + return !home_page_path?(context[:request_path]) |
87 | end | 87 | end |
88 | end | 88 | end |
89 | 89 | ||
@@ -114,7 +114,7 @@ class Block < ActiveRecord::Base | @@ -114,7 +114,7 @@ class Block < ActiveRecord::Base | ||
114 | # blocks to choose one to include in the design. | 114 | # blocks to choose one to include in the design. |
115 | # | 115 | # |
116 | # Must be redefined in subclasses to match the description of each block | 116 | # Must be redefined in subclasses to match the description of each block |
117 | - # type. | 117 | + # type. |
118 | def self.description | 118 | def self.description |
119 | '(dummy)' | 119 | '(dummy)' |
120 | end | 120 | end |
@@ -124,13 +124,13 @@ class Block < ActiveRecord::Base | @@ -124,13 +124,13 @@ class Block < ActiveRecord::Base | ||
124 | # This method can return several types of objects: | 124 | # This method can return several types of objects: |
125 | # | 125 | # |
126 | # * <tt>String</tt>: if the string starts with <tt>http://</tt> or <tt>https://</tt>, then it is assumed to be address of an IFRAME. Otherwise it's is used as regular HTML. | 126 | # * <tt>String</tt>: if the string starts with <tt>http://</tt> or <tt>https://</tt>, then it is assumed to be address of an IFRAME. Otherwise it's is used as regular HTML. |
127 | - # * <tt>Hash</tt>: the hash is used to build an URL that is used as the address for a IFRAME. | 127 | + # * <tt>Hash</tt>: the hash is used to build an URL that is used as the address for a IFRAME. |
128 | # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The | 128 | # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The |
129 | # block can then use <tt>render</tt>, <tt>link_to</tt>, etc. | 129 | # block can then use <tt>render</tt>, <tt>link_to</tt>, etc. |
130 | # | 130 | # |
131 | # The method can also return <tt>nil</tt>, which means "no content". | 131 | # The method can also return <tt>nil</tt>, which means "no content". |
132 | # | 132 | # |
133 | - # See BoxesHelper#extract_block_content for implementation details. | 133 | + # See BoxesHelper#extract_block_content for implementation details. |
134 | def content(args={}) | 134 | def content(args={}) |
135 | "This is block number %d" % self.id | 135 | "This is block number %d" % self.id |
136 | end | 136 | end |
@@ -239,4 +239,21 @@ class Block < ActiveRecord::Base | @@ -239,4 +239,21 @@ class Block < ActiveRecord::Base | ||
239 | self.position = block.position | 239 | self.position = block.position |
240 | end | 240 | end |
241 | 241 | ||
242 | + private | ||
243 | + | ||
244 | + def home_page_path | ||
245 | + home_page_url = Noosfero.root('/') | ||
246 | + | ||
247 | + if owner.kind_of?(Profile) | ||
248 | + home_page_url += "profile/" if owner.home_page.nil? | ||
249 | + home_page_url += owner.identifier | ||
250 | + end | ||
251 | + | ||
252 | + return home_page_url | ||
253 | + end | ||
254 | + | ||
255 | + def home_page_path? path | ||
256 | + return path == home_page_path || path == (home_page_path + '/') | ||
257 | + end | ||
258 | + | ||
242 | end | 259 | end |
test/unit/block_test.rb
@@ -6,7 +6,7 @@ class BlockTest < ActiveSupport::TestCase | @@ -6,7 +6,7 @@ class BlockTest < ActiveSupport::TestCase | ||
6 | should 'describe itself' do | 6 | should 'describe itself' do |
7 | assert_kind_of String, Block.description | 7 | assert_kind_of String, Block.description |
8 | end | 8 | end |
9 | - | 9 | + |
10 | should 'access owner through box' do | 10 | should 'access owner through box' do |
11 | user = create_user('testinguser').person | 11 | user = create_user('testinguser').person |
12 | 12 | ||
@@ -82,7 +82,7 @@ class BlockTest < ActiveSupport::TestCase | @@ -82,7 +82,7 @@ class BlockTest < ActiveSupport::TestCase | ||
82 | should 'be able to be displayed only in the homepage (index) of the environment' do | 82 | should 'be able to be displayed only in the homepage (index) of the environment' do |
83 | block = build(Block, :display => 'home_page_only') | 83 | block = build(Block, :display => 'home_page_only') |
84 | 84 | ||
85 | - assert_equal true, block.visible?(:article => nil, :request_path => '/') | 85 | + assert_equal true, block.visible?(:article => nil, :request_path => "#{Noosfero.root('/')}") |
86 | assert_equal false, block.visible?(:article => nil) | 86 | assert_equal false, block.visible?(:article => nil) |
87 | end | 87 | end |
88 | 88 | ||
@@ -102,7 +102,7 @@ class BlockTest < ActiveSupport::TestCase | @@ -102,7 +102,7 @@ class BlockTest < ActiveSupport::TestCase | ||
102 | block = build(Block, :display => 'except_home_page') | 102 | block = build(Block, :display => 'except_home_page') |
103 | block.stubs(:owner).returns(profile) | 103 | block.stubs(:owner).returns(profile) |
104 | 104 | ||
105 | - assert_equal false, block.visible?(:article => nil, :request_path => '/testinguser') | 105 | + assert_equal false, block.visible?(:article => nil, :request_path => "#{Noosfero.root('/')}profile/testinguser") |
106 | assert_equal true, block.visible?(:article => nil) | 106 | assert_equal true, block.visible?(:article => nil) |
107 | end | 107 | end |
108 | 108 |