Project

General

Profile

Feature #3848 » Allow-the-current-user-to-record-the-time-spent-0.9.3.patch

For redmine-0.9.3 - Oleg Volkov, 2010-03-14 09:11

View differences:

redmine/app/controllers/issues_controller.rb 2010-03-14 10:51:35.847313790 +0300
end
if request.post?
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
if User.current.allowed_to?(:edit_time_entries, @project) and params[:time_entry]
user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i)
else
# TODO: Maybe I should throw an exception if the current user
# tries to edit a time entry he is not allowed to. I don't
# think it can happen with the actual flow.
user = User.current
end
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => Date.today)
@time_entry.attributes = params[:time_entry]
if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid?
attachments = attach_files(@issue, params[:attachments])
redmine/app/controllers/timelog_controller.rb 2010-03-14 10:52:21.161752414 +0300
def edit
(render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
@time_entry.attributes = params[:time_entry]
if request.post? and User.current.allowed_to?(:edit_time_entries, @project)
user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i)
else
# TODO: Maybe I should throw an exception if the current user
# tries to edit a time entry he is not allowed to. I don't think
# it can happen with the actual flow.
user = User.current
end
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => User.current.today)
@time_entry.send(:attributes=, params[:time_entry], false)
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
redmine/app/helpers/timelog_helper.rb 2010-03-14 10:43:55.418369147 +0300
activities.each { |a| collection << [a.name, a.id] }
collection
end
def user_collection_for_select_options
users = @projects = User.find(:all)
collection = []
users.each { |a| collection << [a.name, a.id] if a.allowed_to?(:log_time, @project) }
collection
end
def select_hours(data, criteria, value)
if value.to_s.empty?
redmine/app/views/issues/_edit.rhtml 2010-03-14 10:48:21.554871727 +0300
<% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %>
<div class="splitcontentleft">
<p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p>
<% if User.current.allowed_to?(:edit_time_entries, @project) %>
<p><%= time_entry.select :user_id, user_collection_for_select_options %></p>
<% end %>
</div>
<div class="splitcontentright">
<p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p>
redmine/app/views/timelog/edit.rhtml 2010-03-14 11:01:31.816092433 +0300
<div class="box">
<p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
<% if User.current.allowed_to?(:edit_time_entries, @project) %>
<p> <%= f.select :user_id, user_collection_for_select_options, :required => true %> </p>
<% end %>
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
<p><%= f.text_field :hours, :size => 6, :required => true %></p>
<p><%= f.text_field :comments, :size => 100 %></p>
(6-6/21)