Commit 3c57e0221b7fc5a4e8084b6e81b8e12ca638670c
1 parent
a1c5c11c
Exists in
master
and in
29 other branches
ActionItem102: several stuff
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@663 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
188 additions
and
4 deletions
Show diff stats
app/controllers/environment_admin/region_validators_controller.rb
0 → 100644
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +class RegionValidatorsController < ApplicationController | ||
2 | + | ||
3 | + before_filter :load_region_and_search, :except => 'index' | ||
4 | + | ||
5 | + def index | ||
6 | + @regions = Region.top_level_for(environment) | ||
7 | + end | ||
8 | + | ||
9 | + def region | ||
10 | + # nothing to do, load_region_and_search already does everything needed here | ||
11 | + end | ||
12 | + | ||
13 | + def search | ||
14 | + render :partial => 'search' | ||
15 | + end | ||
16 | + | ||
17 | + def add | ||
18 | + validator = environment.organizations.find(params[:validator_id]) | ||
19 | + @region.validators << validator | ||
20 | + redirect_to :action => 'region', :id => @region.id | ||
21 | + end | ||
22 | + | ||
23 | + def remove | ||
24 | + validator = environment.organizations.find(params[:validator_id]) | ||
25 | + @region.validators.delete(validator) | ||
26 | + redirect_to :action => 'region', :id => @region.id | ||
27 | + end | ||
28 | + | ||
29 | + protected | ||
30 | + | ||
31 | + def load_region_and_search | ||
32 | + @region = environment.regions.find(params[:id]) | ||
33 | + if params[:search] | ||
34 | + @search = Organization.find_by_contents(params[:search]) | ||
35 | + end | ||
36 | + end | ||
37 | + | ||
38 | +end |
app/models/environment.rb
@@ -22,6 +22,8 @@ class Environment < ActiveRecord::Base | @@ -22,6 +22,8 @@ class Environment < ActiveRecord::Base | ||
22 | has_many :domains, :as => :owner | 22 | has_many :domains, :as => :owner |
23 | has_many :profiles | 23 | has_many :profiles |
24 | 24 | ||
25 | + has_many :organizations | ||
26 | + | ||
25 | has_many :categories | 27 | has_many :categories |
26 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' | 28 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' |
27 | 29 |
app/models/profile.rb
@@ -18,6 +18,8 @@ class Profile < ActiveRecord::Base | @@ -18,6 +18,8 @@ class Profile < ActiveRecord::Base | ||
18 | 18 | ||
19 | acts_as_accessible | 19 | acts_as_accessible |
20 | 20 | ||
21 | + acts_as_ferret :fields => [ :name ] | ||
22 | + | ||
21 | # Valid identifiers must match this format. | 23 | # Valid identifiers must match this format. |
22 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ | 24 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ |
23 | 25 |
app/views/admin_panel/index.rhtml
@@ -7,4 +7,5 @@ | @@ -7,4 +7,5 @@ | ||
7 | <li><%= link_to _('Edit the Visual Design'), :controller => 'edit_template'%></li> | 7 | <li><%= link_to _('Edit the Visual Design'), :controller => 'edit_template'%></li> |
8 | <li><%= link_to _('Manage Categories'), :controller => 'categories'%></li> | 8 | <li><%= link_to _('Manage Categories'), :controller => 'categories'%></li> |
9 | <li><%= link_to _('Manage User roles'), :controller => 'role' %></li> | 9 | <li><%= link_to _('Manage User roles'), :controller => 'role' %></li> |
10 | + <li><%= link_to _('Manage Validators by region'), :controller => 'region_validators' %></li> | ||
10 | </ul> | 11 | </ul> |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +<li> | ||
2 | + | ||
3 | +<div class='treeitem'> | ||
4 | + <%= link_to region.name, :action => 'region', :id => region %> | ||
5 | + <em><%= n_('1 validator', '%{num} validators.', region.validators.size) % { :num => region.validators.size } %></em> | ||
6 | + <% unless region.children.empty? %> | ||
7 | + <ul class='tree'> | ||
8 | + <%= render :partial => 'region', :collection => region.children %> | ||
9 | + </ul> | ||
10 | + <% end %> | ||
11 | + | ||
12 | +</div> | ||
13 | + | ||
14 | +</li> |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<% if @search %> | ||
2 | + <ul> | ||
3 | + <% for item in @search %> | ||
4 | + <li> | ||
5 | + <%= item.name %> | ||
6 | + <% form_tag :action => 'add', :id => @region do %> | ||
7 | + <%= hidden_field_tag :validator_id, item.id %> | ||
8 | + <%= submit_tag _('Adicionar') %> | ||
9 | + <% end %> | ||
10 | + </li> | ||
11 | + <% end %> | ||
12 | + </ul> | ||
13 | +<% end %> |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +<h1><%= _('Validators for region %s') % @region.name %></h1> | ||
2 | + | ||
3 | +<h2><%= _('Current validators') %></h2> | ||
4 | + | ||
5 | +<ul> | ||
6 | + <% for validator in @region.validators %> | ||
7 | + <li> | ||
8 | + <%= link_to_homepage validator.name, validator.identifier %> | ||
9 | + <%= link_to _('Remove validation rights'), { :action => 'remove', :id => @region.id, :validator_id => validator }, :method => 'post' %> | ||
10 | + </li> | ||
11 | + <% end %> | ||
12 | +</ul> | ||
13 | + | ||
14 | +<h2><%= _('Add new validators') %></h2> | ||
15 | + | ||
16 | +<p> | ||
17 | +<%= help _('First search organizations by their name, then use the buttons in the search result to add them as validators for this region. ') %> | ||
18 | +</p> | ||
19 | + | ||
20 | +<% form_tag({}, { :method => 'get' }) do %> | ||
21 | + <%= text_field_tag :search, nil, :id => 'search_validator' %> | ||
22 | + <%= submit_tag _('Search') %> | ||
23 | +<% end %> | ||
24 | + | ||
25 | +<%= observe_field 'search_validator', :url => { :action => 'search', :id => @region.id }, :with => 'search', :frequency => 1, :update => 'search_results' %> | ||
26 | + | ||
27 | +<div id='search_results'> | ||
28 | + <%= render :partial => 'search' %> | ||
29 | +</div> |
db/migrate/003_create_profiles.rb
@@ -5,9 +5,6 @@ class CreateProfiles < ActiveRecord::Migration | @@ -5,9 +5,6 @@ class CreateProfiles < ActiveRecord::Migration | ||
5 | t.column :type, :string | 5 | t.column :type, :string |
6 | t.column :identifier, :string | 6 | t.column :identifier, :string |
7 | t.column :environment_id, :integer | 7 | t.column :environment_id, :integer |
8 | - t.column :flexible_template_template, :string, :default => "default" | ||
9 | - t.column :flexible_template_theme, :string, :default => "default" | ||
10 | - t.column :flexible_template_icon_theme, :string, :default => "default" | ||
11 | t.column :active, :boolean, :default => false | 8 | t.column :active, :boolean, :default => false |
12 | t.column :address, :string | 9 | t.column :address, :string |
13 | t.column :contact_phone, :string | 10 | t.column :contact_phone, :string |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +class CreateRegionValidatorsTable < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :region_validators, :id => false do |t| | ||
4 | + t.column :region_id, :integer | ||
5 | + t.column :organization_id, :integer | ||
6 | + end | ||
7 | + end | ||
8 | + | ||
9 | + def self.down | ||
10 | + drop_table :region_validators | ||
11 | + end | ||
12 | +end |
test/functional/membership_editor_controller_test.rb
@@ -19,7 +19,7 @@ class MembershipEditorControllerTest < Test::Unit::TestCase | @@ -19,7 +19,7 @@ class MembershipEditorControllerTest < Test::Unit::TestCase | ||
19 | assert_kind_of Array, assigns(:memberships) | 19 | assert_kind_of Array, assigns(:memberships) |
20 | end | 20 | end |
21 | 21 | ||
22 | - should 'propmt for new enterprise data' do | 22 | + should 'prompt for new enterprise data' do |
23 | get :new_enterprise, :profile => 'ze' | 23 | get :new_enterprise, :profile => 'ze' |
24 | assert assigns(:virtual_communities) | 24 | assert assigns(:virtual_communities) |
25 | assert_kind_of Array, assigns(:virtual_communities) | 25 | assert_kind_of Array, assigns(:virtual_communities) |
@@ -0,0 +1,61 @@ | @@ -0,0 +1,61 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +require 'region_validators_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class RegionValidatorsController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class RegionValidatorsControllerTest < Test::Unit::TestCase | ||
8 | + def setup | ||
9 | + @controller = RegionValidatorsController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + end | ||
13 | + | ||
14 | + # Replace this with your real tests. | ||
15 | + should 'list regions at index' do | ||
16 | + get :index | ||
17 | + assert_response :success | ||
18 | + assert_template 'index' | ||
19 | + assert_kind_of Array, assigns(:regions) | ||
20 | + end | ||
21 | + | ||
22 | + should 'view validators for a specific region' do | ||
23 | + environment = Environment.create!(:name => "my environment") | ||
24 | + region = Region.new(:name => 'my region') | ||
25 | + environment.regions << region | ||
26 | + assert !region.new_record? | ||
27 | + | ||
28 | + @controller.expects(:environment).returns(environment) | ||
29 | + | ||
30 | + get :region, :id => region.id | ||
31 | + | ||
32 | + assert_response :success | ||
33 | + assert_template 'region' | ||
34 | + assert_equal region, assigns(:region) | ||
35 | + end | ||
36 | + | ||
37 | + should 'search possible validators by name' do | ||
38 | + environment = Environment.create!(:name => "my environment") | ||
39 | + region = Region.new(:name => 'my region') | ||
40 | + environment.regions << region | ||
41 | + assert !region.new_record? | ||
42 | + org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru') | ||
43 | + | ||
44 | + @controller.expects(:environment).returns(environment) | ||
45 | + Organization.expects(:find_by_contents).with('frufru').returns([org]) | ||
46 | + | ||
47 | + get :search, :id => region.id, :search => 'frufru' | ||
48 | + | ||
49 | + assert_response :success | ||
50 | + assert_equal [org], assigns(:search) | ||
51 | + end | ||
52 | + | ||
53 | + should 'be able to add validators to the current region' do | ||
54 | + flunk 'need to write this test' | ||
55 | + end | ||
56 | + | ||
57 | + should 'be able to remove validators from the current region' do | ||
58 | + flunk 'need to write this test' | ||
59 | + end | ||
60 | + | ||
61 | +end |
test/unit/region_test.rb
@@ -16,4 +16,12 @@ class RegionTest < Test::Unit::TestCase | @@ -16,4 +16,12 @@ class RegionTest < Test::Unit::TestCase | ||
16 | end | 16 | end |
17 | end | 17 | end |
18 | 18 | ||
19 | + should 'be able to search for possible validators by name' do | ||
20 | + flunk 'need to write this test' | ||
21 | + end | ||
22 | + | ||
23 | + should 'return search results without validators that are already associated to the current region' do | ||
24 | + flunk 'need to write this test' | ||
25 | + end | ||
26 | + | ||
19 | end | 27 | end |