Commit 46cf13bf0a994daa8a353067422d4a1077d2afa5
1 parent
6a007a4b
Exists in
master
and in
22 other branches
ActionItem111: made the changes to allow the links be shown based on witch permissions the user have
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@724 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
16 changed files
with
182 additions
and
17 deletions
Show diff stats
app/controllers/environment_admin/environment_role_manager_controller.rb
0 → 100644
| @@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
| 1 | +class EnvironmentRoleManagerController < ApplicationController | ||
| 2 | + def index | ||
| 3 | + @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments ) | ||
| 4 | + end | ||
| 5 | + | ||
| 6 | + def change_roles | ||
| 7 | + @admin = Person.find(params[:id]) | ||
| 8 | + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } | ||
| 9 | + end | ||
| 10 | + | ||
| 11 | + def update_roles | ||
| 12 | + @roles = params[:roles] ? Role.find(params[:roles]) : [] | ||
| 13 | + @person = Person.find(params[:person]) | ||
| 14 | + if @person.define_roles(@roles, environment) | ||
| 15 | + flash[:notice] = _('Roles successfuly updated') | ||
| 16 | + else | ||
| 17 | + flash[:notice] = _('Couldn\'t change the roles') | ||
| 18 | + end | ||
| 19 | + redirect_to :action => :index | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + def change_role | ||
| 23 | + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } | ||
| 24 | + @admin = Person.find(params[:id]) | ||
| 25 | + @associations = RoleAssignment.find(:all, :conditions => {:accessor_id => @admin, | ||
| 26 | + :accessor_type => @admin.class.base_class.name, | ||
| 27 | + :resource_id => environment, | ||
| 28 | + :resource_type => environment.class.base_class.name}) | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + def add_role | ||
| 32 | + @person = Person.find(params[:person]) | ||
| 33 | + @role = Role.find(params[:role]) | ||
| 34 | + if environment.affiliate(@person, @role) | ||
| 35 | + redirect_to :action => 'index' | ||
| 36 | + else | ||
| 37 | + @admin = Person.find(params[:person]) | ||
| 38 | + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } | ||
| 39 | + render :action => 'affiliate' | ||
| 40 | + end | ||
| 41 | + end | ||
| 42 | + | ||
| 43 | + def remove_role | ||
| 44 | + @association = RoleAssignment.find(params[:id]) | ||
| 45 | + if @association.destroy | ||
| 46 | + flash[:notice] = _('Member succefully unassociated') | ||
| 47 | + else | ||
| 48 | + flash[:notice] = _('Failed to unassociate member') | ||
| 49 | + end | ||
| 50 | + redirect_to :aciton => 'index' | ||
| 51 | + end | ||
| 52 | + | ||
| 53 | + def unassociate | ||
| 54 | + @association = RoleAssignment.find(params[:id]) | ||
| 55 | + if @association.destroy | ||
| 56 | + flash[:notice] = _('Member succefully unassociated') | ||
| 57 | + else | ||
| 58 | + flash[:notice] = _('Failed to unassociate member') | ||
| 59 | + end | ||
| 60 | + redirect_to :aciton => 'index' | ||
| 61 | + end | ||
| 62 | + | ||
| 63 | + def make_admin | ||
| 64 | + @people = Person.find(:all) | ||
| 65 | + @roles = Role.find(:all).select{|r|r.has_kind?(:environment)} | ||
| 66 | + end | ||
| 67 | +end |
app/controllers/profile_admin/profile_members_controller.rb
| @@ -13,9 +13,9 @@ class ProfileMembersController < ProfileAdminController | @@ -13,9 +13,9 @@ class ProfileMembersController < ProfileAdminController | ||
| 13 | @roles = Role.find(params[:roles]) | 13 | @roles = Role.find(params[:roles]) |
| 14 | @person = Person.find(params[:person]) | 14 | @person = Person.find(params[:person]) |
| 15 | if @person.define_roles(@roles, profile) | 15 | if @person.define_roles(@roles, profile) |
| 16 | - flash[:notice] = 'Roles successfuly updated' | 16 | + flash[:notice] = _('Roles successfuly updated') |
| 17 | else | 17 | else |
| 18 | - flash[:notice] = 'Couldn\'t change the roles' | 18 | + flash[:notice] = _('Couldn\'t change the roles') |
| 19 | end | 19 | end |
| 20 | redirect_to :action => :index | 20 | redirect_to :action => :index |
| 21 | end | 21 | end |
app/controllers/public/account_controller.rb
| @@ -16,7 +16,8 @@ class AccountController < PublicController | @@ -16,7 +16,8 @@ class AccountController < PublicController | ||
| 16 | self.current_user.remember_me | 16 | self.current_user.remember_me |
| 17 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } | 17 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
| 18 | end | 18 | end |
| 19 | - redirect_back_or_default(:controller => '/account', :action => 'index') | 19 | +# redirect_back_or_default(:controller => '/account', :action => 'index') |
| 20 | + redirect_back_or_default(homepage_path(:profile => current_user.login)) | ||
| 20 | flash[:notice] = _("Logged in successfully") | 21 | flash[:notice] = _("Logged in successfully") |
| 21 | else | 22 | else |
| 22 | flash[:notice] = _('Incorrect username or password') | 23 | flash[:notice] = _('Incorrect username or password') |
app/helpers/application_helper.rb
| @@ -117,7 +117,8 @@ module ApplicationHelper | @@ -117,7 +117,8 @@ module ApplicationHelper | ||
| 117 | links = [ | 117 | links = [ |
| 118 | ( link_to_homepage(current_user.login) ), | 118 | ( link_to_homepage(current_user.login) ), |
| 119 | ( link_to(_('My account'), { :controller => 'account' }) ), | 119 | ( link_to(_('My account'), { :controller => 'account' }) ), |
| 120 | - ( link_to(_('Admin'), { :controller => 'admin_panel' }) ), | 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 | ].join("\n") | 122 | ].join("\n") |
| 122 | content_tag('span', links, :id => 'user_links') | 123 | content_tag('span', links, :id => 'user_links') |
| 123 | end | 124 | end |
| @@ -171,33 +172,47 @@ module ApplicationHelper | @@ -171,33 +172,47 @@ module ApplicationHelper | ||
| 171 | ] | 172 | ] |
| 172 | end | 173 | end |
| 173 | 174 | ||
| 174 | - def profile_links | 175 | + def person_links |
| 175 | links = [ | 176 | links = [ |
| 176 | [(link_to_myprofile _('Edit visual design'), :controller => 'profile_editor', :action => 'design_editor'), 'edit_profile_design', profile], | 177 | [(link_to_myprofile _('Edit visual design'), :controller => 'profile_editor', :action => 'design_editor'), 'edit_profile_design', profile], |
| 177 | - [(link_to_myprofile _('Edit informations'), :controller => 'profile_editor'), 'edit_profile', profile], | 178 | + [(link_to_myprofile _('Edit profile'), :controller => 'profile_editor'), 'edit_profile', profile], |
| 178 | [(link_to_myprofile _('Manage content'), :controller => 'cms'), 'post_content', profile], | 179 | [(link_to_myprofile _('Manage content'), :controller => 'cms'), 'post_content', profile], |
| 179 | ] | 180 | ] |
| 180 | 181 | ||
| 181 | - if profile.kind_of?(Enterprise) | ||
| 182 | - links << [(link_to_myprofile _('Exclude'), :controller => 'enterprise_editor', :action => 'destroy'), 'edit_profile', profile] | ||
| 183 | - else | ||
| 184 | - links | ||
| 185 | - end | 182 | + end |
| 183 | + | ||
| 184 | + | ||
| 185 | + def enterprise_links | ||
| 186 | + 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], | ||
| 191 | + ] | ||
| 186 | end | 192 | end |
| 187 | 193 | ||
| 188 | 194 | ||
| 189 | #FIXME: find a way of accessing environment from here | 195 | #FIXME: find a way of accessing environment from here |
| 190 | def user_options | 196 | def user_options |
| 197 | + profile = params[:profile] | ||
| 191 | case params[:controller] | 198 | case params[:controller] |
| 192 | when 'admin_panel' | 199 | when 'admin_panel' |
| 193 | admin_links | 200 | admin_links |
| 194 | when 'membership_editor' | 201 | when 'membership_editor' |
| 195 | membership_links | 202 | membership_links |
| 196 | when 'profile_editor' | 203 | when 'profile_editor' |
| 197 | - profile_links | 204 | + if profile.kind_of?(Enterprise) |
| 205 | + enterprise_links | ||
| 206 | + elsif profile.kind_of?(Person) | ||
| 207 | + person_links | ||
| 208 | + else | ||
| 209 | + [] | ||
| 210 | + end | ||
| 211 | + when 'content_viewer' | ||
| 212 | + person_links | ||
| 198 | else | 213 | else |
| 199 | [] | 214 | [] |
| 200 | - end.map{|l| link_if_permitted(l[0], l[1], l[3]) } | 215 | + end.map{|l| link_if_permitted(l[0], l[1], l[2]) } |
| 201 | end | 216 | end |
| 202 | 217 | ||
| 203 | def footer | 218 | def footer |
| @@ -281,5 +296,4 @@ module ApplicationHelper | @@ -281,5 +296,4 @@ module ApplicationHelper | ||
| 281 | ] | 296 | ] |
| 282 | select_tag "#{object}[#{method}]", options_for_select(options, @page.filter_type || Comatose.config.default_filter), { :id=> "#{object}_#{method}" }.merge(html_options) | 297 | select_tag "#{object}[#{method}]", options_for_select(options, @page.filter_type || Comatose.config.default_filter), { :id=> "#{object}_#{method}" }.merge(html_options) |
| 283 | end | 298 | end |
| 284 | - | ||
| 285 | end | 299 | end |
app/models/environment.rb
| @@ -3,6 +3,14 @@ | @@ -3,6 +3,14 @@ | ||
| 3 | # domains. | 3 | # domains. |
| 4 | class Environment < ActiveRecord::Base | 4 | class Environment < ActiveRecord::Base |
| 5 | 5 | ||
| 6 | + PERMISSIONS[:environment] = { | ||
| 7 | + 'edit_environment_features' => N_('Edit environment features'), | ||
| 8 | + 'edit_environment_design' => N_('Edit environment design'), | ||
| 9 | + 'manage_environment_categories' => N_('Manage environment categories'), | ||
| 10 | + 'manage_environment_roles' => N_('Manage environment roles'), | ||
| 11 | + 'manage_environment_validators' => N_('Manage environment validators'), | ||
| 12 | + } | ||
| 13 | + | ||
| 6 | # returns the available features for a Environment, in the form of a | 14 | # returns the available features for a Environment, in the form of a |
| 7 | # hash, with pairs in the form <tt>'feature_name' => 'Feature name'</tt>. | 15 | # hash, with pairs in the form <tt>'feature_name' => 'Feature name'</tt>. |
| 8 | def self.available_features | 16 | def self.available_features |
app/models/profile.rb
| @@ -8,6 +8,7 @@ class Profile < ActiveRecord::Base | @@ -8,6 +8,7 @@ class Profile < ActiveRecord::Base | ||
| 8 | 'destroy_profile' => N_('Destroy profile'), | 8 | 'destroy_profile' => N_('Destroy profile'), |
| 9 | 'manage_memberships' => N_('Manage memberships'), | 9 | 'manage_memberships' => N_('Manage memberships'), |
| 10 | 'post_content' => N_('Post content'), | 10 | 'post_content' => N_('Post content'), |
| 11 | + 'edit_profile_design' => N_('Edit profile design'), | ||
| 11 | } | 12 | } |
| 12 | 13 | ||
| 13 | after_create do |profile| | 14 | after_create do |profile| |
| @@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
| 1 | +<h2> <%= @member.name %> </h2> | ||
| 2 | + | ||
| 3 | +<% form_tag( {:action => 'give_role'}, {:method => :post}) do %> | ||
| 4 | + <%= select_tag 'role', options_for_select(@roles.map{|r|[r.name,r.id]}) %> | ||
| 5 | + <%= hidden_field_tag 'person', current_user.person.id %> | ||
| 6 | + <%= submit_tag _('Affiliate') %> | ||
| 7 | +<% end %> | ||
| 8 | + | ||
| 9 | +<%= link_to _('Back'), :action => 'index' %> |
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +<%= _('Changing role of %s') % @admin.name %> | ||
| 2 | + | ||
| 3 | +<% labelled_form_for :member, @admin, :url => {:action => 'update_roles'} do |f| %> | ||
| 4 | + | ||
| 5 | + <%= _('Roles: ') %> <br> | ||
| 6 | + <% @roles.each do |r| %> | ||
| 7 | + <%= labelled_form_field(r.name, (check_box_tag "roles[]", r.id, @admin.role_assignments.map{|ra|ra.role}.include?(r))) %> | ||
| 8 | + <% end %> | ||
| 9 | + <%= hidden_field_tag 'person', @admin.id %> | ||
| 10 | + | ||
| 11 | + <%= submit_tag _('Save changes') %> | ||
| 12 | + <%= link_to _('Cancel'), :action => 'index' %> | ||
| 13 | +<% end %> |
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +<h2> <%= _('Listing Administrators') %> </h2> | ||
| 2 | + | ||
| 3 | +<%= link_to _('Make new admin'), :action => 'make_admin' %> | ||
| 4 | + | ||
| 5 | +<ul> | ||
| 6 | + <% @admins.each do |a| %> | ||
| 7 | + <li> <%= a.name %> | ||
| 8 | + <%= link_to _('Edit member role'), :action => 'change_role', :id => a %> | ||
| 9 | + <%= link_to _('Remove member'), :action => 'unassociate', :id => a %></li> | ||
| 10 | + <% end %> | ||
| 11 | +</ul> | ||
| 12 | + | ||
| 13 | +<%= link_to _('Back'), :controller => 'admin_panel' %> |
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +<h2> <% _('Make new admin') %> </h2> | ||
| 2 | + | ||
| 3 | +<% labelled_form_for :person, @person, :url => {:action => 'update_roles'} do |f| %> | ||
| 4 | + <%= _('Admin') %> <br> | ||
| 5 | + <% @people.each do |p| %> | ||
| 6 | + <%= labelled_form_field(p.name, (radio_button_tag "person", p.id)) %> | ||
| 7 | + <% end %> | ||
| 8 | + <%= _('Roles: ') %> <br> | ||
| 9 | + <% @roles.each do |r| %> | ||
| 10 | + <%= labelled_form_field(r.name, (check_box_tag "roles[]", r.id)) %> | ||
| 11 | + <% end %> | ||
| 12 | +<%= submit_tag _('Make') %> | ||
| 13 | +<% end %> |
app/views/layouts/application.rhtml
| @@ -71,7 +71,7 @@ | @@ -71,7 +71,7 @@ | ||
| 71 | <%= @category.full_name %> | 71 | <%= @category.full_name %> |
| 72 | <% else @category %> | 72 | <% else @category %> |
| 73 | <div id='user_options'> | 73 | <div id='user_options'> |
| 74 | - <%= user_options %> | 74 | + <%= user_options.join(' ') %> |
| 75 | </div><!-- id='user_options' --> | 75 | </div><!-- id='user_options' --> |
| 76 | <% end %> | 76 | <% end %> |
| 77 | </div> | 77 | </div> |
app/views/role/_form.rhtml
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | <%= f.text_field :name %> | 5 | <%= f.text_field :name %> |
| 6 | 6 | ||
| 7 | <%= _('Permissions: ') %> <br> | 7 | <%= _('Permissions: ') %> <br> |
| 8 | - <% Profile::PERMISSIONS[:profile].keys.each do |p| %> | 8 | + <% permissions.keys.each do |p| %> |
| 9 | <%= labelled_form_field(permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> | 9 | <%= labelled_form_field(permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> |
| 10 | <% end %> | 10 | <% end %> |
| 11 | 11 |
app/views/role/new.rhtml
| 1 | <h2> <%= _('New Role') %> </h2> | 1 | <h2> <%= _('New Role') %> </h2> |
| 2 | 2 | ||
| 3 | -<%= render :partial => 'form', :locals => { :mode => :new } %> | 3 | +<% ActiveRecord::Base::PERMISSIONS.keys.each do |perm_class| %> |
| 4 | + <h3> <%= perm_class %> </h3> | ||
| 5 | + <%= render :partial => 'form', :locals => { :mode => :new, :permissions => ActiveRecord::Base::PERMISSIONS[perm_class] } %> | ||
| 6 | +<% end %> |
public/stylesheets/menu.css
test/functional/environment_role_manager_controller_test.rb
0 → 100644
| @@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | +require 'environment_role_manager_controller' | ||
| 3 | + | ||
| 4 | +# Re-raise errors caught by the controller. | ||
| 5 | +class EnvironmentRoleManagerController; def rescue_action(e) raise e end; end | ||
| 6 | + | ||
| 7 | +class EnvironmentRoleManagerControllerTest < Test::Unit::TestCase | ||
| 8 | + def setup | ||
| 9 | + @controller = EnvironmentRoleManagerController.new | ||
| 10 | + @request = ActionController::TestRequest.new | ||
| 11 | + @response = ActionController::TestResponse.new | ||
| 12 | + end | ||
| 13 | + | ||
| 14 | + # Replace this with your real tests. | ||
| 15 | + def test_truth | ||
| 16 | + assert true | ||
| 17 | + end | ||
| 18 | +end |