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
Replace all allowed_to? calls in the API
Klaus Zanders49037c785779
diff --git a/lib/api/v3/queries/schemas/query_schema_representer.rb b/lib/api/v3/queries/schemas/query_schema_representer.rbindex f6791a977ad..5bfe00c0388 100644--- a/lib/api/v3/queries/schemas/query_schema_representer.rb+++ b/lib/api/v3/queries/schemas/query_schema_representer.rb@@ -88,11 +88,7 @@ module APIschema :public,type: 'Boolean',required: false,- writable: -> do- current_user.allowed_to?(:manage_public_queries,- represented.project,- global: represented.project.nil?)- end,+ writable: -> { allowed_to_manage_public_queries? },has_default: trueschema :sums,@@ -289,6 +285,14 @@ module APIapi_v3_paths.query_filter_instance_schemasendend++ def allowed_to_manage_public_queries?+ if represented.project+ current_user.allowed_in_project?(:manage_public_queries, represented.project)+ else+ current_user.allowed_in_any_project?(:manage_public_queries)+ end+ endendendenddiff --git a/lib/api/v3/work_packages/create_form_representer.rb b/lib/api/v3/work_packages/create_form_representer.rbindex aaa58a6c20c..ff7e05f7a2a 100644--- a/lib/api/v3/work_packages/create_form_representer.rb+++ b/lib/api/v3/work_packages/create_form_representer.rb@@ -54,8 +54,7 @@ module APIlink :commit doif represented.project &&- current_user.allowed_to?(:add_work_packages,- represented.project) &&+ current_user.allowed_in_project?(:add_work_packages, represented.project) &&@errors.empty?{href: api_v3_paths.work_packages,diff --git a/lib/api/v3/work_packages/create_project_form_representer.rb b/lib/api/v3/work_packages/create_project_form_representer.rbindex fa15c7b6b92..f0f15973949 100644--- a/lib/api/v3/work_packages/create_project_form_representer.rb+++ b/lib/api/v3/work_packages/create_project_form_representer.rb@@ -52,8 +52,7 @@ module APIendlink :commit do- if current_user- .allowed_to?(:edit_work_packages, represented.project) &&+ if current_user.allowed_in_project?(:edit_work_packages, represented.project) &&@errors.empty?{href: api_v3_paths.work_packages_by_project(represented.project_id),diff --git a/lib/api/v3/work_packages/update_form_representer.rb b/lib/api/v3/work_packages/update_form_representer.rbindex 168cbdd203d..764e10960ee 100644--- a/lib/api/v3/work_packages/update_form_representer.rb+++ b/lib/api/v3/work_packages/update_form_representer.rb@@ -52,7 +52,7 @@ module APIendlink :commit do- if current_user.allowed_to?(:edit_work_packages, represented.project) &&+ if current_user.allowed_in_project?(:edit_work_packages, represented.project) &&@errors.empty?{href: api_v3_paths.work_package(represented.id),diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex 7ff908b84f8..95242fed8c3 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -135,7 +135,10 @@ module APIendlinks :representations do- representation_formats if current_user.allowed_to?(:export_work_packages, project, global: project.nil?)+ if (project && current_user.allowed_in_project?(:export_work_packages, project)) ||+ (!project && current_user.allowed_in_any_project?(:export_work_packages))+ representation_formats+ endendcollection :elements,diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/comments/authorization_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/comments/authorization_representer.rbindex 6e1b50dc406..6bd1b7aae84 100644--- a/modules/bim/app/representers/bim/bcf/api/v2_1/comments/authorization_representer.rb+++ b/modules/bim/app/representers/bim/bcf/api/v2_1/comments/authorization_representer.rb@@ -38,7 +38,7 @@ module Bim::Bcf::API::V2_1}def manage_bcf_allowed?- represented.user.allowed_to?(:manage_bcf, represented.model.project)+ represented.user.allowed_in_project?(:manage_bcf, represented.model.project)endendenddiff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rbindex b94e3a8e262..0dd971eb58f 100644--- a/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb+++ b/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb@@ -101,7 +101,7 @@ module Bim::Bcf::API::V2_1enddef allowed?(permission)- represented.user.allowed_to?(permission, represented.model.project)+ represented.user.allowed_in_project?(permission, represented.model.project)endendenddiff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rbindex 86d6491714c..410878075e7 100644--- a/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb+++ b/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb@@ -47,7 +47,7 @@ module Bim::Bcf::API::V2_1}def manage_bcf_allowed?- represented.user.allowed_to?(:manage_bcf, represented.model.project)+ represented.user.allowed_in_project?(:manage_bcf, represented.model.project)endendenddiff --git a/modules/github_integration/lib/open_project/github_integration/patches/api/work_package_representer.rb b/modules/github_integration/lib/open_project/github_integration/patches/api/work_package_representer.rbindex e607bc296c4..c8b48ef5149 100644--- a/modules/github_integration/lib/open_project/github_integration/patches/api/work_package_representer.rb+++ b/modules/github_integration/lib/open_project/github_integration/patches/api/work_package_representer.rb@@ -7,7 +7,7 @@ module OpenProject::GithubIntegrationdef extension->(*) dolink :github,- cache_if: -> { current_user.allowed_to?(:show_github_content, represented.project) } do+ cache_if: -> { current_user.allowed_in_project?(:show_github_content, represented.project) } do{href: "#{work_package_path(id: represented.id)}/tabs/github",title: "github"diff --git a/modules/meeting/lib/open_project/meeting/patches/api/work_package_representer.rb b/modules/meeting/lib/open_project/meeting/patches/api/work_package_representer.rbindex 2b23dc6b1f7..1d420c39564 100644--- a/modules/meeting/lib/open_project/meeting/patches/api/work_package_representer.rb+++ b/modules/meeting/lib/open_project/meeting/patches/api/work_package_representer.rb@@ -7,7 +7,7 @@ module OpenProject::Meetingdef extension->(*) dolink :meetings,- cache_if: -> { current_user.allowed_to?(:view_meetings, represented.project) } do+ cache_if: -> { current_user.allowed_in_project?(:view_meetings, represented.project) } donext if represented.new_record?{diff --git a/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rbindex 95f8e4b5c65..18d7f06b5ce 100644--- a/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rb+++ b/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rb@@ -33,13 +33,13 @@ module APIextend ActiveSupport::Concernincluded do- link :fileLinks, cache_if: -> { current_user.allowed_to?(:view_file_links, represented.project) } do+ link :fileLinks, cache_if: -> { current_user.allowed_in_project?(:view_file_links, represented.project) } do{href: api_v3_paths.file_links(represented.id)}end- link :addFileLink, cache_if: -> { current_user.allowed_to?(:manage_file_links, represented.project) } do+ link :addFileLink, cache_if: -> { current_user.allowed_in_project?(:manage_file_links, represented.project) } do{href: api_v3_paths.file_links(represented.id),method: :post@@ -49,7 +49,7 @@ module APIproperty :file_links,embedded: true,exec_context: :decorator,- if: ->(*) { embed_links && current_user.allowed_to?(:view_file_links, represented.project) },+ if: ->(*) { embed_links && current_user.allowed_in_project?(:view_file_links, represented.project) },uncacheable: truedef file_linksdiff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rbindex 485167bad0e..6ae4ea7e252 100644--- a/modules/storages/lib/api/v3/file_links/file_link_representer.rb+++ b/modules/storages/lib/api/v3/file_links/file_link_representer.rb@@ -132,7 +132,7 @@ module API::V3::FileLinksprivatedef user_allowed_to_manage?(model)- model.container.present? && current_user.allowed_to?(:manage_file_links, model.project)+ model.container.present? && current_user.allowed_in_project?(:manage_file_links, model.project)enddef make_origin_data(model)diff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rbindex d82185dcec0..fa74f3c3f4e 100644--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb@@ -49,7 +49,7 @@ class API::V3::FileLinks::FileLinksAPI < API::OpenProjectAPI@file_link = Storages::FileLink.find(params[:file_link_id])unless @file_link.container.present? &&- current_user.allowed_to?(:view_file_links, @file_link.project) &&+ current_user.allowed_in_project?(:view_file_links, @file_link.project) &&@file_link.project.storage_ids.include?(@file_link.storage_id)raise ::API::Errors::NotFound.newenddiff --git a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rbindex 112f7632661..101a60b88b2 100644--- a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb+++ b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb@@ -43,7 +43,7 @@ class API::V3::FileLinks::WorkPackagesFileLinksAPI < API::OpenProjectAPIraise ::API::Errors::InvalidQuery.new(message)end- result = if current_user.allowed_to?(:view_file_links, @work_package.project)+ result = if current_user.allowed_in_project?(:view_file_links, @work_package.project)file_links = query.results.where(container_id: @work_package.id,container_type: 'WorkPackage',storage: @work_package.project.storages)diff --git a/modules/storages/lib/api/v3/project_storages/project_storages_api.rb b/modules/storages/lib/api/v3/project_storages/project_storages_api.rbindex 126461dc3e9..8793acbe659 100644--- a/modules/storages/lib/api/v3/project_storages/project_storages_api.rb+++ b/modules/storages/lib/api/v3/project_storages/project_storages_api.rb@@ -43,7 +43,7 @@ module API::V3::ProjectStoragesraise ::API::Errors::InvalidQuery.new(message)end- results = query.results.filter { |result| current_user.allowed_to?(:view_file_links, result.project) }+ results = query.results.filter { |result| current_user.allowed_in_project?(:view_file_links, result.project) }::API::V3::ProjectStorages::ProjectStorageCollectionRepresenter.new(results,@@ -57,7 +57,7 @@ module API::V3::ProjectStoragesafter_validation do@project_storage = Storages::ProjectStorage.find(params[:id])- unless current_user.allowed_to?(:view_file_links, @project_storage.project)+ unless current_user.allowed_in_project?(:view_file_links, @project_storage.project)raise ::API::Errors::NotFound.newendend