mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-11-17 19:50:36 -05:00
Running timers page with view/stop permissions
- New top-menu page listing running timers: owner, issue, project, activity, start time, time on this run and entry total, oldest first; refreshes every minute - Role permissions "View running timers" and "Stop other users' timers", checked against each timer's project; users can always stop their own - A timer can be stopped at an earlier time (when the person left): hours logged after it are taken off the entry, and the comment notes who stopped it and when - Timers now record when they were started (session_started_at); timers running from before show "unknown" until restarted - Integration tests for permissions, project scoping and stopping; unit tests for Timer#stop_for Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
11 files changed
+399
-1
No files matched your search
@@ -0,0 +1,49 @@
|
||||
# Lists everyone's running timers, and lets managers stop a timer someone forgot (optionally at the
|
||||
# time they actually stopped working).
|
||||
class StopwatchRunningTimersController < StopwatchController
|
||||
before_action :authorize_view
|
||||
|
||||
def index
|
||||
@rows = Stopwatch::RunningTimers.visible_to(User.current)
|
||||
end
|
||||
|
||||
def stop
|
||||
owner = User.find_by(id: params[:user_id])
|
||||
return render_404 unless owner
|
||||
|
||||
timer = Stopwatch::Timer.new(owner)
|
||||
unless timer.running?
|
||||
flash[:warning] = l(:notice_stopwatch_timer_not_running, name: owner.name)
|
||||
return redirect_to stopwatch_running_timers_path
|
||||
end
|
||||
|
||||
row = Stopwatch::RunningTimers::Row.new(user: owner, timer: timer, time_entry: timer.time_entry)
|
||||
return deny_access unless row.stoppable_by?(User.current)
|
||||
|
||||
stop_at = nil
|
||||
if params[:stopped_at].present?
|
||||
stop_at = parse_user_time(params[:stopped_at])
|
||||
unless stop_at
|
||||
flash[:error] = l(:error_stopwatch_invalid_stop_time)
|
||||
return redirect_to stopwatch_running_timers_path
|
||||
end
|
||||
end
|
||||
|
||||
hours = timer.stop_for(at: stop_at, by: User.current)
|
||||
flash[:notice] = l(:notice_stopwatch_timer_stopped_for, name: owner.name, hours: format_hours(hours.to_f))
|
||||
redirect_to stopwatch_running_timers_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authorize_view
|
||||
User.current.allowed_to?(:view_running_timers, nil, global: true) or deny_access
|
||||
end
|
||||
|
||||
# The "stopped at" field is a local date and time in the viewer's time zone
|
||||
def parse_user_time(value)
|
||||
(User.current.time_zone || Time.zone).parse(value.to_s)
|
||||
rescue ArgumentError
|
||||
nil
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user