Fixed time entries context menu display according permissions (#9405).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7922 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-11-24 21:31:21 +00:00
parent f436918dbe
commit 703211c0a6
3 changed files with 23 additions and 5 deletions

View File

@ -51,9 +51,8 @@ class ContextMenusController < ApplicationController
@projects = @time_entries.collect(&:project).compact.uniq @projects = @time_entries.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1 @project = @projects.first if @projects.size == 1
@activities = TimeEntryActivity.shared.active @activities = TimeEntryActivity.shared.active
@can = {:edit => User.current.allowed_to?(:log_time, @projects), @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
:update => User.current.allowed_to?(:log_time, @projects), :delete => User.current.allowed_to?(:edit_time_entries, @projects)
:delete => User.current.allowed_to?(:log_time, @projects)
} }
@back = back_url @back = back_url
render :layout => false render :layout => false

View File

@ -15,10 +15,10 @@
<ul> <ul>
<% @activities.each do |u| -%> <% @activities.each do |u| -%>
<li><%= context_menu_link h(u.name), {:controller => 'timelog', :action => 'bulk_edit', :ids => @time_entries.collect(&:id), :time_entry => {'activity_id' => u}, :back_url => @back}, :method => :post, <li><%= context_menu_link h(u.name), {:controller => 'timelog', :action => 'bulk_edit', :ids => @time_entries.collect(&:id), :time_entry => {'activity_id' => u}, :back_url => @back}, :method => :post,
:selected => (@time_entry && u == @time_entry.activity), :disabled => !@can[:update] %></li> :selected => (@time_entry && u == @time_entry.activity), :disabled => !@can[:edit] %></li>
<% end -%> <% end -%>
<li><%= context_menu_link l(:label_none), {:controller => 'timelog', :action => 'bulk_edit', :ids => @time_entries.collect(&:id), :time_entry => {'activity_id' => 'none'}, :back_url => @back}, :method => :post, <li><%= context_menu_link l(:label_none), {:controller => 'timelog', :action => 'bulk_edit', :ids => @time_entries.collect(&:id), :time_entry => {'activity_id' => 'none'}, :back_url => @back}, :method => :post,
:selected => (@time_entry && @time_entry.activity.nil?), :disabled => !@can[:update] %></li> :selected => (@time_entry && @time_entry.activity.nil?), :disabled => !@can[:edit] %></li>
</ul> </ul>
</li> </li>
<% end %> <% end %>

View File

@ -129,4 +129,23 @@ class ContextMenusControllerTest < ActionController::TestCase
assert_template 'context_menu' assert_template 'context_menu'
assert_equal [1], assigns(:issues).collect(&:id) assert_equal [1], assigns(:issues).collect(&:id)
end end
def test_time_entries_context_menu
@request.session[:user_id] = 2
get :time_entries, :ids => [1, 2]
assert_response :success
assert_template 'time_entries'
assert_tag 'a', :content => 'Edit'
assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
end
def test_time_entries_context_menu_without_edit_permission
@request.session[:user_id] = 2
Role.find_by_name('Manager').remove_permission! :edit_time_entries
get :time_entries, :ids => [1, 2]
assert_response :success
assert_template 'time_entries'
assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
end
end end