diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb
index 8045453..7741bbe 100644
--- a/app/helpers/boxes_helper.rb
+++ b/app/helpers/boxes_helper.rb
@@ -65,7 +65,7 @@ module BoxesHelper
end
def display_box_content(box, main_content)
- context = { :article => @page, :request_path => request.path, :locale => locale, :params => request.params }
+ context = { :article => @page, :request_path => request.path, :locale => locale, :params => request.params, :user => user }
box_decorator.select_blocks(box.blocks.includes(:box), context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box)
end
diff --git a/app/models/block.rb b/app/models/block.rb
index 1d51c1c..81991f0 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -22,11 +22,13 @@ class Block < ActiveRecord::Base
#
# * :article: the article being viewed currently
# * :language: in which language the block will be displayed
+ # * :user: the logged user
def visible?(context = nil)
return false if display == 'never'
if context
return false if language != 'all' && language != context[:locale]
+ return false unless display_to_user?(context[:user])
begin
return self.send("display_#{display}", context)
@@ -38,6 +40,10 @@ class Block < ActiveRecord::Base
true
end
+ def display_to_user?(user)
+ display_user == 'all' || (user.nil? && display_user == 'not_logged') || (user && display_user == 'logged')
+ end
+
def display_always(context)
true
end
@@ -68,6 +74,14 @@ class Block < ActiveRecord::Base
# the homepage of its owner.
settings_items :display, :type => :string, :default => 'always'
+
+ # The condition for displaying a block to users. It can assume the following values:
+ #
+ # * 'all': the block is always displayed
+ # * 'logged': the block is displayed to logged users only
+ # * 'not_logged': the block is displayed only to not logged users
+ settings_items :display_user, :type => :string, :default => 'all'
+
# The block can be configured to be displayed in all languages or in just one language. It can assume any locale of the environment:
#
# * 'all': the block is always displayed
@@ -179,6 +193,14 @@ class Block < ActiveRecord::Base
DISPLAY_OPTIONS[option]
end
+ def display_user_options
+ @display_user_options ||= {
+ 'all' => __('All users'),
+ 'logged' => __('Logged'),
+ 'not_logged' => __('Not logged'),
+ }
+ end
+
def duplicate
duplicated_block = self.clone
duplicated_block.display = 'never'
diff --git a/app/views/box_organizer/edit.rhtml b/app/views/box_organizer/edit.rhtml
index 4916980..530de37 100644
--- a/app/views/box_organizer/edit.rhtml
+++ b/app/views/box_organizer/edit.rhtml
@@ -15,6 +15,10 @@
<% end %>
+