diff --git a/app/controllers/environment_admin/region_validators_controller.rb b/app/controllers/environment_admin/region_validators_controller.rb
new file mode 100644
index 0000000..7f47505
--- /dev/null
+++ b/app/controllers/environment_admin/region_validators_controller.rb
@@ -0,0 +1,38 @@
+class RegionValidatorsController < ApplicationController
+
+ before_filter :load_region_and_search, :except => 'index'
+
+ def index
+ @regions = Region.top_level_for(environment)
+ end
+
+ def region
+ # nothing to do, load_region_and_search already does everything needed here
+ end
+
+ def search
+ render :partial => 'search'
+ end
+
+ def add
+ validator = environment.organizations.find(params[:validator_id])
+ @region.validators << validator
+ redirect_to :action => 'region', :id => @region.id
+ end
+
+ def remove
+ validator = environment.organizations.find(params[:validator_id])
+ @region.validators.delete(validator)
+ redirect_to :action => 'region', :id => @region.id
+ end
+
+ protected
+
+ def load_region_and_search
+ @region = environment.regions.find(params[:id])
+ if params[:search]
+ @search = Organization.find_by_contents(params[:search])
+ end
+ end
+
+end
diff --git a/app/helpers/region_validators_helper.rb b/app/helpers/region_validators_helper.rb
new file mode 100644
index 0000000..f4810b7
--- /dev/null
+++ b/app/helpers/region_validators_helper.rb
@@ -0,0 +1,2 @@
+module RegionValidatorsHelper
+end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 4aa51bb..4374158 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -22,6 +22,8 @@ class Environment < ActiveRecord::Base
has_many :domains, :as => :owner
has_many :profiles
+ has_many :organizations
+
has_many :categories
has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color'
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 8546b09..ee8943c 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -18,6 +18,8 @@ class Profile < ActiveRecord::Base
acts_as_accessible
+ acts_as_ferret :fields => [ :name ]
+
# Valid identifiers must match this format.
IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/
diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml
index 34d0956..2030d51 100644
--- a/app/views/admin_panel/index.rhtml
+++ b/app/views/admin_panel/index.rhtml
@@ -7,4 +7,5 @@
<%= link_to _('Edit the Visual Design'), :controller => 'edit_template'%>
<%= link_to _('Manage Categories'), :controller => 'categories'%>
<%= link_to _('Manage User roles'), :controller => 'role' %>
+ <%= link_to _('Manage Validators by region'), :controller => 'region_validators' %>
diff --git a/app/views/region_validators/_region.rhtml b/app/views/region_validators/_region.rhtml
new file mode 100644
index 0000000..16ee9b7
--- /dev/null
+++ b/app/views/region_validators/_region.rhtml
@@ -0,0 +1,14 @@
+
+
+
+ <%= link_to region.name, :action => 'region', :id => region %>
+
<%= n_('1 validator', '%{num} validators.', region.validators.size) % { :num => region.validators.size } %>
+ <% unless region.children.empty? %>
+
+ <%= render :partial => 'region', :collection => region.children %>
+
+ <% end %>
+
+
+
+
diff --git a/app/views/region_validators/_search.rhtml b/app/views/region_validators/_search.rhtml
new file mode 100644
index 0000000..3ce1ec7
--- /dev/null
+++ b/app/views/region_validators/_search.rhtml
@@ -0,0 +1,13 @@
+<% if @search %>
+
+ <% for item in @search %>
+ -
+ <%= item.name %>
+ <% form_tag :action => 'add', :id => @region do %>
+ <%= hidden_field_tag :validator_id, item.id %>
+ <%= submit_tag _('Adicionar') %>
+ <% end %>
+
+ <% end %>
+
+<% end %>
diff --git a/app/views/region_validators/index.rhtml b/app/views/region_validators/index.rhtml
new file mode 100644
index 0000000..06a055a
--- /dev/null
+++ b/app/views/region_validators/index.rhtml
@@ -0,0 +1,5 @@
+<%= _('Validators by Region') %>
+
+
+ <%= render :partial => 'region', :collection => @regions %>
+
diff --git a/app/views/region_validators/region.rhtml b/app/views/region_validators/region.rhtml
new file mode 100644
index 0000000..dfeffd2
--- /dev/null
+++ b/app/views/region_validators/region.rhtml
@@ -0,0 +1,29 @@
+<%= _('Validators for region %s') % @region.name %>
+
+<%= _('Current validators') %>
+
+
+ <% for validator in @region.validators %>
+ -
+ <%= link_to_homepage validator.name, validator.identifier %>
+ <%= link_to _('Remove validation rights'), { :action => 'remove', :id => @region.id, :validator_id => validator }, :method => 'post' %>
+
+ <% end %>
+
+
+<%= _('Add new validators') %>
+
+
+<%= help _('First search organizations by their name, then use the buttons in the search result to add them as validators for this region. ') %>
+
+
+<% form_tag({}, { :method => 'get' }) do %>
+ <%= text_field_tag :search, nil, :id => 'search_validator' %>
+ <%= submit_tag _('Search') %>
+<% end %>
+
+<%= observe_field 'search_validator', :url => { :action => 'search', :id => @region.id }, :with => 'search', :frequency => 1, :update => 'search_results' %>
+
+
+ <%= render :partial => 'search' %>
+
diff --git a/db/migrate/003_create_profiles.rb b/db/migrate/003_create_profiles.rb
index c7080b1..2493f2a 100644
--- a/db/migrate/003_create_profiles.rb
+++ b/db/migrate/003_create_profiles.rb
@@ -5,9 +5,6 @@ class CreateProfiles < ActiveRecord::Migration
t.column :type, :string
t.column :identifier, :string
t.column :environment_id, :integer
- t.column :flexible_template_template, :string, :default => "default"
- t.column :flexible_template_theme, :string, :default => "default"
- t.column :flexible_template_icon_theme, :string, :default => "default"
t.column :active, :boolean, :default => false
t.column :address, :string
t.column :contact_phone, :string
diff --git a/db/migrate/019_create_region_validators_table.rb b/db/migrate/019_create_region_validators_table.rb
new file mode 100644
index 0000000..0f718a6
--- /dev/null
+++ b/db/migrate/019_create_region_validators_table.rb
@@ -0,0 +1,12 @@
+class CreateRegionValidatorsTable < ActiveRecord::Migration
+ def self.up
+ create_table :region_validators, :id => false do |t|
+ t.column :region_id, :integer
+ t.column :organization_id, :integer
+ end
+ end
+
+ def self.down
+ drop_table :region_validators
+ end
+end
diff --git a/test/functional/membership_editor_controller_test.rb b/test/functional/membership_editor_controller_test.rb
index cac5f65..baf6d65 100644
--- a/test/functional/membership_editor_controller_test.rb
+++ b/test/functional/membership_editor_controller_test.rb
@@ -19,7 +19,7 @@ class MembershipEditorControllerTest < Test::Unit::TestCase
assert_kind_of Array, assigns(:memberships)
end
- should 'propmt for new enterprise data' do
+ should 'prompt for new enterprise data' do
get :new_enterprise, :profile => 'ze'
assert assigns(:virtual_communities)
assert_kind_of Array, assigns(:virtual_communities)
diff --git a/test/functional/region_validators_controller_test.rb b/test/functional/region_validators_controller_test.rb
new file mode 100644
index 0000000..139d2cd
--- /dev/null
+++ b/test/functional/region_validators_controller_test.rb
@@ -0,0 +1,61 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'region_validators_controller'
+
+# Re-raise errors caught by the controller.
+class RegionValidatorsController; def rescue_action(e) raise e end; end
+
+class RegionValidatorsControllerTest < Test::Unit::TestCase
+ def setup
+ @controller = RegionValidatorsController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ # Replace this with your real tests.
+ should 'list regions at index' do
+ get :index
+ assert_response :success
+ assert_template 'index'
+ assert_kind_of Array, assigns(:regions)
+ end
+
+ should 'view validators for a specific region' do
+ environment = Environment.create!(:name => "my environment")
+ region = Region.new(:name => 'my region')
+ environment.regions << region
+ assert !region.new_record?
+
+ @controller.expects(:environment).returns(environment)
+
+ get :region, :id => region.id
+
+ assert_response :success
+ assert_template 'region'
+ assert_equal region, assigns(:region)
+ end
+
+ should 'search possible validators by name' do
+ environment = Environment.create!(:name => "my environment")
+ region = Region.new(:name => 'my region')
+ environment.regions << region
+ assert !region.new_record?
+ org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru')
+
+ @controller.expects(:environment).returns(environment)
+ Organization.expects(:find_by_contents).with('frufru').returns([org])
+
+ get :search, :id => region.id, :search => 'frufru'
+
+ assert_response :success
+ assert_equal [org], assigns(:search)
+ end
+
+ should 'be able to add validators to the current region' do
+ flunk 'need to write this test'
+ end
+
+ should 'be able to remove validators from the current region' do
+ flunk 'need to write this test'
+ end
+
+end
diff --git a/test/unit/region_test.rb b/test/unit/region_test.rb
index 2068cc3..3034255 100644
--- a/test/unit/region_test.rb
+++ b/test/unit/region_test.rb
@@ -16,4 +16,12 @@ class RegionTest < Test::Unit::TestCase
end
end
+ should 'be able to search for possible validators by name' do
+ flunk 'need to write this test'
+ end
+
+ should 'return search results without validators that are already associated to the current region' do
+ flunk 'need to write this test'
+ end
+
end
--
libgit2 0.21.2