diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index ccc1075..bceab36 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -74,6 +74,7 @@ class AdminController < ApplicationController :default_admin_changed => User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?, :file_repository_writable => File.writable?(Attachment.storage_path), :rmagick_available => Object.const_defined?(:Magick) - } + } + @plugins = Redmine::Plugin.registered_plugins end end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 229a4ab..09af631 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -30,4 +30,16 @@ class SettingsController < ApplicationController redirect_to :action => 'edit' and return end end + + def plugin + plugin_id = params[:id].to_sym + @plugin = Redmine::Plugin.registered_plugins[plugin_id] + if request.post? + Setting["plugin_#{plugin_id}"] = params[:settings] + flash[:notice] = l(:notice_successful_update) + redirect_to :action => 'plugin', :id => params[:id] + end + @partial = "../../vendor/plugins/#{plugin_id}/app/views/" + @plugin.settings[:partial] + @settings = Setting["plugin_#{plugin_id}"] + end end diff --git a/app/models/setting.rb b/app/models/setting.rb index d661eed..1c953f4 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -19,7 +19,11 @@ 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| + next unless plugin.settings + @@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true} + end + validates_uniqueness_of :name validates_inclusion_of :name, :in => @@available_settings.keys validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' } diff --git a/app/views/admin/info.rhtml b/app/views/admin/info.rhtml index 59b1c3f..d84d2ad 100644 --- a/app/views/admin/info.rhtml +++ b/app/views/admin/info.rhtml @@ -7,3 +7,19 @@ File repository writable<%= image_tag (@flags[:file_repository_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %> RMagick available<%= image_tag (@flags[:rmagick_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %> + +<% if @plugins.any? %> +  +

Plugins

+ + <% @plugins.keys.sort.each do |plugin| %> + + + + + + + + <% end %> +
<%=h @plugins[plugin].name %><%=h @plugins[plugin].description %><%=h @plugins[plugin].author %><%=h @plugins[plugin].version %><%= link_to('Configure', :controller => 'settings', :action => 'plugin', :id => plugin.to_s) if @plugins[plugin].configurable? %>
+<% end %> diff --git a/app/views/settings/plugin.rhtml b/app/views/settings/plugin.rhtml new file mode 100644 index 0000000..6f4eb2b --- /dev/null +++ b/app/views/settings/plugin.rhtml @@ -0,0 +1,8 @@ +

<%= l(:label_settings) %>: <%=h @plugin.name %>

+ +<% form_tag({:action => 'plugin'}) do %> +
+<%= render :partial => @partial, :locals => {:settings => @settings}%> +
+<%= submit_tag l(:button_apply) %> +<% end %> diff --git a/config/environment.rb b/config/environment.rb index 7782e6a..a6c5149 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -58,6 +58,10 @@ Rails::Initializer.run do |config| # ActionMailer::Base.deliveries array. #config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :smtp + + # Uncomment this line if the engines plugin is installed. + # This will ensure that engines is loaded first. + # config.plugins = ["engines", "*"] end ActiveRecord::Errors.default_error_messages = { diff --git a/lib/redmine.rb b/lib/redmine.rb index 3ec7749..d14f886 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -3,6 +3,7 @@ require 'redmine/menu_manager' require 'redmine/mime_type' require 'redmine/acts_as_watchable/init' require 'redmine/acts_as_event/init' +require 'redmine/plugin' begin require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick) diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb new file mode 100644 index 0000000..e604797 --- /dev/null +++ b/lib/redmine/plugin.rb @@ -0,0 +1,124 @@ +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module Redmine #:nodoc: + + # Base class for Redmine plugins. + # Plugins are registered using the register class method that acts as the public constructor. + # + # Redmine::Plugin.register :example do + # name 'Example plugin' + # author 'John Smith' + # description 'This is an example plugin for Redmine' + # version '0.0.1' + # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings' + # end + # + # === Plugin attributes + # + # +settings+ is an optional attribute that let the plugin be configurable. + # It must be a hash with the following keys: + # * :default: default value for the plugin settings + # * :partial: path of the configuration partial view, relative to the plugin app/views directory + # Example: + # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings' + # In this example, the settings partial will be found here in the plugin directory: app/views/settings/_settings.rhtml. + # + # When rendered, the plugin settings value is available as the local variable +settings+ + class Plugin + @registered_plugins = {} + class << self + attr_reader :registered_plugins + private :new + + def def_field(*names) + class_eval do + names.each do |name| + define_method(name) do |*args| + args.empty? ? instance_variable_get("@#{name}") : instance_variable_set("@#{name}", *args) + end + end + end + end + end + def_field :name, :description, :author, :version, :settings + + # Plugin constructor + def self.register(name, &block) + p = new + p.instance_eval(&block) + Plugin.registered_plugins[name] = p + end + + # Adds an item to the given +menu+. + # The +id+ parameter (equals to the project id) is automatically added to the url. + # menu :project_menu, :label_plugin_example, :controller => 'example', :action => 'say_hello' + # + # Currently, only the project menu can be extended. Thus, the +name+ parameter must be +:project_menu+ + def menu(name, label, url) + Redmine::MenuManager.map(name) {|menu| menu.push label, url} + end + + # Defines a permission called +name+ for the given +actions+. + # + # The +actions+ argument is a hash with controllers as keys and actions as values (a single value or an array): + # permission :destroy_contacts, { :contacts => :destroy } + # permission :view_contacts, { :contacts => [:index, :show] } + # + # The +options+ argument can be used to make the permission public (implicitly given to any user) + # or to restrict users the permission can be given to. + # + # Examples + # # A permission that is implicitly given to any user + # # This permission won't appear on the Roles & Permissions setup screen + # permission :say_hello, { :example => :say_hello }, :public => true + # + # # A permission that can be given to any user + # permission :say_hello, { :example => :say_hello } + # + # # A permission that can be given to registered users only + # permission :say_hello, { :example => :say_hello }, :require => loggedin + # + # # A permission that can be given to project members only + # permission :say_hello, { :example => :say_hello }, :require => member + def permission(name, actions, options = {}) + if @project_module + Redmine::AccessControl.map {|map| map.project_module(@project_module) {|map|map.permission(name, actions, options)}} + else + Redmine::AccessControl.map {|map| map.permission(name, actions, options)} + end + end + + # Defines a project module, that can be enabled/disabled for each project. + # Permissions defined inside +block+ will be bind to the module. + # + # project_module :things do + # permission :view_contacts, { :contacts => [:list, :show] }, :public => true + # permission :destroy_contacts, { :contacts => :destroy } + # end + def project_module(name, &block) + @project_module = name + self.instance_eval(&block) + @project_module = nil + end + + # Returns +true+ if the plugin can be configured. + def configurable? + settings && settings.is_a?(Hash) && !settings[:partial].blank? + end + end +end diff --git a/lib/tasks/migrate_plugins.rake b/lib/tasks/migrate_plugins.rake new file mode 100644 index 0000000..61df9c3 --- /dev/null +++ b/lib/tasks/migrate_plugins.rake @@ -0,0 +1,15 @@ +namespace :db do + desc 'Migrates installed plugins.' + task :migrate_plugins => :environment do + if Rails.respond_to?('plugins') + Rails.plugins.each do |plugin| + next unless plugin.respond_to?('migrate') + puts "Migrating #{plugin.name}..." + plugin.migrate + end + else + puts "Undefined method plugins for Rails!" + puts "Make sure engines plugin is installed." + end + end +end diff --git a/public/images/22x22/plugin.png b/public/images/22x22/plugin.png new file mode 100644 index 0000000000000000000000000000000000000000..455fa6a80e64876635321ca740420eb037ebaa41 GIT binary patch literal 1338 zc$@(`1;zS_P)z^Q>-8KIssI20AY({UO#lFGm;eBCjs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