Commit b4bacb9eb0a9a4976b4ebe27cad15da7e15c584a
1 parent
ff69a878
Exists in
master
and in
29 other branches
ActionItem11: added affiliation of a person to an organization
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@314 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
13 changed files
with
84 additions
and
31 deletions
Show diff stats
app/controllers/enterprise_controller.rb
| ... | ... | @@ -13,11 +13,10 @@ class EnterpriseController < ApplicationController |
| 13 | 13 | |
| 14 | 14 | def list |
| 15 | 15 | @enterprises = Enterprise.find(:all) - @my_enterprises |
| 16 | - @pending_enterprises = current_user.person.pending_enterprises(false) | |
| 17 | 16 | end |
| 18 | 17 | |
| 19 | 18 | def show |
| 20 | - @enterprise = current_user.person.related_profiles.find(params[:id]) | |
| 19 | + @enterprise = @my_enterprises.find(params[:id]) | |
| 21 | 20 | end |
| 22 | 21 | |
| 23 | 22 | def register_form |
| ... | ... | @@ -29,7 +28,7 @@ class EnterpriseController < ApplicationController |
| 29 | 28 | @enterprise = Enterprise.new(params[:enterprise]) |
| 30 | 29 | @enterprise.organization_info = OrganizationInfo.new(params[:organization]) |
| 31 | 30 | if @enterprise.save |
| 32 | - @enterprise.people << current_user.person | |
| 31 | + @enterprise.people << @person | |
| 33 | 32 | flash[:notice] = _('Enterprise was succesfully created') |
| 34 | 33 | redirect_to :action => 'index' |
| 35 | 34 | else |
| ... | ... | @@ -39,12 +38,12 @@ class EnterpriseController < ApplicationController |
| 39 | 38 | end |
| 40 | 39 | |
| 41 | 40 | def edit |
| 42 | - @enterprise = current_user.person.related_profiles.find(params[:id]) | |
| 41 | + @enterprise = @my_enterprises.find(params[:id]) | |
| 43 | 42 | end |
| 44 | 43 | |
| 45 | 44 | def update |
| 46 | - @enterprise = current_user.person.related_profiles.find(params[:id]) | |
| 47 | - if @enterprise.update_attributes(params[:enterprise]) | |
| 45 | + @enterprise = @my_enterprises.find(params[:id]) | |
| 46 | + if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) | |
| 48 | 47 | redirect_to :action => 'index' |
| 49 | 48 | else |
| 50 | 49 | flash[:notice] = _('Could not update the enterprise') |
| ... | ... | @@ -52,8 +51,14 @@ class EnterpriseController < ApplicationController |
| 52 | 51 | end |
| 53 | 52 | end |
| 54 | 53 | |
| 54 | + def affiliate | |
| 55 | + @enterprise = Enterprise.find(params[:id]) | |
| 56 | + @enterprise.people << @person | |
| 57 | + redirect_to :action => 'index' | |
| 58 | + end | |
| 59 | + | |
| 55 | 60 | def destroy |
| 56 | - @enterprise = current_user.person.related_profiles.find(params[:id]) | |
| 61 | + @enterprise = @my_enterprises.find(params[:id]) | |
| 57 | 62 | @enterprise.destroy |
| 58 | 63 | redirect_to :action => 'index' |
| 59 | 64 | end |
| ... | ... | @@ -61,10 +66,19 @@ class EnterpriseController < ApplicationController |
| 61 | 66 | protected |
| 62 | 67 | |
| 63 | 68 | def logon |
| 64 | - redirect_to :controller => 'account' unless logged_in? | |
| 69 | + if logged_in? | |
| 70 | + @user = current_user | |
| 71 | + @person = @user.person | |
| 72 | + else | |
| 73 | + redirect_to :controller => 'account' unless logged_in? | |
| 74 | + end | |
| 65 | 75 | end |
| 66 | 76 | |
| 67 | 77 | def my_enterprises |
| 68 | - @my_enterprises = current_user.person.enterprises | |
| 78 | + if logged_in? | |
| 79 | + @my_active_enterprises = @person.active_enterprises | |
| 80 | + @my_pending_enterprises = @person.pending_enterprises | |
| 81 | + @my_enterprises = @person.enterprises | |
| 82 | + end | |
| 69 | 83 | end |
| 70 | 84 | end | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -94,6 +94,7 @@ module ApplicationHelper |
| 94 | 94 | [ link_to(_('My accont'), { :controller => 'account' }) ], |
| 95 | 95 | [ link_to_profile(_('My home page')) ], |
| 96 | 96 | [ link_to_cms(_('Manage content')) ], |
| 97 | + [ link_to(_('My enterprises'), { :controller => 'enterprise' }) ], | |
| 97 | 98 | ].join("\n") |
| 98 | 99 | content_tag('span', links, :id => 'user_links') |
| 99 | 100 | end | ... | ... |
app/models/affiliation.rb
app/models/organization.rb
app/models/person.rb
| 1 | 1 | class Person < Profile |
| 2 | - belongs_to :user | |
| 3 | - has_many :personal_affiliations, :class_name => 'Affiliation' | |
| 4 | - has_many :related_profiles, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile' | |
| 2 | + ENTERPRISE = {:class_name => 'Enterprise', :through => :affiliations, :source => 'organization'} | |
| 5 | 3 | |
| 6 | - has_many :enterprises, :class_name => 'Enterprise', :through => :personal_affiliations, :source => 'profile', :conditions => ['active = ?', true] | |
| 7 | - | |
| 8 | - has_many :pending_enterprises, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile', :conditions => ['type = ? and active = ?', 'Enterprise', false] | |
| 9 | - | |
| 4 | + belongs_to :user | |
| 5 | + has_many :affiliations | |
| 6 | + has_many :organizations, :through => :affiliations | |
| 7 | + has_many :enterprises, ENTERPRISE | |
| 8 | + has_many :pending_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', false]) | |
| 9 | + has_many :active_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', true]) | |
| 10 | 10 | has_many :friendships |
| 11 | 11 | has_many :friends, :class_name => 'Person', :through => :friendships |
| 12 | - | |
| 13 | - has_many :other_friendships | |
| 14 | - has_many :other_friend, :class_name => 'Person', :through => :other_friendships, :foreign_key => 'friend_id' | |
| 12 | + has_many :person_friendships | |
| 13 | + has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' | |
| 15 | 14 | end | ... | ... |
app/views/enterprise/_enterprise.rhtml
| 1 | -<li> <%= link_to enterprise.name, :action => 'show', :id => enterprise %> | |
| 2 | -<p> <%= link_to _('Edit'), :action => 'edit', :id => enterprise %> </p> | |
| 3 | -<p> <%= link_to _('Delete'), :action => 'destroy', :id => enterprise %> </p> | |
| 1 | +<li> | |
| 2 | +<%= link_to enterprise.name, :action => 'show', :id => enterprise %> | |
| 3 | +<%= link_to _('Edit'), :action => 'edit', :id => enterprise %> | |
| 4 | +<%= link_to _('Delete'), :action => 'destroy', :id => enterprise %> | |
| 5 | +<%= link_to _('Affiliate'), :action => 'affiliate', :id => enterprise unless @my_enterprises.include?(enterprise) %> | |
| 4 | 6 | </li> | ... | ... |
app/views/enterprise/list.rhtml
| 1 | 1 | <p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> </p> |
| 2 | 2 | <h2> <%= _('Listing my enterprises') %> </h2> |
| 3 | 3 | <ul> |
| 4 | - <%= render :partial => 'enterprise', :collection => @my_enterprises %> | |
| 4 | + <%= render :partial => 'enterprise', :collection => @my_active_enterprises %> | |
| 5 | 5 | </ul> |
| 6 | 6 | |
| 7 | -<% unless @pending_enterprises.blank? %> | |
| 7 | +<% unless @my_pending_enterprises.blank? %> | |
| 8 | 8 | <h2> <%= _('Listing pending enterprises') %> </h2> |
| 9 | 9 | <ul> |
| 10 | - <%= render :partial => 'enterprise', :collection => @pending_enterprises %> | |
| 10 | + <%= render :partial => 'enterprise', :collection => @my_pending_enterprises %> | |
| 11 | 11 | </ul> |
| 12 | 12 | <% end %> |
| 13 | + | |
| 14 | +<h4> <%= _('Other Enterprises') %> </h4> | |
| 15 | +<ul> | |
| 16 | + <%= render :partial => 'enterprise', :collection => @enterprises %> | |
| 17 | +</ul> | ... | ... |
app/views/enterprise/show.rhtml
| ... | ... | @@ -10,6 +10,6 @@ |
| 10 | 10 | <p> <%= _('Economic activity: ') %> <%= @enterprise.organization_info.economic_activity %> </p> |
| 11 | 11 | <p> <%= _('Management infomation: ') %> <%= @enterprise.organization_info.management_information %> </p> |
| 12 | 12 | |
| 13 | -<p> <%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> </p> | |
| 14 | -<p> <%= link_to _('Delete enterprise'), :action => 'destroy', :id => @enterprise %> </p> | |
| 15 | -<p> <%= link_to _('Register new enterprise'), :action => 'register_form' %> </p> | |
| 13 | +<%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> | |
| 14 | +<%= link_to _('Delete enterprise'), :action => 'destroy', :id => @enterprise %> | |
| 15 | +<%= link_to _('Register new enterprise'), :action => 'register_form' %> | ... | ... |
db/migrate/007_create_affiliations.rb
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +class CreateFriendships < ActiveRecord::Migration | |
| 2 | + def self.up | |
| 3 | + create_table :friendships do |t| | |
| 4 | + t.column :person_id, :integer | |
| 5 | + t.column :friend_id, :integer | |
| 6 | + t.column :created_at, :datetime | |
| 7 | + end | |
| 8 | + end | |
| 9 | + | |
| 10 | + def self.down | |
| 11 | + drop_table :friendships | |
| 12 | + end | |
| 13 | +end | ... | ... |