diff --git a/app/controllers/enterprise_controller.rb b/app/controllers/enterprise_controller.rb index 28702ae..d90082d 100644 --- a/app/controllers/enterprise_controller.rb +++ b/app/controllers/enterprise_controller.rb @@ -13,11 +13,10 @@ class EnterpriseController < ApplicationController def list @enterprises = Enterprise.find(:all) - @my_enterprises - @pending_enterprises = current_user.person.pending_enterprises(false) end def show - @enterprise = current_user.person.related_profiles.find(params[:id]) + @enterprise = @my_enterprises.find(params[:id]) end def register_form @@ -29,7 +28,7 @@ class EnterpriseController < ApplicationController @enterprise = Enterprise.new(params[:enterprise]) @enterprise.organization_info = OrganizationInfo.new(params[:organization]) if @enterprise.save - @enterprise.people << current_user.person + @enterprise.people << @person flash[:notice] = _('Enterprise was succesfully created') redirect_to :action => 'index' else @@ -39,12 +38,12 @@ class EnterpriseController < ApplicationController end def edit - @enterprise = current_user.person.related_profiles.find(params[:id]) + @enterprise = @my_enterprises.find(params[:id]) end def update - @enterprise = current_user.person.related_profiles.find(params[:id]) - if @enterprise.update_attributes(params[:enterprise]) + @enterprise = @my_enterprises.find(params[:id]) + if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) redirect_to :action => 'index' else flash[:notice] = _('Could not update the enterprise') @@ -52,8 +51,14 @@ class EnterpriseController < ApplicationController end end + def affiliate + @enterprise = Enterprise.find(params[:id]) + @enterprise.people << @person + redirect_to :action => 'index' + end + def destroy - @enterprise = current_user.person.related_profiles.find(params[:id]) + @enterprise = @my_enterprises.find(params[:id]) @enterprise.destroy redirect_to :action => 'index' end @@ -61,10 +66,19 @@ class EnterpriseController < ApplicationController protected def logon - redirect_to :controller => 'account' unless logged_in? + if logged_in? + @user = current_user + @person = @user.person + else + redirect_to :controller => 'account' unless logged_in? + end end def my_enterprises - @my_enterprises = current_user.person.enterprises + if logged_in? + @my_active_enterprises = @person.active_enterprises + @my_pending_enterprises = @person.pending_enterprises + @my_enterprises = @person.enterprises + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dff3560..0c7ba20 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -94,6 +94,7 @@ module ApplicationHelper [ link_to(_('My accont'), { :controller => 'account' }) ], [ link_to_profile(_('My home page')) ], [ link_to_cms(_('Manage content')) ], + [ link_to(_('My enterprises'), { :controller => 'enterprise' }) ], ].join("\n") content_tag('span', links, :id => 'user_links') end diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 8e84a00..c3f0c6c 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -1,4 +1,4 @@ class Affiliation < ActiveRecord::Base belongs_to :person - belongs_to :profile + belongs_to :organization end diff --git a/app/models/friendship.rb b/app/models/friendship.rb new file mode 100644 index 0000000..ab4fcd8 --- /dev/null +++ b/app/models/friendship.rb @@ -0,0 +1,2 @@ +class Friendship < ActiveRecord::Base +end diff --git a/app/models/organization.rb b/app/models/organization.rb index e0f0f97..5d6bd69 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,3 +1,5 @@ class Organization < Profile has_one :organization_info + has_many :affiliations + has_many :people, :through => :affiliations end diff --git a/app/models/person.rb b/app/models/person.rb index 1e9fad3..538a972 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,15 +1,14 @@ class Person < Profile - belongs_to :user - has_many :personal_affiliations, :class_name => 'Affiliation' - has_many :related_profiles, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile' + ENTERPRISE = {:class_name => 'Enterprise', :through => :affiliations, :source => 'organization'} - has_many :enterprises, :class_name => 'Enterprise', :through => :personal_affiliations, :source => 'profile', :conditions => ['active = ?', true] - - has_many :pending_enterprises, :class_name => 'Profile', :through => :personal_affiliations, :source => 'profile', :conditions => ['type = ? and active = ?', 'Enterprise', false] - + belongs_to :user + has_many :affiliations + has_many :organizations, :through => :affiliations + has_many :enterprises, ENTERPRISE + has_many :pending_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', false]) + has_many :active_enterprises, ENTERPRISE.merge(:conditions => ['active = ?', true]) has_many :friendships has_many :friends, :class_name => 'Person', :through => :friendships - - has_many :other_friendships - has_many :other_friend, :class_name => 'Person', :through => :other_friendships, :foreign_key => 'friend_id' + has_many :person_friendships + has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' end diff --git a/app/views/enterprise/_enterprise.rhtml b/app/views/enterprise/_enterprise.rhtml index 9235801..9172dc5 100644 --- a/app/views/enterprise/_enterprise.rhtml +++ b/app/views/enterprise/_enterprise.rhtml @@ -1,4 +1,6 @@ -
<%= link_to _('Edit'), :action => 'edit', :id => enterprise %>
-<%= link_to _('Delete'), :action => 'destroy', :id => enterprise %>
+<%= link_to _('Register new enterprise'), :action => 'register_form' %>
<%= _('Economic activity: ') %> <%= @enterprise.organization_info.economic_activity %>
<%= _('Management infomation: ') %> <%= @enterprise.organization_info.management_information %>
-<%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %>
-<%= link_to _('Delete enterprise'), :action => 'destroy', :id => @enterprise %>
-<%= link_to _('Register new enterprise'), :action => 'register_form' %>
+<%= link_to _('Edit enterprise'), :action => 'edit', :id => @enterprise %> +<%= link_to _('Delete enterprise'), :action => 'destroy', :id => @enterprise %> +<%= link_to _('Register new enterprise'), :action => 'register_form' %> diff --git a/db/migrate/007_create_affiliations.rb b/db/migrate/007_create_affiliations.rb index cfe97a4..35f37b3 100644 --- a/db/migrate/007_create_affiliations.rb +++ b/db/migrate/007_create_affiliations.rb @@ -1,8 +1,8 @@ class CreateAffiliations < ActiveRecord::Migration def self.up create_table :affiliations do |t| - t.column :person_id, :integer - t.column :profile_id, :integer + t.column :person_id, :integer + t.column :organization_id, :integer end end diff --git a/db/migrate/011_create_friendships.rb b/db/migrate/011_create_friendships.rb new file mode 100644 index 0000000..32ce15e --- /dev/null +++ b/db/migrate/011_create_friendships.rb @@ -0,0 +1,13 @@ +class CreateFriendships < ActiveRecord::Migration + def self.up + create_table :friendships do |t| + t.column :person_id, :integer + t.column :friend_id, :integer + t.column :created_at, :datetime + end + end + + def self.down + drop_table :friendships + end +end diff --git a/test/fixtures/friendships.yml b/test/fixtures/friendships.yml new file mode 100644 index 0000000..b49c4eb --- /dev/null +++ b/test/fixtures/friendships.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 +two: + id: 2 diff --git a/test/unit/friendship_test.rb b/test/unit/friendship_test.rb new file mode 100644 index 0000000..bfc3041 --- /dev/null +++ b/test/unit/friendship_test.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FriendshipTest < Test::Unit::TestCase + fixtures :friendships + + # Replace this with your real tests. + def test_truth + assert true + end +end -- libgit2 0.21.2