Commit 05b73d10bfd62a448e8645b51042e6438f2972eb

Authored by MoisesMachado
1 parent 0558b6da

ActionItem111: alguns bugs corrigidos e populate melhorado


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@726 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/home_controller.rb
1 1 class HomeController < PublicController
2 2  
3 3 design :holder => 'environment'
4   -
  4 + def index
  5 +# redirect_to homepage_path(:profile => 'anhetegua')
  6 + end
5 7 end
... ...
app/helpers/application_helper.rb
... ... @@ -118,7 +118,7 @@ module ApplicationHelper
118 118 ( link_to_homepage(current_user.login) ),
119 119 ( link_to(_('My account'), { :controller => 'account' }) ),
120 120 ( link_to_myprofile _('My Enterprises'), {:controller => 'membership_editor'} ),
121   - ( link_to(_('Admin'), { :controller => 'admin_panel' }) if current_user.person.role_assignments.map{|ra| ra.role.permissions}.any?{|ps|ps.any?{|p|ActiveRecord::Base::PERMISSIONS[:environment].keys.include?(p)}}),
  121 + ( link_to(_('Admin'), { :controller => 'admin_panel' }) if current_user.person.is_admin?),
122 122 ].join("\n")
123 123 content_tag('span', links, :id => 'user_links')
124 124 end
... ... @@ -174,20 +174,19 @@ module ApplicationHelper
174 174  
175 175 def person_links
176 176 links = [
177   - [(link_to_myprofile _('Edit visual design'), :controller => 'profile_editor', :action => 'design_editor'), 'edit_profile_design', profile],
178   - [(link_to_myprofile _('Edit profile'), :controller => 'profile_editor'), 'edit_profile', profile],
179   - [(link_to_myprofile _('Manage content'), :controller => 'cms'), 'post_content', profile],
  177 + [(link_to_myprofile _('Edit visual design'), {:controller => 'profile_editor', :action => 'design_editor'}, profile.identifier), 'edit_profile_design', profile],
  178 + [(link_to_myprofile _('Edit profile'), {:controller => 'profile_editor'}, profile.identifier), 'edit_profile', profile],
  179 + [(link_to_myprofile _('Manage content'), {:controller => 'cms'}, profile.identifier), 'post_content', profile],
180 180 ]
181   -
182 181 end
183 182  
184 183  
185 184 def enterprise_links
186 185 links = [
187   - [(link_to_myprofile _('Edit visual design'), :controller => 'profile_editor', :action => 'design_editor'), 'edit_profile_design', profile],
188   - [(link_to_myprofile _('Edit informations'), :controller => 'profile_editor'), 'edit_profile', profile],
189   - [(link_to_myprofile _('Manage content'), :controller => 'cms'), 'post_content', profile],
190   - [(link_to_myprofile _('Exclude'), :controller => 'enterprise_editor', :action => 'destroy'), 'edit_profile', profile],
  186 + [(link_to_myprofile _('Edit visual design'), {:controller => 'profile_editor', :action => 'design_editor'}, profile), 'edit_profile_design', profile],
  187 + [(link_to_myprofile _('Edit informations'), {:controller => 'profile_editor'}, profile), 'edit_profile', profile],
  188 + [(link_to_myprofile _('Manage content'), {:controller => 'cms'}, profile), 'post_content', profile],
  189 + [(link_to_myprofile _('Exclude'), {:controller => 'enterprise_editor', :action => 'destroy'}, profile), 'edit_profile', profile],
191 190 ]
192 191 end
193 192  
... ... @@ -237,7 +236,7 @@ module ApplicationHelper
237 236 # Current implementation generates a <label> tag for +label+ and wrap the
238 237 # label and the control with a <div> tag with class 'formfield'
239 238 def display_form_field(label, html_for_field)
240   - content_tag('div', content_tag('div', content_tag('label', label)) + html_for_field, :class => 'formfield')
  239 + content_tag('div', content_tag('div', content_tag('label', label)) +html_for_field, :class => 'formfield')
241 240 end
242 241  
243 242 alias_method :labelled_form_field, :display_form_field
... ...
app/models/person.rb
... ... @@ -52,4 +52,12 @@ class Person &lt; Profile
52 52 def email
53 53 self.user.nil? ? nil : self.user.email
54 54 end
  55 +
  56 + def is_admin?
  57 + role_assignments.map{|ra|ra.role.permissions}.any? do |ps|
  58 + ps.any? do |p|
  59 + ActiveRecord::Base::PERMISSIONS[:environment].keys.include?(p)
  60 + end
  61 + end
  62 + end
55 63 end
... ...
app/views/role/edit.rhtml
1 1 <h2> <%= _("Editing #{@role.name}") %> </h2>
2 2  
3   -<%= render :partial => 'form', :locals => { :mode => :edit, :role => @role } %>
  3 +<%= render :partial => 'form', :locals => { :mode => :edit, :role => @role, :permissions => ActiveRecord::Base::PERMISSIONS[@role.kind] } %>
... ...
script/populate
1 1 #!/usr/bin/env ruby
2 2 require File.dirname(__FILE__) + '/../config/environment'
3 3  
  4 +anhetegua = Profile.create!(:name => 'anhetegua', :identifier => 'anhetegua')
  5 +
4 6 User.create!(:login => 'testprofile', :email => 'admin@localhost.localdomain', :password => 'test', :password_confirmation => 'test')
5 7 User.create!(:login => 'user', :email => 'user@localhost.localdomain', :password => 'user', :password_confirmation => 'user')
6 8 User.create!(:login => 'usuario', :email => 'usuario@localhost.localdomain', :password => 'usuario', :password_confirmation => 'usuario')
7   -User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test')
  9 +ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test')
  10 +root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root').person
  11 +
  12 +admin_role = Role.create!(:name => 'admin', :permissions => ['edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators'])
  13 +
  14 +RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => nil)
  15 +
  16 +empa = Enterprise.create!(:name => 'Empreendimento A', :identifier => 'empreendimento_a')
  17 +
  18 +owner_role = Role.create!(:name => 'owner', :permissions => ['edit_profile', 'destroy_profile', 'manage_memberships', 'post_content', 'edit_profile_design'])
8 19  
  20 +RoleAssignment.create!(:accessor => ze, :role => owner_role, :resource => empa)
  21 +RoleAssignment.create!(:accessor => root, :role => owner_role, :resource => anhetegua)
9 22  
... ...