From d32845cc6eec74ff5bf3a6bf65e2e34b4b1813be Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Tue, 5 Oct 2021 04:33:47 +0800 Subject: [PATCH] extract controller base class --- app/controllers/stopwatch_controller.rb | 12 ++++++++++++ app/controllers/stopwatch_timers_controller.rb | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 app/controllers/stopwatch_controller.rb diff --git a/app/controllers/stopwatch_controller.rb b/app/controllers/stopwatch_controller.rb new file mode 100644 index 0000000..7ddf659 --- /dev/null +++ b/app/controllers/stopwatch_controller.rb @@ -0,0 +1,12 @@ +# base class for stopwatch controllers +class StopwatchController < ApplicationController + helper :timelog, :custom_fields + + before_action :require_login + + private + + def authorize_edit_time + @time_entry.editable_by?(User.current) or deny_access + end +end diff --git a/app/controllers/stopwatch_timers_controller.rb b/app/controllers/stopwatch_timers_controller.rb index 145793e..2408620 100644 --- a/app/controllers/stopwatch_timers_controller.rb +++ b/app/controllers/stopwatch_timers_controller.rb @@ -8,10 +8,8 @@ # - same for project, unless we are in a project context # - focus first field that needs an action, depending on above # -class StopwatchTimersController < ApplicationController - helper :timelog, :custom_fields +class StopwatchTimersController < StopwatchController - before_action :require_login before_action :find_optional_data, only: %i(new create) before_action :authorize_log_time, only: %i(new create start stop current) before_action :find_time_entry, only: %i(edit update start stop)