Commit 932e054f28dea9e4dc84dffa2b57d8e0fac5703d
1 parent
ab8dc0f5
Exists in
staging
and in
42 other branches
Add support for base plugins
Base plugins are enanbed by default and cannot be disabled at the system level, but can be disabled per-environment at the web UI. A part of the required changes also fix the Noosfero plugin infrastructure, in special migrations, on Rails 3.
Showing
10 changed files
with
44 additions
and
31 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -286,7 +286,7 @@ class Environment < ActiveRecord::Base |
286 | 286 | www.youtube.com |
287 | 287 | ] + ('a' .. 'z').map{|i| "#{i}.yimg.com"} |
288 | 288 | |
289 | - settings_items :enabled_plugins, :type => Array, :default => [] | |
289 | + settings_items :enabled_plugins, :type => Array, :default => Noosfero::Plugin.available_plugin_names | |
290 | 290 | |
291 | 291 | settings_items :search_hints, :type => Hash, :default => {} |
292 | 292 | ... | ... |
config/plugins/people_block
debian/noosfero.install
lib/noosfero/plugin.rb
... | ... | @@ -104,7 +104,7 @@ class Noosfero::Plugin |
104 | 104 | |
105 | 105 | def available_plugins |
106 | 106 | unless @available_plugins |
107 | - path = File.join(Rails.root, 'config', 'plugins', '*') | |
107 | + path = File.join(Rails.root, '{baseplugins,config/plugins}', '*') | |
108 | 108 | @available_plugins = Dir.glob(path).select{ |i| File.directory?(i) } |
109 | 109 | if Rails.env.test? && !@available_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo')) |
110 | 110 | @available_plugins << File.join(Rails.root, 'plugins', 'foo') |
... | ... | @@ -113,6 +113,10 @@ class Noosfero::Plugin |
113 | 113 | @available_plugins |
114 | 114 | end |
115 | 115 | |
116 | + def available_plugin_names | |
117 | + available_plugins.map { |f| File.basename(f).camelize } | |
118 | + end | |
119 | + | |
116 | 120 | def all |
117 | 121 | @all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize } |
118 | 122 | end | ... | ... |
lib/tasks/plugins.rake
1 | 1 | require 'active_record' |
2 | 2 | #require_dependency 'active_record/migration' |
3 | 3 | |
4 | -class ActiveRecord::Migrator | |
5 | - alias_method :orig_initialize, :initialize | |
6 | - def initialize *args | |
7 | - orig_initialize *args | |
8 | - @migrations_paths = ["db/migrate", "config/plugins/*/db/migrate"] | |
9 | - end | |
10 | -end | |
11 | - | |
12 | 4 | namespace :noosfero do |
13 | 5 | namespace :plugins do |
14 | - plugin_migration_dirs = Dir.glob(Rails.root.join('config', 'plugins', '*', 'db', 'migrate')) | |
6 | + | |
7 | + plugin_migration_dirs = Dir.glob(Rails.root.join('{baseplugins,config/plugins}', '*', 'db', 'migrate')) | |
8 | + | |
9 | + task :load_config do | |
10 | + dirs = Dir.glob("{baseplugins,config/plugins}/*/db/migrate") | |
11 | + dirs.each do |dir| | |
12 | + ActiveRecord::Migrator.migrations_paths << dir | |
13 | + end | |
14 | + end | |
15 | + | |
15 | 16 | task :migrate do |
16 | 17 | plugin_migration_dirs.each do |path| |
17 | 18 | ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? |
... | ... | @@ -20,3 +21,6 @@ namespace :noosfero do |
20 | 21 | end |
21 | 22 | end |
22 | 23 | end |
24 | + | |
25 | +task 'db:migrate' => 'noosfero:plugins:load_config' | |
26 | +task 'db:schema:load' => 'noosfero:plugins:load_config' | ... | ... |
lib/tasks/plugins_tests.rake
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | @all_tasks = [:units, :functionals, :integration, :cucumber, :selenium] |
4 | 4 | |
5 | 5 | def enabled_plugins |
6 | - Dir.glob('config/plugins/*').map { |f| File.basename(f) } - ['README'] | |
6 | + Dir.glob('{baseplugins,config/plugins}/*').map { |f| File.basename(f) } - ['README'] | |
7 | 7 | end |
8 | 8 | |
9 | 9 | @original_enabled_plugins = enabled_plugins |
... | ... | @@ -51,7 +51,7 @@ def plugin_name(plugin) |
51 | 51 | end |
52 | 52 | |
53 | 53 | def plugin_enabled?(plugin) |
54 | - File.exist?(File.join('config', 'plugins', plugin)) | |
54 | + File.exist?(File.join('config', 'plugins', plugin)) || File.exist?(File.join('baseplugins', plugin)) | |
55 | 55 | end |
56 | 56 | |
57 | 57 | def plugin_disabled_warning(plugin) | ... | ... |
plugins/people_block/before_disable.rb
script/noosfero-plugins
... | ... | @@ -14,9 +14,10 @@ fi |
14 | 14 | # data |
15 | 15 | available_plugins_dir="$NOOSFERO_DIR/plugins" |
16 | 16 | enabled_plugins_dir="$NOOSFERO_DIR/config/plugins" |
17 | +base_plugins_dir="$NOOSFERO_DIR/baseplugins" | |
17 | 18 | available_plugins=$(find "$available_plugins_dir" -maxdepth 1 -mindepth 1 -type d -not -name 'template' -printf '%f\n' | sort) |
18 | 19 | enabled_plugins=$(find -L "$enabled_plugins_dir" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | sort) |
19 | -disabled_plugins=$(printf "%s\n" $available_plugins $enabled_plugins_dir | sort | uniq -u) | |
20 | +base_plugins=$(find -L "$base_plugins_dir" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | sort) | |
20 | 21 | |
21 | 22 | # operation defaults |
22 | 23 | quiet=false |
... | ... | @@ -32,7 +33,7 @@ _list() { |
32 | 33 | |
33 | 34 | _status() { |
34 | 35 | for plugin in $available_plugins; do |
35 | - if [ -h "$enabled_plugins_dir/$plugin" ]; then | |
36 | + if [ -h "$enabled_plugins_dir/$plugin" -o -h "$base_plugins_dir/$plugin" ]; then | |
36 | 37 | status="*" |
37 | 38 | else |
38 | 39 | status=" " |
... | ... | @@ -79,8 +80,9 @@ _enable(){ |
79 | 80 | cd $enabled_plugins_dir |
80 | 81 | source="../../plugins/$plugin" |
81 | 82 | target="$enabled_plugins_dir/$plugin" |
83 | + base="$base_plugins_dir/$plugin" | |
82 | 84 | run "$source/before_enable.rb" |
83 | - if [ -h "$target" ]; then | |
85 | + if [ -h "$target" -o -h "$base" ]; then | |
84 | 86 | _say "$plugin already enabled" |
85 | 87 | else |
86 | 88 | if [ ! -d "$source" ]; then |
... | ... | @@ -127,19 +129,20 @@ _disable(){ |
127 | 129 | target="$enabled_plugins_dir/$plugin" |
128 | 130 | plugins_public_dir="$NOOSFERO_DIR/public/plugins" |
129 | 131 | plugins_features_dir="$NOOSFERO_DIR/features/plugins" |
130 | - if ! run "$source/before_disable.rb"; then | |
131 | - echo "W: failed to disabling $plugin" | |
132 | - echo | |
132 | + | |
133 | + if [ -h "$base_plugins_dir/$plugin" ]; then | |
134 | + _say "$plugin is a base plugin and cannot be disabled" | |
135 | + return | |
136 | + fi | |
137 | + | |
138 | + if [ -h "$target" ]; then | |
139 | + rm "$target" | |
140 | + test -h "$plugins_public_dir/$plugin" && rm "$plugins_public_dir/$plugin" | |
141 | + test -h "$plugins_features_dir/$plugin" && rm "$plugins_features_dir/$plugin" | |
142 | + _say "$plugin disabled" | |
143 | + run "$source/after_disable.rb" | |
133 | 144 | else |
134 | - if [ -h "$target" ]; then | |
135 | - rm "$target" | |
136 | - test -h "$plugins_public_dir/$plugin" && rm "$plugins_public_dir/$plugin" | |
137 | - test -h "$plugins_features_dir/$plugin" && rm "$plugins_features_dir/$plugin" | |
138 | - _say "$plugin disabled" | |
139 | - run "$source/after_disable.rb" | |
140 | - else | |
141 | - _say "$plugin already disabled" | |
142 | - fi | |
145 | + _say "$plugin already disabled" | |
143 | 146 | fi |
144 | 147 | } |
145 | 148 | ... | ... |