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

Correclty check permission in schema for WP representer

Klaus Zanders14116d2082c1
diff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
index 071dc445cad..fe72aa0c42c 100644
--- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
+++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
@@ -62,21 +62,21 @@ module API
opts, = args
opts[:attribute_group] = attribute_group property
- super property, **opts
+ super(property, **opts)
end
def schema_with_allowed_link(property, *args)
opts, = args
opts[:attribute_group] = attribute_group property
- super property, **opts
+ super(property, **opts)
end
def schema_with_allowed_collection(property, *args)
opts, = args
opts[:attribute_group] = attribute_group property
- super property, **opts
+ super(property, **opts)
end
end
@@ -168,9 +168,9 @@ module API
type: 'Duration',
required: false,
show_if: ->(*) {
- current_user.allowed_in_project?(:view_time_entries, represented.project) ||
- current_user.allowed_in_work_package?(:view_own_time_entries, represented)
- }
+ current_user.allowed_in_project?(:view_time_entries, represented.project) ||
+ current_user.allowed_in_any_work_package?(:view_own_time_entries, in_project: represented.project)
+ }
schema :percentage_done,
type: 'Integer',
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index 44c7cb1d92a..24b8e28dd41 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -573,7 +573,16 @@ module API
def view_time_entries_allowed?
@view_time_entries_allowed ||=
current_user.allowed_in_project?(:view_time_entries, represented.project) ||
- current_user.allowed_in_work_package?(:view_own_time_entries, represented)
+ view_own_time_entries_allowed?
+ end
+
+ def view_own_time_entries_allowed?
+ @view_own_time_entries_allowed ||= if represented.new_record?
+ current_user.allowed_in_any_work_package?(:view_own_time_entries,
+ in_project: represented.project)
+ else
+ current_user.allowed_in_work_package?(:view_own_time_entries, represented)
+ end
end
def log_time_allowed?