From 64bb8e043db4538259799cb1a6ba338908c38df9 Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 5 Apr 2014 18:47:16 +0200 Subject: [PATCH] enable/disable plugins by config option --- app/controllers/application_controller.rb | 13 +++++++++++++ config/app_config.yml.SAMPLE | 10 ++++++++-- config/locales/en.yml | 1 + config/locales/nl.yml | 1 + lib/foodsoft_messages/README.md | 3 +++ .../app/controllers/messages_controller.rb | 2 ++ .../ordergroups/show/new_message.html.haml.deface | 3 ++- .../admin/users/show/new_message.html.haml.deface | 3 ++- .../workgroups/show/new_message.html.haml.deface | 3 ++- .../_ordergroups/new_message.html.haml.deface | 3 ++- .../users/_users/new_message.html.haml.deface | 3 ++- .../_workgroup/new_message.html.haml.deface | 3 ++- .../home/_start_nav/new_message.html.haml.deface | 3 ++- .../latest_public_messages_index.html.haml.deface | 11 ++++++----- lib/foodsoft_messages/lib/foodsoft_messages.rb | 5 +++++ .../lib/foodsoft_messages/engine.rb | 1 + .../lib/foodsoft_messages/user_link.rb | 2 +- lib/foodsoft_wiki/README.md | 3 +++ .../app/controllers/pages_controller.rb | 1 + lib/foodsoft_wiki/lib/foodsoft_wiki.rb | 5 +++++ lib/foodsoft_wiki/lib/foodsoft_wiki/engine.rb | 1 + 21 files changed, 65 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9130c61b..3574ef44 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -104,6 +104,19 @@ class ApplicationController < ActionController::Base end end + # Many plugins can be turned on and off on the fly with a `use_` configuration option. + # To disable a controller in the plugin, you can use this as a `before_action`: + # + # class MypluginController < ApplicationController + # before_filter -> { require_plugin_enabled FoodsoftMyplugin } + # end + # + def require_plugin_enabled(plugin) + unless plugin.enabled? + redirect_to root_path, alert: I18n.t('application.controller.error_plugin_disabled') + end + end + # Redirect to the login page, used in authenticate, plugins can override this. def redirect_to_login(options={}) redirect_to login_url, options diff --git a/config/app_config.yml.SAMPLE b/config/app_config.yml.SAMPLE index b3dc7db8..8a205605 100644 --- a/config/app_config.yml.SAMPLE +++ b/config/app_config.yml.SAMPLE @@ -67,6 +67,12 @@ default: &defaults # Members of a user's groups and administrators can still see full names. use_nick: false + # Most plugins can be enabled/disabled here as well. Messages and wiki are enabled + # by default and need to be set to false to disable. Most other plugins needs to + # be enabled before they do anything. + #use_wiki: true + #use_messages: true + # Base font size for generated PDF documents #pdf_font_size: 12 # Page size for generated PDF documents @@ -86,8 +92,8 @@ default: &defaults notification: error_recipients: - admin@foodcoop.test - sender_address: "\"FoodSoft Error\" " - email_prefix: "[FoodSoft]" + sender_address: "\"Foodsoft Error\" " + email_prefix: "[Foodsoft]" # Access to sharedLists, the external article-database shared_lists: diff --git a/config/locales/en.yml b/config/locales/en.yml index 88a099f9..afb7916f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -288,6 +288,7 @@ en: error_denied: You are not allowed to view the requested page. If you think you should, ask an administrator to give you appropriate permissions. If you have access to multiple user accounts, you might want to %{sign_in}. error_denied_sign_in: sign in as another user error_members_only: This action is only available to members of the group! + error_plugin_disabled: This feature is currently disabled. error_token: Access denied (invalid token)! article_categories: create: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 631bc01b..72068ac1 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -286,6 +286,7 @@ nl: error_denied: Je hebt geen toegang tot de gevraagde pagina. Als je denkt dat je dat wel zou moeten hebben, vraag dan een beheerder je die rechten te geven. Als je meerdere accounts hebt, wil je mogelijk %{sign_in}. error_denied_sign_in: inloggen als een andere gebruiker error_members_only: Deze actie is alleen beschikbaar voor leden van de groep! + error_plugin_disabled: Deze actie is momenteel uitgeschakeld. error_token: Geen toegang (ongeldig token)! article_categories: create: diff --git a/lib/foodsoft_messages/README.md b/lib/foodsoft_messages/README.md index cff05a32..4af6235f 100644 --- a/lib/foodsoft_messages/README.md +++ b/lib/foodsoft_messages/README.md @@ -11,5 +11,8 @@ add the following to foodsoft's Gemfile: gem 'foodsoft_messages', path: 'lib/foodsoft_messages' ``` +This plugin introduces the foodcoop config option `use_messages`, which can be +set to `false` to disable messages. May be useful in multicoop deployments. + This plugin is part of the foodsoft package and uses the GPL-3 license (see foodsoft's LICENSE for the full license text). diff --git a/lib/foodsoft_messages/app/controllers/messages_controller.rb b/lib/foodsoft_messages/app/controllers/messages_controller.rb index 11cc5a44..e993afc7 100644 --- a/lib/foodsoft_messages/app/controllers/messages_controller.rb +++ b/lib/foodsoft_messages/app/controllers/messages_controller.rb @@ -1,5 +1,7 @@ class MessagesController < ApplicationController + before_filter -> { require_plugin_enabled FoodsoftMessages } + # Renders the "inbox" action. def index @messages = Message.public.page(params[:page]).per(@per_page).order('created_at DESC').includes(:sender) diff --git a/lib/foodsoft_messages/app/overrides/admin/ordergroups/show/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/admin/ordergroups/show/new_message.html.haml.deface index b8b107c0..d2cd5021 100644 --- a/lib/foodsoft_messages/app/overrides/admin/ordergroups/show/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/admin/ordergroups/show/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_after 'erb:contains("delete")' -= link_to t('.send_message'), new_message_path(:message => {:group_id => @ordergroup.id}), class: 'btn' +- if FoodsoftMessages.enabled? + = link_to t('.send_message'), new_message_path(:message => {:group_id => @ordergroup.id}), class: 'btn' diff --git a/lib/foodsoft_messages/app/overrides/admin/users/show/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/admin/users/show/new_message.html.haml.deface index bac3dace..2881ac71 100644 --- a/lib/foodsoft_messages/app/overrides/admin/users/show/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/admin/users/show/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_after 'erb:contains("delete")' -= link_to t('.send_message'), new_message_path(:message => {:mail_to => @user.id}), class: 'btn' +- if FoodsoftMessages.enabled? + = link_to t('.send_message'), new_message_path(:message => {:mail_to => @user.id}), class: 'btn' diff --git a/lib/foodsoft_messages/app/overrides/admin/workgroups/show/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/admin/workgroups/show/new_message.html.haml.deface index 8b0f14fa..4ee2fe2b 100644 --- a/lib/foodsoft_messages/app/overrides/admin/workgroups/show/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/admin/workgroups/show/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_after 'erb:contains("delete")' -= link_to_new_message(message_params: {group_id: @workgroup.id}) +- if FoodsoftMessages.enabled? + = link_to_new_message(message_params: {group_id: @workgroup.id}) diff --git a/lib/foodsoft_messages/app/overrides/foodcoop/ordergroups/_ordergroups/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/foodcoop/ordergroups/_ordergroups/new_message.html.haml.deface index cd99357f..6796c23f 100644 --- a/lib/foodsoft_messages/app/overrides/foodcoop/ordergroups/_ordergroups/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/foodcoop/ordergroups/_ordergroups/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_bottom 'tbody tr' -%td= link_to_new_message(message_params: {group_id: ordergroup.id}) +- if FoodsoftMessages.enabled? + %td= link_to_new_message(message_params: {group_id: ordergroup.id}) diff --git a/lib/foodsoft_messages/app/overrides/foodcoop/users/_users/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/foodcoop/users/_users/new_message.html.haml.deface index 0a11ff7f..a8b60473 100644 --- a/lib/foodsoft_messages/app/overrides/foodcoop/users/_users/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/foodcoop/users/_users/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_bottom 'tbody tr' -%td= link_to_new_message(message_params: {mail_to: user.id}) +- if FoodsoftMessages.enabled? + %td= link_to_new_message(message_params: {mail_to: user.id}) diff --git a/lib/foodsoft_messages/app/overrides/foodcoop/workgroups/_workgroup/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/foodcoop/workgroups/_workgroup/new_message.html.haml.deface index 4fe6ad66..1426e522 100644 --- a/lib/foodsoft_messages/app/overrides/foodcoop/workgroups/_workgroup/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/foodcoop/workgroups/_workgroup/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_after 'erb:contains("tasks")' -= link_to_new_message message_params: {group_id: workgroup.id} +- if FoodsoftMessages.enabled? + = link_to_new_message message_params: {group_id: workgroup.id} diff --git a/lib/foodsoft_messages/app/overrides/home/_start_nav/new_message.html.haml.deface b/lib/foodsoft_messages/app/overrides/home/_start_nav/new_message.html.haml.deface index e6437404..6e3ad213 100644 --- a/lib/foodsoft_messages/app/overrides/home/_start_nav/new_message.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/home/_start_nav/new_message.html.haml.deface @@ -1,2 +1,3 @@ / insert_after 'erb:contains("tasks")' -%li= link_to t('.write_message'), new_message_path +- if FoodsoftMessages.enabled? + %li= link_to t('.write_message'), new_message_path diff --git a/lib/foodsoft_messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface b/lib/foodsoft_messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface index dd4ab82b..d4e1db1c 100644 --- a/lib/foodsoft_messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface +++ b/lib/foodsoft_messages/app/overrides/home/index/latest_public_messages_index.html.haml.deface @@ -1,6 +1,7 @@ / insert_after 'erb[silent]:contains("")' -- unless Message.public.empty? - %section#messages - %h2= t '.messages.title' - = render 'messages/messages', messages: Message.public.order('created_at DESC').limit(5), pagination: false - %p= link_to t('.messages.view_all'), messages_path +- if FoodsoftMessages.enabled? + - unless Message.public.empty? + %section#messages + %h2= t '.messages.title' + = render 'messages/messages', messages: Message.public.order('created_at DESC').limit(5), pagination: false + %p= link_to t('.messages.view_all'), messages_path diff --git a/lib/foodsoft_messages/lib/foodsoft_messages.rb b/lib/foodsoft_messages/lib/foodsoft_messages.rb index 09baaa8a..9cc7c4a6 100644 --- a/lib/foodsoft_messages/lib/foodsoft_messages.rb +++ b/lib/foodsoft_messages/lib/foodsoft_messages.rb @@ -3,4 +3,9 @@ require "foodsoft_messages/user_link" require "deface" module FoodsoftMessages + # Return whether messages are used or not. + # Enabled by default since it used to be part of the foodsoft core. + def self.enabled? + FoodsoftConfig[:use_messages] != false + end end diff --git a/lib/foodsoft_messages/lib/foodsoft_messages/engine.rb b/lib/foodsoft_messages/lib/foodsoft_messages/engine.rb index 19eae5ad..38b8b4ff 100644 --- a/lib/foodsoft_messages/lib/foodsoft_messages/engine.rb +++ b/lib/foodsoft_messages/lib/foodsoft_messages/engine.rb @@ -1,6 +1,7 @@ module FoodsoftMessages class Engine < ::Rails::Engine def navigation(primary, context) + return unless FoodsoftMessages.enabled? return if primary[:foodcoop].nil? sub_nav = primary[:foodcoop].sub_navigation sub_nav.items << diff --git a/lib/foodsoft_messages/lib/foodsoft_messages/user_link.rb b/lib/foodsoft_messages/lib/foodsoft_messages/user_link.rb index bb2d05d2..2278ebf2 100644 --- a/lib/foodsoft_messages/lib/foodsoft_messages/user_link.rb +++ b/lib/foodsoft_messages/lib/foodsoft_messages/user_link.rb @@ -6,7 +6,7 @@ module FoodsoftMessages # modify user presentation link to writing a message for the user def show_user_link(user=@current_user) - if user.nil? + if user.nil? or not FoodsoftMessages.enabled? show_user user else link_to show_user(user), new_message_path('message[mail_to]' => user.id), diff --git a/lib/foodsoft_wiki/README.md b/lib/foodsoft_wiki/README.md index dcf2f18c..1f6b866d 100644 --- a/lib/foodsoft_wiki/README.md +++ b/lib/foodsoft_wiki/README.md @@ -14,5 +14,8 @@ gem 'acts_as_versioned', git: 'git://github.com/technoweenie/acts_as_versioned.g gem 'foodsoft_wiki', path: 'lib/foodsoft_wiki' ``` +This plugin introduces the foodcoop config option `use_wiki`, which can be set +to `false` to disable the wiki. May be useful in multicoop deployments. + This plugin is part of the foodsoft package and uses the GPL-3 license (see foodsoft's LICENSE for the full license text). diff --git a/lib/foodsoft_wiki/app/controllers/pages_controller.rb b/lib/foodsoft_wiki/app/controllers/pages_controller.rb index 39ca7c62..d8114e96 100644 --- a/lib/foodsoft_wiki/app/controllers/pages_controller.rb +++ b/lib/foodsoft_wiki/app/controllers/pages_controller.rb @@ -1,5 +1,6 @@ # encoding: utf-8 class PagesController < ApplicationController + before_filter -> { require_plugin_enabled FoodsoftWiki } skip_before_filter :authenticate, :only => :all before_filter :only => :all do diff --git a/lib/foodsoft_wiki/lib/foodsoft_wiki.rb b/lib/foodsoft_wiki/lib/foodsoft_wiki.rb index ddcb0f83..dc726e81 100644 --- a/lib/foodsoft_wiki/lib/foodsoft_wiki.rb +++ b/lib/foodsoft_wiki/lib/foodsoft_wiki.rb @@ -5,4 +5,9 @@ require 'content_for_in_controllers' require 'foodsoft_wiki/engine' module FoodsoftWiki + # Return whether the wiki is used or not. + # Enabled by default since it used to be part of the foodsoft core. + def self.enabled? + FoodsoftConfig[:use_wiki] != false + end end diff --git a/lib/foodsoft_wiki/lib/foodsoft_wiki/engine.rb b/lib/foodsoft_wiki/lib/foodsoft_wiki/engine.rb index 68f0ab7f..b56e617a 100644 --- a/lib/foodsoft_wiki/lib/foodsoft_wiki/engine.rb +++ b/lib/foodsoft_wiki/lib/foodsoft_wiki/engine.rb @@ -1,6 +1,7 @@ module FoodsoftWiki class Engine < ::Rails::Engine def navigation(primary, ctx) + return unless FoodsoftWiki.enabled? primary.item :wiki, I18n.t('navigation.wiki.title'), '#', id: nil do |subnav| subnav.item :wiki_home, I18n.t('navigation.wiki.home'), ctx.wiki_path, id: nil subnav.item :all_pages, I18n.t('navigation.wiki.all_pages'), ctx.all_pages_path, id: nil