Commit a8c2d855e42ad70d46665f1f55fd76abda342b73
1 parent
95942fcc
Exists in
master
and in
22 other branches
ActionItem16: added approve and reject capabilities to enterprise
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@399 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
13 changed files
with
121 additions
and
6 deletions
Show diff stats
app/controllers/enterprise_controller.rb
@@ -85,7 +85,7 @@ class EnterpriseController < ApplicationController | @@ -85,7 +85,7 @@ class EnterpriseController < ApplicationController | ||
85 | # Activate a validated enterprise | 85 | # Activate a validated enterprise |
86 | def activate | 86 | def activate |
87 | @enterprise = Enterprise.find(params[:id]) | 87 | @enterprise = Enterprise.find(params[:id]) |
88 | - if @enterprise.update_attribute('active', true) | 88 | + if @enterprise.activate |
89 | flash[:notice] = _('Enterprise successfuly activacted') | 89 | flash[:notice] = _('Enterprise successfuly activacted') |
90 | else | 90 | else |
91 | flash[:notice] = _('Failed to activate the enterprise') | 91 | flash[:notice] = _('Failed to activate the enterprise') |
@@ -93,6 +93,28 @@ class EnterpriseController < ApplicationController | @@ -93,6 +93,28 @@ class EnterpriseController < ApplicationController | ||
93 | redirect_to :action => 'index' | 93 | redirect_to :action => 'index' |
94 | end | 94 | end |
95 | 95 | ||
96 | + # Validates an eterprise | ||
97 | + def approve | ||
98 | + @enterprise = Enterprise.find(params[:id]) | ||
99 | + if @enterprise.approve | ||
100 | + flash[:notice] = _('Enterprise successfuly approved') | ||
101 | + else | ||
102 | + flash[:notice] = _('Failed to approve the enterprise') | ||
103 | + end | ||
104 | + redirect_to :action => 'index' | ||
105 | + end | ||
106 | + | ||
107 | + def reject | ||
108 | + @enterprise = Enterprise.find(params[:id]) | ||
109 | + if @enterprise.reject | ||
110 | + flash[:notice] = _('Enterprise successfuly rejected') | ||
111 | + else | ||
112 | + flash[:notice] = _('Failed to reject the enterprise') | ||
113 | + end | ||
114 | + redirect_to :action => 'index' | ||
115 | + end | ||
116 | + | ||
117 | + | ||
96 | protected | 118 | protected |
97 | 119 | ||
98 | # Make sure that the user is logged before access this controller | 120 | # Make sure that the user is logged before access this controller |
app/models/enterprise.rb
1 | #An enterprise is a kind of organization. According to the system concept, only enterprises can offer products/services and ahave to be validated by an validation entity | 1 | #An enterprise is a kind of organization. According to the system concept, only enterprises can offer products/services and ahave to be validated by an validation entity |
2 | class Enterprise < Organization | 2 | class Enterprise < Organization |
3 | belongs_to :validation_entity, :class_name => 'organization', :foreign_key => 'validation_entity_id' | 3 | belongs_to :validation_entity, :class_name => 'organization', :foreign_key => 'validation_entity_id' |
4 | + has_one :enterprise_info | ||
5 | + | ||
6 | + after_create do |enterprise| | ||
7 | + EnterpriseInfo.create!(:enterprise_id => enterprise.id) | ||
8 | + end | ||
9 | + | ||
10 | + # Test that an enterprise can't be activated unless was previously approved | ||
11 | + def validate | ||
12 | + if self.active && !self.approved? | ||
13 | + errors.add('active', _('Not approved enterprise can\'t be activated')) | ||
14 | + end | ||
15 | + end | ||
16 | + | ||
17 | + # Activate the enterprise so it can be seen by other users | ||
18 | + def activate | ||
19 | + self.active = true | ||
20 | + self.save | ||
21 | + end | ||
22 | + | ||
23 | + # Approve the enterprise so it can be activated by its owner | ||
24 | + def approve | ||
25 | + enterprise_info.update_attribute('approval_status', 'approved') | ||
26 | + end | ||
27 | + | ||
28 | + # Reject the approval of the enterprise giving a status message describing its problem | ||
29 | + def reject(msg = 'rejected', comments = '') | ||
30 | + enterprise_info.update_attribute('approval_status', msg) | ||
31 | + enterprise_info.update_attribute('approval_comments', comments) | ||
32 | + end | ||
33 | + | ||
34 | + # Check if the enterprise was approved, that is if the fild approval_status holds the string 'approved' | ||
35 | + def approved? | ||
36 | + enterprise_info.approval_status == 'approved' | ||
37 | + end | ||
38 | + # Check if the enterprise was rejected, that is if the fild approval_status holds the string 'rejected' | ||
39 | + def rejected? | ||
40 | + enterprise_info.approval_status == 'rejected' | ||
41 | + end | ||
4 | end | 42 | end |
app/models/person.rb
@@ -3,7 +3,7 @@ class Person < Profile | @@ -3,7 +3,7 @@ class Person < Profile | ||
3 | ENTERPRISE = {:class_name => 'Enterprise', :through => :affiliations, :foreign_key => 'person_id', :source => 'profile'} | 3 | ENTERPRISE = {:class_name => 'Enterprise', :through => :affiliations, :foreign_key => 'person_id', :source => 'profile'} |
4 | 4 | ||
5 | belongs_to :user | 5 | belongs_to :user |
6 | - has_many :affiliations | 6 | + has_many :affiliations, :dependent => :destroy |
7 | has_many :profiles, :through => :affiliations | 7 | has_many :profiles, :through => :affiliations |
8 | has_many :enterprises, ENTERPRISE | 8 | has_many :enterprises, ENTERPRISE |
9 | has_many :pending_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', false]) | 9 | has_many :pending_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', false]) |
app/models/profile.rb
@@ -27,7 +27,7 @@ class Profile < ActiveRecord::Base | @@ -27,7 +27,7 @@ class Profile < ActiveRecord::Base | ||
27 | 27 | ||
28 | has_many :domains, :as => :owner | 28 | has_many :domains, :as => :owner |
29 | belongs_to :virtual_community | 29 | belongs_to :virtual_community |
30 | - has_many :affiliations | 30 | + has_many :affiliations, :dependent => :destroy |
31 | has_many :people, :through => :affiliations | 31 | has_many :people, :through => :affiliations |
32 | 32 | ||
33 | 33 |
app/views/enterprise/_enterprise.rhtml
@@ -6,6 +6,12 @@ | @@ -6,6 +6,12 @@ | ||
6 | <%= help _('Remove the enterprise from the system') %> | 6 | <%= help _('Remove the enterprise from the system') %> |
7 | <%= link_to _('Affiliate'), :action => 'affiliate', :id => enterprise unless @my_enterprises.include?(enterprise) %> | 7 | <%= link_to _('Affiliate'), :action => 'affiliate', :id => enterprise unless @my_enterprises.include?(enterprise) %> |
8 | <%= help _('Be a member of the enterprise') unless @my_enterprises.include?(enterprise) %> | 8 | <%= help _('Be a member of the enterprise') unless @my_enterprises.include?(enterprise) %> |
9 | -<%= link_to _('Activate'), :action => 'activate', :id => enterprise if @my_pending_enterprises.include?(enterprise) %> | ||
10 | -<%= help _('Activate the profile of an approved enterprise') if @my_pending_enterprises.include?(enterprise) %> | 9 | +<%= link_to _('Activate'), :action => 'activate', :id => enterprise unless enterprise.active %> |
10 | +<%= help _('Activate the profile of an approved enterprise') unless enterprise.active %> | ||
11 | +<% unless enterprise.approved? %> | ||
12 | + <%= link_to _('Approve'), :action => 'approve', :id => enterprise %> | ||
13 | + <%= help _('Approve a submitted enterprise profile') %> | ||
14 | + <%= link_to _('Reject'), :action => 'reject', :id => enterprise %> | ||
15 | + <%= help _('Reject a submitted enterprise profile') %> | ||
16 | +<% end %> | ||
11 | </li> | 17 | </li> |
app/views/enterprise/list.rhtml
1 | <%= render :partial => 'search_box' %> | 1 | <%= render :partial => 'search_box' %> |
2 | 2 | ||
3 | +<%= error_messages_for 'enterprise' %> | ||
4 | +<%= error_messages_for 'enterprise_info' %> | ||
5 | + | ||
3 | <p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> | 6 | <p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> |
4 | <%= help _('Creates a new enterprise') %> | 7 | <%= help _('Creates a new enterprise') %> |
5 | </p> | 8 | </p> |
app/views/enterprise/search.rhtml
1 | -<h2> <%= @tagged_enterprises.size.to_s + _(' tags found') %> </h2> | 1 | +<h2> <%= @tagged_enterprises.size.to_s + _(' enterprises found') %> </h2> |
2 | 2 | ||
3 | <%= render :partial => 'enterprise', :collection => @tagged_enterprises %> | 3 | <%= render :partial => 'enterprise', :collection => @tagged_enterprises %> |
db/migrate/003_create_profiles.rb
@@ -17,6 +17,7 @@ class CreateProfiles < ActiveRecord::Migration | @@ -17,6 +17,7 @@ class CreateProfiles < ActiveRecord::Migration | ||
17 | 17 | ||
18 | #enterprise fields | 18 | #enterprise fields |
19 | t.column :validation_entity_id, :integer | 19 | t.column :validation_entity_id, :integer |
20 | + t.column :approved, :boolean | ||
20 | end | 21 | end |
21 | end | 22 | end |
22 | 23 |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class CreateEnterpriseInfos < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :enterprise_infos do |t| | ||
4 | + t.column :approval_status, :string, :default => 'not evaluated' | ||
5 | + t.column :approval_comments, :text | ||
6 | + t.column :enterprise_id, :integer | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + def self.down | ||
11 | + drop_table :enterprise_infos | ||
12 | + end | ||
13 | +end |
test/unit/enterprise_test.rb
@@ -45,4 +45,14 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -45,4 +45,14 @@ class EnterpriseTest < Test::Unit::TestCase | ||
45 | p1.identifier = 'bli' | 45 | p1.identifier = 'bli' |
46 | end | 46 | end |
47 | end | 47 | end |
48 | + | ||
49 | + def test_cannot_be_activated_without_approval | ||
50 | + e = Enterprise.create(:identifier => 'bli', :name => 'Bli') | ||
51 | + assert !e.approved | ||
52 | + e.activate | ||
53 | + assert !e.valid? | ||
54 | + e.approve | ||
55 | + e.activate | ||
56 | + assert e.valid? | ||
57 | + end | ||
48 | end | 58 | end |