diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index da2e9b7..31c8868 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -1,7 +1,13 @@ class EnvironmentDesignController < BoxOrganizerController - + protect 'edit_environment_design', :environment + def filtered_available_blocks(blocks=nil) + filtered_available_blocks = [] + blocks.each { |block| filtered_available_blocks << block if @environment.enabled_blocks.include?(block.name) } + filtered_available_blocks + end + def available_blocks # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from # the Noosfero core soon, see ActionItem3045 diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb index 8de1440..f69e13b 100644 --- a/app/controllers/admin/features_controller.rb +++ b/app/controllers/admin/features_controller.rb @@ -1,10 +1,39 @@ class FeaturesController < AdminController + protect 'edit_environment_features', :environment - + def index @features = Environment.available_features.sort_by{|k,v|v} end + def manage_blocks + @blocks = [ ArticleBlock, + TagsBlock, + RecentDocumentsBlock, + ProfileInfoBlock, + LinkListBlock, + MyNetworkBlock, + FeedReaderBlock, + ProfileImageBlock, + LocationBlock, + SlideshowBlock, + ProfileSearchBlock, + HighlightsBlock, + FriendsBlock, + FavoriteEnterprisesBlock, + CommunitiesBlock, + EnterprisesBlock, + MembersBlock, + DisabledEnterpriseMessageBlock, + ProductCategoriesBlock, + FeaturedProductsBlock, + FansBlock, + ProductsBlock ] + + @blocks += plugins.dispatch(:extra_blocks) + @blocks.sort_by! { |block| block.name } + end + post_only :update def update if @environment.update_attributes(params[:environment]) @@ -15,6 +44,16 @@ class FeaturesController < AdminController end end + post_only :update_blocks + def update_blocks + if @environment.update_attributes(params[:environment]) + session[:notice] = _('Blocks updated successfully.') + redirect_to :action => 'manage_blocks' + else + render :action => 'manage_blocks' + end + end + def manage_fields @person_fields = Person.fields @enterprise_fields = Enterprise.fields diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index eb13d5d..6ca6f67 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -68,8 +68,8 @@ class BoxOrganizerController < ApplicationController raise ArgumentError.new("Type %s is not allowed. Go away." % type) end else - @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1) - @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]) + @center_block_types = filtered_available_blocks((Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1)) + @side_block_types = filtered_available_blocks((Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3])) @boxes = boxes_holder.boxes.with_position render :action => 'add_block', :layout => false end diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 8fb5245..41952fb 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -3,7 +3,13 @@ class ProfileDesignController < BoxOrganizerController needs_profile protect 'edit_profile_design', :profile - + + def filtered_available_blocks(blocks=nil) + filtered_available_blocks = [] + blocks.each { |block| filtered_available_blocks << block if @environment.enabled_blocks.include?(block.name) } + filtered_available_blocks + end + def available_blocks blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] diff --git a/app/models/environment.rb b/app/models/environment.rb index 579dfa7..cdab09c 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -3,7 +3,7 @@ # domains. class Environment < ActiveRecord::Base - attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :enabled_blocks, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound has_many :users @@ -289,6 +289,8 @@ class Environment < ActiveRecord::Base settings_items :enabled_plugins, :type => Array, :default => [] + settings_items :enabled_blocks, :type => Array, :default => [] + settings_items :search_hints, :type => Hash, :default => {} # Set to return http forbidden to host not on the allow origin list bellow @@ -337,6 +339,10 @@ class Environment < ActiveRecord::Base enabled_plugins.include?(plugin.to_s) end + def block_enabled?(block) + enabled_blocks.include?(block.to_s) + end + # enables the features identified by features, which is expected to # be an Enumarable object containing the identifiers of the desired features. # Passing nil is the same as passing an empty Array. diff --git a/app/views/admin_panel/index.html.erb b/app/views/admin_panel/index.html.erb index 163a6a0..d7fcbbe 100644 --- a/app/views/admin_panel/index.html.erb +++ b/app/views/admin_panel/index.html.erb @@ -11,6 +11,7 @@
+<%= _('Here you can enable or disable blocks of your environment.') %> +
+ +<%= labelled_form_for(:environment, :url => {:action => 'update_blocks'}) do |f| %> + +<%= _('Block') %> | +<%= _('Description') %> | +<%= _('Enabled?') %> | +
---|---|---|
+ <%= _(block.name.humanize) %> + | ++ <%= _(block.description) %> + | ++ <%= check_box_tag "environment[enabled_blocks][]", block, @environment.block_enabled?(block) %> + | +