Commit 3041e7ee8d303ed3166f233674c4726f7d6ca7af

Authored by MoisesMachado
1 parent adbea539

ActionItem5: cleaned some code and made some views more interconected and accessible


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@561 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/profile_admin/enterprise_editor_controller.rb
... ... @@ -4,8 +4,7 @@ class EnterpriseEditorController < ProfileAdminController
4 4  
5 5 # Show details about an enterprise
6 6 def index
7   - @my_enterprises = @person.enterprises
8   - @my_pending_enterprises = @person.pending_enterprises
  7 + @enterprise = @profile
9 8 end
10 9  
11 10 # Provides an interface to editing the enterprise details
... ... @@ -23,13 +22,6 @@ class EnterpriseEditorController < ProfileAdminController
23 22 render :action => 'edit'
24 23 end
25 24 end
26   -
27   - # Make the current user a new member of the enterprise
28   - def affiliate
29   - member_role = Role.find_by_name('member') || Role.create(:name => 'member')
30   - @enterprise.affiliate(@person,member_role)
31   - redirect_to :action => 'index'
32   - end
33 25  
34 26 # Elimitates the enterprise of the system
35 27 def destroy
... ...
app/controllers/profile_admin/membership_editor_controller.rb
... ... @@ -14,8 +14,8 @@ class MembershipEditorController < ProfileAdminController
14 14 @enterprise = Enterprise.new(params[:enterprise])
15 15 @enterprise.organization_info = OrganizationInfo.new(params[:organization])
16 16 if @enterprise.save
17   - @enterprise.affiliate(@person, Role.find_by_name('owner'))
18   - flash[:notice] = _('The enterprise was succesfully created, the validation entity will cotact you as soon as your enterprise is approved')
  17 + @enterprise.affiliate(current_user.person, Role.find(:all, :conditions => {:name => ['owner', 'member', 'moderator']}))
  18 + flash[:notice] = _('The enterprise was successfully created, the validation entity will cotact you as soon as your enterprise is approved')
19 19 redirect_to :action => 'index'
20 20 else
21 21 flash[:notice] = _('Enterprise was not created')
... ...
app/models/person.rb
... ... @@ -34,7 +34,7 @@ class Person < Profile
34 34 :all,
35 35 :conditions => self.class.conditions_for_profiles(conditions, self),
36 36 :joins => "LEFT JOIN role_assignments ON profiles.id = role_assignments.resource_id AND role_assignments.resource_type = \"#{Profile.base_class.name}\"",
37   - :select => 'profiles.*')
  37 + :select => 'profiles.*').uniq
38 38 end
39 39  
40 40 def info
... ...
app/models/profile.rb
... ... @@ -102,11 +102,14 @@ class Profile < ActiveRecord::Base
102 102 homepage.children.find(:all, :limit => limit, :order => 'created_on desc')
103 103 end
104 104  
105   - def affiliate(person, role)
106   - unless RoleAssignment.find(:first, :conditions => {:person_id => person, :role_id => role, :resource_id => self, :resource_type => self.class.base_class.name})
107   - RoleAssignment.new(:person => person, :role => role, :resource => self).save
108   - else
109   - false
110   - end
  105 + def affiliate(person, roles)
  106 + roles = [roles] unless roles.kind_of?(Array)
  107 + roles.map do |role|
  108 + unless RoleAssignment.find(:first, :conditions => {:person_id => person, :role_id => role, :resource_id => self, :resource_type => self.class.base_class.name})
  109 + RoleAssignment.new(:person => person, :role => role, :resource => self).save
  110 + else
  111 + false
  112 + end
  113 + end.any?
111 114 end
112 115 end
... ...
app/models/role.rb
... ... @@ -3,9 +3,9 @@ class Role < ActiveRecord::Base
3 3 PERMISSIONS = {
4 4 :profile => {
5 5 'edit_profile' => N_('Edit profile'),
6   - 'post_content' => N_('Post content'),
7 6 'destroy_profile' => N_('Destroy profile'),
8   - 'manage_membership' => N_('Manage membership'),
  7 + 'manage_memberships' => N_('Manage memberships'),
  8 + 'post_content' => N_('Post content'),
9 9 'moderate_content' => N_('Moderate content'),
10 10 },
11 11 :system => {
... ...
app/views/account/index.rhtml
... ... @@ -20,6 +20,10 @@
20 20 <%= _('Manage your content.') %>
21 21 </p>
22 22  
  23 +<p>
  24 +<%= link_to_myprofile(_('Manage memberships.'), :controller => 'membership_editor') %>
  25 +<%= _('Manage your affiliation with other profiles.') %>
  26 +</p>
23 27  
24 28 <p>
25 29 <%= link_to _('Logout.'), :action => 'logout' %>
... ...
app/views/enterprise_editor/_enterprise.rhtml
... ... @@ -1,17 +0,0 @@
1   -<li>
2   -<%= link_to enterprise.name, :action => 'show', :id => enterprise %>
3   -<%= link_to _('Edit'), :action => 'edit', :id => enterprise %>
4   -<%= help _('Change the infomation about the enterprise') %>
5   -<%= link_to _('Delete'), :action => 'destroy', :id => enterprise %>
6   -<%= help _('Remove the enterprise from the system') %>
7   -<%= link_to _('Affiliate'), :action => 'affiliate', :id => enterprise unless @my_enterprises.include?(enterprise) %>
8   -<%= help _('Be a member of the enterprise') unless @my_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 %>
17   -</li>
app/views/enterprise_editor/index.rhtml
... ... @@ -15,7 +15,5 @@
15 15 <%= help _('Change the information about the enterprise') %>
16 16 <%= link_to _('Delete enterprise'), :action => 'destroy', :id => @profile %>
17 17 <%= help _('Remove the enterprise from the system') %>
18   -<%= link_to _('Affiliate'), :action => 'affiliate' unless @my_enterprises.include?(@profile) %>
19   -<%= help _('Be a member of the enterprise') unless @my_enterprises.include?(@profile) %>
20   -<%= link_to _('Activate'), :action => 'activate', :id => @profile if @my_pending_enterprises.include?(@profile) %>
21   -<%= help _('Activate an approved enterprise') if @my_pending_enterprises.include?(@profile) %>
  18 +<%= link_to _('Activate'), :action => 'activate', :id => @profile unless @profile.active? %>
  19 +<%= help _('Activate an approved enterprise') unless @profile.active? %>
... ...
app/views/profile_editor/index.rhtml
... ... @@ -2,4 +2,10 @@
2 2  
3 3 <%= display_profile_info(profile) %>
4 4  
5   -<%= link_to _('Edit'), :action => 'edit' %>
  5 +<p> <%= link_to _('Edit'), :action => 'edit' %> </p>
  6 +
  7 +<p> <%= link_to _('Manage members'), :controller => 'profile_members' %> </p>
  8 +
  9 +<% if @profile.class == Enterprise %>
  10 + <p> <%= link_to _('Edit enterprise info'), :controller => 'enterprise_editor'%> </p>
  11 +<% end %>
... ...
app/views/profile_members/affiliate.rhtml
... ... @@ -5,3 +5,5 @@
5 5 <%= hidden_field_tag 'person', current_user.person.id %>
6 6 <%= submit_tag _('Affiliate') %>
7 7 <% end %>
  8 +
  9 +<%= link_to _('Back'), :action => 'index' %>
... ...
app/views/profile_members/change_role.rhtml
... ... @@ -9,4 +9,5 @@
9 9 <%= hidden_field_tag 'person', @member.id %>
10 10  
11 11 <%= submit_tag _('Save changes') %>
  12 + <%= link_to _('Cancel'), :action => 'index' %>
12 13 <% end %>
... ...
app/views/profile_members/index.rhtml
1 1 <h2> <%= _('Listing Members') %> </h2>
2 2  
3   -<%= link_to _('Affiliate'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %>
  3 +<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %>
4 4  
5 5 <ul>
6 6 <% @members.each do |m| %>
... ...
test/fixtures/roles.yml
... ... @@ -8,5 +8,11 @@ two:
8 8 id: 2
9 9 name: 'owner'
10 10 permissions:
11   - - manage_membership
12   - - moderate_content
  11 + - destroy_profile
  12 + - edit_profile
  13 +three:
  14 + id: 3
  15 + name: 'moderator'
  16 + permissions:
  17 + - manage_memberships
  18 + - moderate_content
... ...