Commit d9861a6912319e96d5542228a9df42f8e79956be

Authored by MoisesMachado
1 parent 5d1a3c2d

ActionItem5: linked the functionlity of managing members of profiles and editing the enterprise info


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@566 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
@@ -57,9 +57,9 @@ class ApplicationController < ActionController::Base @@ -57,9 +57,9 @@ class ApplicationController < ActionController::Base
57 # * +permission+ must be a symbol or string naming the needed permission. 57 # * +permission+ must be a symbol or string naming the needed permission.
58 # * +target+ is the object over witch the user would need the specified permission. 58 # * +target+ is the object over witch the user would need the specified permission.
59 def self.protect(actions, permission, target = nil) 59 def self.protect(actions, permission, target = nil)
60 - before_filter :only => actions do |controller|  
61 - unless controller.send(:logged_in?) and controller.send(:current_user).person.has_permission?(permission, target)  
62 - controller.send(:render, {:file => 'app/views/shared/access_denied.rhtml', :layout => true}) 60 + before_filter :only => actions do |c|
  61 + unless c.send(:logged_in?) && c.send(:current_user).person.has_permission?(permission.to_s, c.send(target))
  62 + c.send(:render, {:file => 'app/views/shared/access_denied.rhtml', :layout => true})
63 end 63 end
64 end 64 end
65 end 65 end
app/controllers/profile_admin/enterprise_editor_controller.rb
1 class EnterpriseEditorController < ProfileAdminController 1 class EnterpriseEditorController < ProfileAdminController
2 2
3 before_filter :logon, :check_enterprise 3 before_filter :logon, :check_enterprise
4 - 4 + protect [:edit, :update], :edit_profile, :profile
  5 + protect [:destroy], :destroy_profile, @profile
  6 +
  7 +
5 # Show details about an enterprise 8 # Show details about an enterprise
6 def index 9 def index
7 @enterprise = @profile 10 @enterprise = @profile
app/models/enterprise.rb
@@ -8,11 +8,11 @@ class Enterprise &lt; Organization @@ -8,11 +8,11 @@ class Enterprise &lt; Organization
8 end 8 end
9 9
10 # Test that an enterprise can't be activated unless was previously approved 10 # Test that an enterprise can't be activated unless was previously approved
11 - def validate  
12 - if self.active && !self.approved?  
13 - errors.add('active', _('Not approved enterprise can\'t be activated'))  
14 - end  
15 - end 11 +# def validate
  12 +# if self.active && !self.approved?
  13 +# errors.add('active', _('Not approved enterprise can\'t be activated'))
  14 +# end
  15 +# end
16 16
17 # Activate the enterprise so it can be seen by other users 17 # Activate the enterprise so it can be seen by other users
18 def activate 18 def activate
app/models/profile.rb
@@ -50,6 +50,7 @@ class Profile &lt; ActiveRecord::Base @@ -50,6 +50,7 @@ class Profile &lt; ActiveRecord::Base
50 validates_presence_of :identifier, :name 50 validates_presence_of :identifier, :name
51 validates_format_of :identifier, :with => IDENTIFIER_FORMAT 51 validates_format_of :identifier, :with => IDENTIFIER_FORMAT
52 validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS 52 validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS
  53 + validates_uniqueness_of :identifier
53 54
54 # A profile_owner cannot have more than one profile, but many profiles can exist 55 # A profile_owner cannot have more than one profile, but many profiles can exist
55 # without being associated to a particular user. 56 # without being associated to a particular user.
app/models/role.rb
@@ -6,7 +6,6 @@ class Role &lt; ActiveRecord::Base @@ -6,7 +6,6 @@ class Role &lt; ActiveRecord::Base
6 'destroy_profile' => N_('Destroy profile'), 6 'destroy_profile' => N_('Destroy profile'),
7 'manage_memberships' => N_('Manage memberships'), 7 'manage_memberships' => N_('Manage memberships'),
8 'post_content' => N_('Post content'), 8 'post_content' => N_('Post content'),
9 - 'moderate_content' => N_('Moderate content'),  
10 }, 9 },
11 :system => { 10 :system => {
12 } 11 }
app/views/enterprise_editor/index.rhtml
1 <h3> <%= @profile.name %> </h3> 1 <h3> <%= @profile.name %> </h3>
2 2
  3 +<%= error_messages_for 'profile' %>
  4 +
3 <p> <%= _('Identifier: ') %> <%= @profile.identifier %> </p> 5 <p> <%= _('Identifier: ') %> <%= @profile.identifier %> </p>
4 <p> <%= _('Address: ') %> <%= @profile.address %> </p> 6 <p> <%= _('Address: ') %> <%= @profile.address %> </p>
5 <p> <%= _('Contact phone: ') %> <%= @profile.contact_phone %> </p> 7 <p> <%= _('Contact phone: ') %> <%= @profile.contact_phone %> </p>
@@ -17,3 +19,5 @@ @@ -17,3 +19,5 @@
17 <%= help _('Remove the enterprise from the system') %> 19 <%= help _('Remove the enterprise from the system') %>
18 <%= link_to _('Activate'), :action => 'activate', :id => @profile unless @profile.active? %> 20 <%= link_to _('Activate'), :action => 'activate', :id => @profile unless @profile.active? %>
19 <%= help _('Activate an approved enterprise') unless @profile.active? %> 21 <%= help _('Activate an approved enterprise') unless @profile.active? %>
  22 +
  23 +<%= link_to _('Back'), :controller => :profile_editor %>
app/views/membership_editor/index.rhtml
@@ -2,7 +2,10 @@ @@ -2,7 +2,10 @@
2 2
3 <ul> 3 <ul>
4 <% @memberships.each do |m|%> 4 <% @memberships.each do |m|%>
5 - <li> <%= link_to m.name, '/' + m.identifier %> </li> 5 + <li>
  6 + <%= link_to m.name, '/' + m.identifier %>
  7 + <%= link_to _('Manage') , '/myprofile/' + m.identifier %>
  8 + </li>
6 <% end %> 9 <% end %>
7 </ul> 10 </ul>
8 11
app/views/profile_members/index.rhtml
@@ -9,3 +9,5 @@ @@ -9,3 +9,5 @@
9 <%= link_to _('Remove member'), :action => 'unassociate', :id => m %></li> 9 <%= link_to _('Remove member'), :action => 'unassociate', :id => m %></li>
10 <% end %> 10 <% end %>
11 </ul> 11 </ul>
  12 +
  13 +<%= link_to _('Back'), :controller => 'profile_editor' %>
test/fixtures/roles.yml
@@ -8,6 +8,8 @@ two: @@ -8,6 +8,8 @@ two:
8 id: 2 8 id: 2
9 name: 'owner' 9 name: 'owner'
10 permissions: 10 permissions:
  11 + - menage_memberships
  12 + - post_content
11 - destroy_profile 13 - destroy_profile
12 - edit_profile 14 - edit_profile
13 three: 15 three:
@@ -15,4 +17,3 @@ three: @@ -15,4 +17,3 @@ three:
15 name: 'moderator' 17 name: 'moderator'
16 permissions: 18 permissions:
17 - manage_memberships 19 - manage_memberships
18 - - moderate_content