summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-09-23 17:19:27 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-09-23 17:19:27 +0000
commite4f0864e3a7f17f0e8a282aad29202f53bf11139 (patch)
treea40440471a6b0a8bc8aedf9d89d8bf2ef27e918f
parenta42a115b8fa21ab506cd40765a9e5684f022451b (diff)
downloadredmine-e4f0864e3a7f17f0e8a282aad29202f53bf11139.tar.gz
redmine-e4f0864e3a7f17f0e8a282aad29202f53bf11139.zip
Basic plugin support.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@752 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/admin_controller.rb3
-rw-r--r--app/controllers/settings_controller.rb12
-rw-r--r--app/models/setting.rb6
-rw-r--r--app/views/admin/info.rhtml16
-rw-r--r--app/views/settings/plugin.rhtml8
-rw-r--r--config/environment.rb4
-rw-r--r--lib/redmine.rb1
-rw-r--r--lib/redmine/plugin.rb124
-rw-r--r--lib/tasks/migrate_plugins.rake15
-rw-r--r--public/images/22x22/plugin.pngbin0 -> 1338 bytes
-rw-r--r--public/stylesheets/application.css1
-rw-r--r--vendor/plugins/gloc-1.1.0/lib/gloc-internal.rb2
12 files changed, 189 insertions, 3 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index ccc107507..bceab361c 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 229a4ab3c..09af63176 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 d661eed75..1c953f4c8 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 59b1c3f26..d84d2ad32 100644
--- a/app/views/admin/info.rhtml
+++ b/app/views/admin/info.rhtml
@@ -7,3 +7,19 @@
<tr class="even"><td>File repository writable</td><td><%= image_tag (@flags[:file_repository_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
<tr class="odd"><td>RMagick available</td><td><%= image_tag (@flags[:rmagick_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
</table>
+
+<% if @plugins.any? %>
+&nbsp;
+<h3 class="icon22 icon22-plugin">Plugins</h3>
+<table class="list">
+ <% @plugins.keys.sort.each do |plugin| %>
+ <tr class="<%= cycle('odd', 'even') %>">
+ <td><%=h @plugins[plugin].name %></td>
+ <td><%=h @plugins[plugin].description %></td>
+ <td><%=h @plugins[plugin].author %></td>
+ <td><%=h @plugins[plugin].version %></td>
+ <td><%= link_to('Configure', :controller => 'settings', :action => 'plugin', :id => plugin.to_s) if @plugins[plugin].configurable? %></td>
+ </tr>
+ <% end %>
+</table>
+<% end %>
diff --git a/app/views/settings/plugin.rhtml b/app/views/settings/plugin.rhtml
new file mode 100644
index 000000000..6f4eb2b70
--- /dev/null
+++ b/app/views/settings/plugin.rhtml
@@ -0,0 +1,8 @@
+<h2><%= l(:label_settings) %>: <%=h @plugin.name %></h2>
+
+<% form_tag({:action => 'plugin'}) do %>
+<div class="box tabular">
+<%= render :partial => @partial, :locals => {:settings => @settings}%>
+</div>
+<%= submit_tag l(:button_apply) %>
+<% end %>
diff --git a/config/environment.rb b/config/environment.rb
index 7782e6ad6..a6c5149ed 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 3ec774928..d14f886c2 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 000000000..e6047974e
--- /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 <tt>register</tt> 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:
+ # * <tt>:default</tt>: default value for the plugin settings
+ # * <tt>:partial</tt>: path of the configuration partial view, relative to the plugin <tt>app/views</tt> directory
+ # Example:
+ # settings :default => {'foo'=>'bar'}, :partial => 'settings/settings'
+ # In this example, the settings partial will be found here in the plugin directory: <tt>app/views/settings/_settings.rhtml</tt>.
+ #
+ # 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 000000000..61df9c3f0
--- /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 000000000..455fa6a80
--- /dev/null
+++ b/public/images/22x22/plugin.png
Binary files differ
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 5cbc89ab0..92797c0fc 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -446,3 +446,4 @@ vertical-align: middle;
.icon22-comment { background-image: url(../images/22x22/comment.png); }
.icon22-package { background-image: url(../images/22x22/package.png); }
.icon22-settings { background-image: url(../images/22x22/settings.png); }
+.icon22-plugin { background-image: url(../images/22x22/plugin.png); }
diff --git a/vendor/plugins/gloc-1.1.0/lib/gloc-internal.rb b/vendor/plugins/gloc-1.1.0/lib/gloc-internal.rb
index f16e90555..faed551ca 100644
--- a/vendor/plugins/gloc-1.1.0/lib/gloc-internal.rb
+++ b/vendor/plugins/gloc-1.1.0/lib/gloc-internal.rb
@@ -73,7 +73,7 @@ module GLoc
end
def _get_lang_file_list(dir) #:nodoc:
- dir= File.join(RAILS_ROOT,'lang') if dir.nil?
+ dir= File.join(RAILS_ROOT,'{.,vendor/plugins/*}','lang') if dir.nil?
Dir[File.join(dir,'*.{yaml,yml}')]
end