enable/disable plugins by config option

This commit is contained in:
wvengen 2014-04-05 18:47:16 +02:00
parent 6d98be6d22
commit 64bb8e043d
21 changed files with 65 additions and 15 deletions

View file

@ -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

View file

@ -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\" <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:

View file

@ -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:

View file

@ -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:

View file

@ -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).

View file

@ -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)

View file

@ -1,2 +1,3 @@
/ insert_after 'erb:contains("delete")'
- if FoodsoftMessages.enabled?
= link_to t('.send_message'), new_message_path(:message => {:group_id => @ordergroup.id}), class: 'btn'

View file

@ -1,2 +1,3 @@
/ insert_after 'erb:contains("delete")'
- if FoodsoftMessages.enabled?
= link_to t('.send_message'), new_message_path(:message => {:mail_to => @user.id}), class: 'btn'

View file

@ -1,2 +1,3 @@
/ insert_after 'erb:contains("delete")'
- if FoodsoftMessages.enabled?
= link_to_new_message(message_params: {group_id: @workgroup.id})

View file

@ -1,2 +1,3 @@
/ insert_bottom 'tbody tr'
- if FoodsoftMessages.enabled?
%td= link_to_new_message(message_params: {group_id: ordergroup.id})

View file

@ -1,2 +1,3 @@
/ insert_bottom 'tbody tr'
- if FoodsoftMessages.enabled?
%td= link_to_new_message(message_params: {mail_to: user.id})

View file

@ -1,2 +1,3 @@
/ insert_after 'erb:contains("tasks")'
- if FoodsoftMessages.enabled?
= link_to_new_message message_params: {group_id: workgroup.id}

View file

@ -1,2 +1,3 @@
/ insert_after 'erb:contains("tasks")'
- if FoodsoftMessages.enabled?
%li= link_to t('.write_message'), new_message_path

View file

@ -1,4 +1,5 @@
/ insert_after 'erb[silent]:contains("<dashboard_middle_mark>")'
- if FoodsoftMessages.enabled?
- unless Message.public.empty?
%section#messages
%h2= t '.messages.title'

View file

@ -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

View file

@ -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 <<

View file

@ -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),

View file

@ -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).

View file

@ -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

View file

@ -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

View file

@ -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