Feature #3848 » 0001-Allow-the-current-user-to-record-the-time-spent-by-a.patch
| app/controllers/issues_controller.rb | ||
|---|---|---|
| 177 | 177 |
end |
| 178 | 178 | |
| 179 | 179 |
if request.post? |
| 180 |
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
| 180 |
if User.current.allowed_to?(:edit_time_entries, @project) |
|
| 181 |
user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i) |
|
| 182 |
else |
|
| 183 |
# TODO: Maybe I should throw an exception if the current user |
|
| 184 |
# tries to edit a time entry he is not allowed to. I don't |
|
| 185 |
# think it can happen with the actual flow. |
|
| 186 |
user = User.current |
|
| 187 |
end |
|
| 188 |
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => Date.today) |
|
| 181 | 189 |
@time_entry.attributes = params[:time_entry] |
| 182 | 190 |
attachments = attach_files(@issue, params[:attachments]) |
| 183 | 191 |
attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
|
| app/controllers/timelog_controller.rb | ||
|---|---|---|
| 195 | 195 |
|
| 196 | 196 |
def edit |
| 197 | 197 |
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current) |
| 198 |
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
| 198 |
if request.post? and User.current.allowed_to?(:edit_time_entries, @project) |
|
| 199 |
user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i) |
|
| 200 |
else |
|
| 201 |
# TODO: Maybe I should throw an exception if the current user |
|
| 202 |
# tries to edit a time entry he is not allowed to. I don't think |
|
| 203 |
# it can happen with the actual flow. |
|
| 204 |
user = User.current |
|
| 205 |
end |
|
| 206 |
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => Date.today) |
|
| 199 | 207 |
@time_entry.attributes = params[:time_entry] |
| 200 | 208 |
if request.post? and @time_entry.save |
| 201 | 209 |
flash[:notice] = l(:notice_successful_update) |
| app/helpers/timelog_helper.rb | ||
|---|---|---|
| 33 | 33 |
activities.each { |a| collection << [a.name, a.id] }
|
| 34 | 34 |
collection |
| 35 | 35 |
end |
| 36 | ||
| 37 |
def user_collection_for_select_options |
|
| 38 |
users = @projects = User.find(:all) |
|
| 39 |
collection = [] |
|
| 40 |
users.each { |a| collection << [a.name, a.id] if a.allowed_to?(:log_time, @project) }
|
|
| 41 |
collection |
|
| 42 |
end |
|
| 36 | 43 |
|
| 37 | 44 |
def select_hours(data, criteria, value) |
| 38 | 45 |
if value.to_s.empty? |
| app/views/issues/_edit.rhtml | ||
|---|---|---|
| 20 | 20 |
<% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %>
|
| 21 | 21 |
<div class="splitcontentleft"> |
| 22 | 22 |
<p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p> |
| 23 |
<% if User.current.allowed_to?(:edit_time_entries, @project) %> |
|
| 24 |
<p><%= time_entry.select :user_id, user_collection_for_select_options %></p> |
|
| 25 |
<% end %> |
|
| 23 | 26 |
</div> |
| 24 | 27 |
<div class="splitcontentright"> |
| 25 | 28 |
<p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p> |
| app/views/timelog/edit.rhtml | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
<div class="box"> |
| 8 | 8 |
<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>
|
| 9 |
<% if User.current.allowed_to?(:edit_time_entries, @project) %> |
|
| 10 |
<p> <%= f.select :user_id, user_collection_for_select_options, :required => true %> </p> |
|
| 11 |
<% end %> |
|
| 9 | 12 |
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
|
| 10 | 13 |
<p><%= f.text_field :hours, :size => 6, :required => true %></p> |
| 11 | 14 |
<p><%= f.text_field :comments, :size => 100 %></p> |