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 57 # * +permission+ must be a symbol or string naming the needed permission.
58 58 # * +target+ is the object over witch the user would need the specified permission.
59 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 63 end
64 64 end
65 65 end
... ...
app/controllers/profile_admin/enterprise_editor_controller.rb
1 1 class EnterpriseEditorController < ProfileAdminController
2 2  
3 3 before_filter :logon, :check_enterprise
4   -
  4 + protect [:edit, :update], :edit_profile, :profile
  5 + protect [:destroy], :destroy_profile, @profile
  6 +
  7 +
5 8 # Show details about an enterprise
6 9 def index
7 10 @enterprise = @profile
... ...
app/models/enterprise.rb
... ... @@ -8,11 +8,11 @@ class Enterprise &lt; Organization
8 8 end
9 9  
10 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 17 # Activate the enterprise so it can be seen by other users
18 18 def activate
... ...
app/models/profile.rb
... ... @@ -50,6 +50,7 @@ class Profile &lt; ActiveRecord::Base
50 50 validates_presence_of :identifier, :name
51 51 validates_format_of :identifier, :with => IDENTIFIER_FORMAT
52 52 validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS
  53 + validates_uniqueness_of :identifier
53 54  
54 55 # A profile_owner cannot have more than one profile, but many profiles can exist
55 56 # without being associated to a particular user.
... ...
app/models/role.rb
... ... @@ -6,7 +6,6 @@ class Role &lt; ActiveRecord::Base
6 6 'destroy_profile' => N_('Destroy profile'),
7 7 'manage_memberships' => N_('Manage memberships'),
8 8 'post_content' => N_('Post content'),
9   - 'moderate_content' => N_('Moderate content'),
10 9 },
11 10 :system => {
12 11 }
... ...
app/views/enterprise_editor/index.rhtml
1 1 <h3> <%= @profile.name %> </h3>
2 2  
  3 +<%= error_messages_for 'profile' %>
  4 +
3 5 <p> <%= _('Identifier: ') %> <%= @profile.identifier %> </p>
4 6 <p> <%= _('Address: ') %> <%= @profile.address %> </p>
5 7 <p> <%= _('Contact phone: ') %> <%= @profile.contact_phone %> </p>
... ... @@ -17,3 +19,5 @@
17 19 <%= help _('Remove the enterprise from the system') %>
18 20 <%= link_to _('Activate'), :action => 'activate', :id => @profile unless @profile.active? %>
19 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 2  
3 3 <ul>
4 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 9 <% end %>
7 10 </ul>
8 11  
... ...
app/views/profile_members/index.rhtml
... ... @@ -9,3 +9,5 @@
9 9 <%= link_to _('Remove member'), :action => 'unassociate', :id => m %></li>
10 10 <% end %>
11 11 </ul>
  12 +
  13 +<%= link_to _('Back'), :controller => 'profile_editor' %>
... ...
test/fixtures/roles.yml
... ... @@ -8,6 +8,8 @@ two:
8 8 id: 2
9 9 name: 'owner'
10 10 permissions:
  11 + - menage_memberships
  12 + - post_content
11 13 - destroy_profile
12 14 - edit_profile
13 15 three:
... ... @@ -15,4 +17,3 @@ three:
15 17 name: 'moderator'
16 18 permissions:
17 19 - manage_memberships
18   - - moderate_content
... ...