Skip to content

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

add permission checks

Klaus Zandersb1c1709a446c
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rb
index 3ed26b37a86..94badab870a 100644
--- a/modules/costs/app/controllers/time_entries_controller.rb
+++ b/modules/costs/app/controllers/time_entries_controller.rb
@@ -146,24 +146,38 @@ class TimeEntriesController < ApplicationController
def load_and_authorize_optional_project
if params[:project_id].present?
@project = Project.visible.find(params[:project_id])
- # TODO: Authorize
+
+ if !User.current.allowed_in_project?(:log_time, @project) &&
+ !User.current.allowed_in_any_work_package?(:log_own_time, in_project: @project)
+ deny_access
+ end
+
end
rescue ActiveRecord::NotFound
- # noop
+ deny_access(not_found: true)
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
+
+ if !User.current.allowed_in_project?(:log_time, @project) &&
+ !User.current.allowed_in_work_package?(:log_own_time, @work_package)
+ deny_access
+ end
end
+ rescue ActiveRecord::NotFound
+ deny_access(not_found: true)
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])
+ TimeEntry.find_by(id: params[:time_entry_id]).tap do |entry|
+ if entry && !TimeEntries::UpdateContract.new(entry, current_user).user_allowed_to_update?
+ deny_access(not_found: true)
+ end
+ end
else
TimeEntry.new(project: @project, work_package: @work_package, user: User.current)
end