redmine_foreign_timelog.patch

Patrik Halfar, 2015-01-29 23:05

Download (3.07 KB)

View differences:

app/controllers/timelog_controller.rb
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
107
-- app/helpers/timelog_helper.rb
112
++ app/helpers/timelog_helper.rb
......
55 55
    collection
56 56
  end
57 57

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

  
58 70
  def select_hours(data, criteria, value)
59 71
    if value.to_s.empty?
60 72
      data.select {|row| row[criteria].blank? }
61
-- app/views/timelog/_form.html.erb
73
++ app/views/timelog/_form.html.erb
......
17 17
  </p>
18 18
  <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
19 19
  <p><%= f.text_field :hours, :size => 6, :required => true %></p>
20
  <% if User.current.allowed_to?(:log_foreign_time, @project) %>
21
  <p><%= f.select :user_id, user_collection_for_select_options(@project, @time_entry.user), :required => true %></p>
22
  <% end %>
20 23
  <p><%= f.text_field :comments, :size => 100, :maxlength => 255 %></p>
21 24
  <p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
22 25
  <% @time_entry.custom_field_values.each do |value| %>
23
-- config/locales/cs.yml
26
++ config/locales/cs.yml
......
424
  permission_log_foreign_time: Přidat stáveny čas jiným uživatelům
......
424
-- config/locales/en.yml
425
++ config/locales/en.yml
......
474
  permission_log_foreign_time: Add time logs for other users
......
474
-- lib/redmine.rb
475
++ lib/redmine.rb
......
131 131
    map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
132 132
    map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
133 133
    map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
134
    map.permission :log_foreign_time, {:timelog => [:new, :create]}, :require => :member
134 135
  end
135 136

  
136 137
  map.project_module :news do |map|