Skip to content

Commit

Permalink
enable/disable plugins by config option
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Apr 5, 2014
1 parent 0ee3c52 commit 17b4832
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 15 deletions.
13 changes: 13 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def authenticate_or_token(prefix, role = 'any')
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
Expand Down
10 changes: 8 additions & 2 deletions config/app_config.yml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -86,8 +92,8 @@ default: &defaults
notification:
error_recipients:
- admin@foodcoop.test
sender_address: "\"FoodSoft Error\" <foodsoft@foodcoop.test>"
email_prefix: "[FoodSoft]"
sender_address: "\"Foodsoft Error\" <foodsoft@foodcoop.test>"
email_prefix: "[Foodsoft]"

# Access to sharedLists, the external article-database
shared_lists:
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions lib/foodsoft_messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 2 additions & 0 deletions lib/foodsoft_messages/app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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})
Original file line number Diff line number Diff line change
@@ -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})
Original file line number Diff line number Diff line change
@@ -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})
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/ insert_after 'erb[silent]:contains("<dashboard_middle_mark>")'
- 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
5 changes: 5 additions & 0 deletions lib/foodsoft_messages/lib/foodsoft_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
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
1 change: 1 addition & 0 deletions lib/foodsoft_messages/lib/foodsoft_messages/engine.rb
Original file line number Diff line number Diff line change
@@ -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 <<
Expand Down
2 changes: 1 addition & 1 deletion lib/foodsoft_messages/lib/foodsoft_messages/user_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.included(base) # :nodoc:

# 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),
Expand Down
3 changes: 3 additions & 0 deletions lib/foodsoft_wiki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
1 change: 1 addition & 0 deletions lib/foodsoft_wiki/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/foodsoft_wiki/lib/foodsoft_wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
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
1 change: 1 addition & 0 deletions lib/foodsoft_wiki/lib/foodsoft_wiki/engine.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 17b4832

Please sign in to comment.