OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
extract finder stuff into before actions
Klaus Zandersd4ff3cb1c812
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex 9dbfdb6fdbc..1f6490febd4 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -32,29 +32,15 @@ class TimeEntriesController < ApplicationControllerbefore_action :require_login+ with_options only: [:dialog] do+ before_action :load_and_authorize_optional_project+ before_action :load_and_authorize_optional_work_package+ before_action :load_or_build_and_authorize_time_entry+ end+authorization_checked! :dialog, :create, :update, :user_tz_caption, :time_entry_activitiesdef dialog- if params[:project_id].present?- @project = begin- Project.visible.find(params[:project_id])- rescue ActiveRecord::NotFound- nil- end- end-- if params[:work_package_id].present?- @work_package = WorkPackage.visible.find_by(id: params[:work_package_id])- @project = @work_package.project- end-- @time_entry = if params[:time_entry_id]- # TODO: Properly handle authorization- TimeEntry.find_by(id: params[:time_entry_id])- else- TimeEntry.new(project: @project, work_package: @work_package, user: User.current)- end-if params[:date].present?@time_entry.spent_on = params[:date]end@@ -68,7 +54,7 @@ class TimeEntriesController < ApplicationController""end- add_caption_to_input_element_via_turbo_stream("input[name=\"time_entry[user_id]\"]",+ add_caption_to_input_element_via_turbo_stream('input[name="time_entry[user_id]"]',caption:,clean_other_captions: true)respond_with_turbo_streams@@ -124,4 +110,32 @@ class TimeEntriesController < ApplicationControllerrespond_with_turbo_streamsendend++ private++ def load_and_authorize_optional_project+ if params[:project_id].present?+ @project = Project.visible.find(params[:project_id])+ # TODO: Authorize+ end+ rescue ActiveRecord::NotFound+ # noop+ end++ def load_and_authorize_optional_work_package+ if params[:work_package_id].present?+ @work_package = WorkPackage.visible.find_by(id: params[:work_package_id])+ @project = @work_package.project+ # TODO: Authorize+ end+ end++ def load_or_build_and_authorize_time_entry+ @time_entry = if params[:time_entry_id]+ # TODO: Properly handle authorization+ TimeEntry.find_by(id: params[:time_entry_id])+ else+ TimeEntry.new(project: @project, work_package: @work_package, user: User.current)+ end+ endend