diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 119e2b922..d3afeeea1 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -50,7 +50,7 @@ class AdminController < ApplicationController end def plugins - @plugins = Redmine::Plugin.registered_plugins.values.sort + @plugins = Redmine::Plugin.all end # Loads the default configuration diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 7f9c9d5cc..99f7bcf08 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -45,14 +45,15 @@ class SettingsController < ApplicationController end def plugin - plugin_id = params[:id].to_sym - @plugin = Redmine::Plugin.registered_plugins[plugin_id] + @plugin = Redmine::Plugin.find(params[:id]) if request.post? - Setting["plugin_#{plugin_id}"] = params[:settings] + Setting["plugin_#{@plugin.id}"] = params[:settings] flash[:notice] = l(:notice_successful_update) - redirect_to :action => 'plugin', :id => params[:id] + redirect_to :action => 'plugin', :id => @plugin.id end @partial = @plugin.settings[:partial] - @settings = Setting["plugin_#{plugin_id}"] + @settings = Setting["plugin_#{@plugin.id}"] + rescue Redmine::PluginNotFound + render_404 end end diff --git a/app/models/setting.rb b/app/models/setting.rb index 072afa0db..187347d64 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -75,9 +75,9 @@ class Setting < ActiveRecord::Base cattr_accessor :available_settings @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml")) - Redmine::Plugin.registered_plugins.each do |id, plugin| + Redmine::Plugin.all.each do |plugin| next unless plugin.settings - @@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true} + @@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true} end validates_uniqueness_of :name diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 17953ef8c..80c638b28 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -17,6 +17,8 @@ module Redmine #:nodoc: + class PluginNotFound < StandardError; end + # Base class for Redmine plugins. # Plugins are registered using the register class method that acts as the public constructor. # @@ -62,7 +64,17 @@ module Redmine #:nodoc: def self.register(id, &block) p = new(id) p.instance_eval(&block) - Plugin.registered_plugins[id] = p + registered_plugins[id] = p + end + + # Returns an array off all registered plugins + def self.all + registered_plugins.values.sort + end + + # Finds a plugin by its id + def self.find(id) + registered_plugins[id.to_sym] || raise(PluginNotFound) end def initialize(id)