redmine_3_2_log_time_for_others.patch

Andor Tóth, 2016-07-29 13:25

Download (3.65 KB)

View differences:

./lib/redmine.rb 2016-07-29 12:14:58.165121070 +0200
126 126
    map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
127 127
    map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
128 128
    map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
129
    map.permission :log_foreign_time, {:timelog => [:new, :create]}, :require => :member
129 130
  end
130 131

  
131 132
  map.project_module :news do |map|
132
-- ./config/locales/en.yml.orig	2015-12-06 15:06:23.000000000 +0100
133
++ ./config/locales/en.yml	2016-07-29 12:14:10.875012095 +0200
......
472 472
  permission_edit_documents: Edit documents
473 473
  permission_delete_documents: Delete documents
474 474
  permission_manage_files: Manage files
475
  permission_log_foreign_time: Add time logs for other users
475 476
  permission_view_files: View files
476 477
  permission_manage_wiki: Manage wiki
477 478
  permission_rename_wiki_pages: Rename wiki pages
478
-- ./app/views/timelog/_form.html.erb.orig	2016-07-29 12:13:05.212249291 +0200
479
++ ./app/views/timelog/_form.html.erb	2016-07-29 12:12:56.804407709 +0200
......
19 19
  </p>
20 20
  <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
21 21
  <p><%= f.text_field :hours, :size => 6, :required => true %></p>
22
  <% if User.current.allowed_to?(:log_foreign_time, @project) %>
23
  <p><%= f.select :user_id, user_collection_for_select_options(@project, @time_entry.user), :required => true %></p>
24
  <% end %>
22 25
  <p><%= f.text_field :comments, :size => 100, :maxlength => 1024 %></p>
23 26
  <p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
24 27
  <% @time_entry.custom_field_values.each do |value| %>
25
-- ./app/helpers/timelog_helper.rb.orig	2015-12-06 15:06:18.000000000 +0100
28
++ ./app/helpers/timelog_helper.rb	2016-07-29 12:16:55.200915920 +0200
......
56 56
    collection
57 57
  end
58 58

  
59
  def user_collection_for_select_options(project, selected = nil)
60
    collection = project.members.map{ |member| member.user }
61
    collection.keep_if{ |user| user.allowed_to?(:log_time, project) }
62
    s = ''
63
    s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id) if User.current.admin? || collection.include?(User.current)
64
    collection.sort.each do |element|
65
      selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)
66
      s << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
67
    end
68
    s.html_safe
69
  end
70

  
59 71
  def select_hours(data, criteria, value)
60 72
    if value.to_s.empty?
61 73
      data.select {|row| row[criteria].blank? }
62
-- ./app/controllers/timelog_controller.rb.orig	2015-12-06 15:06:19.000000000 +0100
74
++ ./app/controllers/timelog_controller.rb	2016-07-29 12:05:37.046693478 +0200
......
100 100
  end
101 101

  
102 102
  def create
103
    @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
103
    if request.post? and User.current.allowed_to?(:log_foreign_time, @project)
104
      user = User.find(params[:time_entry][:user_id])
105
    else
106
      user = User.current
107
    end
108
    @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => User.current.today)
104 109
    @time_entry.safe_attributes = params[:time_entry]
105 110
    if @time_entry.project && !User.current.allowed_to?(:log_time, @time_entry.project)
106 111
      render_403