Commit 1f71e6736b26f5715246c12294ea931a1c690b48

Authored by MoisesMachado
1 parent 39655247

ActionItem6: some enterprise level fixes :)

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@185 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/enterprise_controller.rb
... ... @@ -2,7 +2,8 @@
2 2 class EnterpriseController < ApplicationController
3 3  
4 4 def index
5   - @my_enterprises = current_user.enterprises
  5 + @my_enterprises = current_user.enterprises if current_user
  6 + @enterprises = Enterprise.find(:all) - @my_enterprises
6 7 end
7 8  
8 9 def register
... ... @@ -21,6 +22,7 @@ class EnterpriseController &lt; ApplicationController
21 22  
22 23 def create
23 24 @enterprise = Enterprise.new(params[:enterprise])
  25 + @enterprise.manager = current_user
24 26 if @enterprise.save
25 27 flash[:notice] = _('Enterprise was succesfully created')
26 28 redirect_to :action => 'register'
... ...
app/models/enterprise.rb
... ... @@ -6,6 +6,7 @@ class Enterprise &lt; ActiveRecord::Base
6 6 end
7 7  
8 8 has_one :enterprise_profile, :class_name => 'Profile', :as => :profile_owner
  9 + has_many :affiliations
9 10 has_many :users, :through => :affiliation
10 11 belongs_to :manager, :class_name => 'User'
11 12  
... ...
app/models/user.rb
... ... @@ -10,7 +10,7 @@ class User &lt; ActiveRecord::Base
10 10  
11 11 has_one :personal_profile, :class_name => 'Profile', :as => :profile_owner
12 12 has_many :affiliations
13   - has_many :enterprises, :through => :affiliation
  13 + has_many :enterprises, :through => :affiliations
14 14 # Virtual attribute for the unencrypted password
15 15 attr_accessor :password
16 16  
... ...