Commit c760938da2323dfa1fab8f1ef091f3a00c9ca0a8
1 parent
71b98ac5
Exists in
master
and in
28 other branches
ActionItem6: documented the enterprise controller and the related models
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@355 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
17 additions
and
0 deletions
Show diff stats
app/controllers/enterprise_controller.rb
@@ -3,6 +3,7 @@ class EnterpriseController < ApplicationController | @@ -3,6 +3,7 @@ class EnterpriseController < ApplicationController | ||
3 | 3 | ||
4 | before_filter :logon, :my_enterprises | 4 | before_filter :logon, :my_enterprises |
5 | 5 | ||
6 | + # Redirects to show if there is only one action and to list otherwise | ||
6 | def index | 7 | def index |
7 | if @my_enterprises.size == 1 | 8 | if @my_enterprises.size == 1 |
8 | redirect_to :action => 'show', :id => @my_enterprises[0] | 9 | redirect_to :action => 'show', :id => @my_enterprises[0] |
@@ -11,20 +12,24 @@ class EnterpriseController < ApplicationController | @@ -11,20 +12,24 @@ class EnterpriseController < ApplicationController | ||
11 | end | 12 | end |
12 | end | 13 | end |
13 | 14 | ||
15 | + # Lists all enterprises | ||
14 | def list | 16 | def list |
15 | @enterprises = Enterprise.find(:all) - @my_enterprises | 17 | @enterprises = Enterprise.find(:all) - @my_enterprises |
16 | end | 18 | end |
17 | 19 | ||
20 | + # Show details about an enterprise | ||
18 | def show | 21 | def show |
19 | @enterprise = @my_enterprises.find(params[:id]) | 22 | @enterprise = @my_enterprises.find(params[:id]) |
20 | end | 23 | end |
21 | 24 | ||
25 | + # Make a form to the creation of an eterprise | ||
22 | def register_form | 26 | def register_form |
23 | @enterprise = Enterprise.new() | 27 | @enterprise = Enterprise.new() |
24 | @vitual_communities = VirtualCommunity.find(:all) | 28 | @vitual_communities = VirtualCommunity.find(:all) |
25 | @validation_entities = Organization.find(:all) | 29 | @validation_entities = Organization.find(:all) |
26 | end | 30 | end |
27 | 31 | ||
32 | + # Saves the new created enterprise | ||
28 | def register | 33 | def register |
29 | @enterprise = Enterprise.new(params[:enterprise]) | 34 | @enterprise = Enterprise.new(params[:enterprise]) |
30 | @enterprise.organization_info = OrganizationInfo.new(params[:organization]) | 35 | @enterprise.organization_info = OrganizationInfo.new(params[:organization]) |
@@ -40,11 +45,13 @@ class EnterpriseController < ApplicationController | @@ -40,11 +45,13 @@ class EnterpriseController < ApplicationController | ||
40 | end | 45 | end |
41 | end | 46 | end |
42 | 47 | ||
48 | + # Provides an interface to editing the enterprise details | ||
43 | def edit | 49 | def edit |
44 | @enterprise = @my_enterprises.find(params[:id]) | 50 | @enterprise = @my_enterprises.find(params[:id]) |
45 | @validation_entities = Organization.find(:all) - [@enterprise] | 51 | @validation_entities = Organization.find(:all) - [@enterprise] |
46 | end | 52 | end |
47 | 53 | ||
54 | + # Saves the changes made in an enterprise | ||
48 | def update | 55 | def update |
49 | @enterprise = @my_enterprises.find(params[:id]) | 56 | @enterprise = @my_enterprises.find(params[:id]) |
50 | if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) | 57 | if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) |
@@ -56,22 +63,26 @@ class EnterpriseController < ApplicationController | @@ -56,22 +63,26 @@ class EnterpriseController < ApplicationController | ||
56 | end | 63 | end |
57 | end | 64 | end |
58 | 65 | ||
66 | + # Make the current user a new member of the enterprise | ||
59 | def affiliate | 67 | def affiliate |
60 | @enterprise = Enterprise.find(params[:id]) | 68 | @enterprise = Enterprise.find(params[:id]) |
61 | @enterprise.people << @person | 69 | @enterprise.people << @person |
62 | redirect_to :action => 'index' | 70 | redirect_to :action => 'index' |
63 | end | 71 | end |
64 | 72 | ||
73 | + # Elimitates the enterprise of the system | ||
65 | def destroy | 74 | def destroy |
66 | @enterprise = @my_enterprises.find(params[:id]) | 75 | @enterprise = @my_enterprises.find(params[:id]) |
67 | @enterprise.destroy | 76 | @enterprise.destroy |
68 | redirect_to :action => 'index' | 77 | redirect_to :action => 'index' |
69 | end | 78 | end |
70 | 79 | ||
80 | + # Search enterprises by name or tags | ||
71 | def search | 81 | def search |
72 | @tagged_enterprises = Enterprise.search(params[:query]) | 82 | @tagged_enterprises = Enterprise.search(params[:query]) |
73 | end | 83 | end |
74 | 84 | ||
85 | + # Activate a validated enterprise | ||
75 | def activate | 86 | def activate |
76 | @enterprise = Enterprise.find(params[:id]) | 87 | @enterprise = Enterprise.find(params[:id]) |
77 | if @enterprise.update_attribute('active', true) | 88 | if @enterprise.update_attribute('active', true) |
@@ -84,6 +95,7 @@ class EnterpriseController < ApplicationController | @@ -84,6 +95,7 @@ class EnterpriseController < ApplicationController | ||
84 | 95 | ||
85 | protected | 96 | protected |
86 | 97 | ||
98 | + # Make sure that the user is logged before access this controller | ||
87 | def logon | 99 | def logon |
88 | if logged_in? | 100 | if logged_in? |
89 | @user = current_user | 101 | @user = current_user |
@@ -93,6 +105,7 @@ class EnterpriseController < ApplicationController | @@ -93,6 +105,7 @@ class EnterpriseController < ApplicationController | ||
93 | end | 105 | end |
94 | end | 106 | end |
95 | 107 | ||
108 | + # Initializes some variables to contain the enterprises of the current user | ||
96 | def my_enterprises | 109 | def my_enterprises |
97 | if logged_in? | 110 | if logged_in? |
98 | @my_active_enterprises = @person.active_enterprises | 111 | @my_active_enterprises = @person.active_enterprises |
app/models/affiliation.rb
app/models/organization.rb
1 | +# Represents any organization of the system and has an organization_info object to hold its info | ||
1 | class Organization < Profile | 2 | class Organization < Profile |
2 | has_one :organization_info | 3 | has_one :organization_info |
3 | has_many :validated_enterprises, :class_name => 'enterprise' | 4 | has_many :validated_enterprises, :class_name => 'enterprise' |
app/models/person.rb
1 | +# A person is the profile of an user holding all relationships with the rest of the system | ||
1 | class Person < Profile | 2 | class Person < Profile |
2 | 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'} |
3 | 4 |
app/models/profile.rb
@@ -56,6 +56,7 @@ class Profile < ActiveRecord::Base | @@ -56,6 +56,7 @@ class Profile < ActiveRecord::Base | ||
56 | self.virtual_community ||= VirtualCommunity.default | 56 | self.virtual_community ||= VirtualCommunity.default |
57 | end | 57 | end |
58 | 58 | ||
59 | + # Searches tags by tag or name | ||
59 | def self.search(term) | 60 | def self.search(term) |
60 | find_tagged_with(term) + find_all_by_name(term) | 61 | find_tagged_with(term) + find_all_by_name(term) |
61 | end | 62 | end |