Commit a8c2d855e42ad70d46665f1f55fd76abda342b73
1 parent
95942fcc
Exists in
master
and in
29 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 | 85 | # Activate a validated enterprise |
86 | 86 | def activate |
87 | 87 | @enterprise = Enterprise.find(params[:id]) |
88 | - if @enterprise.update_attribute('active', true) | |
88 | + if @enterprise.activate | |
89 | 89 | flash[:notice] = _('Enterprise successfuly activacted') |
90 | 90 | else |
91 | 91 | flash[:notice] = _('Failed to activate the enterprise') |
... | ... | @@ -93,6 +93,28 @@ class EnterpriseController < ApplicationController |
93 | 93 | redirect_to :action => 'index' |
94 | 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 | 118 | protected |
97 | 119 | |
98 | 120 | # Make sure that the user is logged before access this controller | ... | ... |
app/models/enterprise.rb
1 | 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 | 2 | class Enterprise < Organization |
3 | 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 | 42 | end | ... | ... |
app/models/person.rb
... | ... | @@ -3,7 +3,7 @@ class Person < Profile |
3 | 3 | ENTERPRISE = {:class_name => 'Enterprise', :through => :affiliations, :foreign_key => 'person_id', :source => 'profile'} |
4 | 4 | |
5 | 5 | belongs_to :user |
6 | - has_many :affiliations | |
6 | + has_many :affiliations, :dependent => :destroy | |
7 | 7 | has_many :profiles, :through => :affiliations |
8 | 8 | has_many :enterprises, ENTERPRISE |
9 | 9 | has_many :pending_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', false]) | ... | ... |
app/models/profile.rb
app/views/enterprise/_enterprise.rhtml
... | ... | @@ -6,6 +6,12 @@ |
6 | 6 | <%= help _('Remove the enterprise from the system') %> |
7 | 7 | <%= link_to _('Affiliate'), :action => 'affiliate', :id => enterprise unless @my_enterprises.include?(enterprise) %> |
8 | 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 | 17 | </li> | ... | ... |
app/views/enterprise/list.rhtml
app/views/enterprise/search.rhtml
db/migrate/003_create_profiles.rb
... | ... | @@ -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 | 45 | p1.identifier = 'bli' |
46 | 46 | end |
47 | 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 | 58 | end | ... | ... |