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

Fix loading of concern

Klaus Zanders65f5232a4e53
diff --git a/app/controllers/concerns/shares/work_packages/authorization.rb b/app/controllers/concerns/shares/work_packages/authorization.rb
deleted file mode 100644
index 32b4bf5f34e..00000000000
--- a/app/controllers/concerns/shares/work_packages/authorization.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-# -- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2010-2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-# ++
-
-module Shares
- module WorkPackages
- module Authorization
- extend ActiveSupport::Concern
-
- included do
- def sharing_manageable?
- # TODO: Fix this to check based on the entity
- case @entity
- when WorkPackage
- User.current.allowed_in_project?(:share_work_packages, @entity.project)
- else
- raise ArgumentError, <<~ERROR
- Checking sharing capabilities for an unsupported entity:
- - #{@entity.class}
- ERROR
- end
- end
- end
- end
- end
-end
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb
index e7c22b313a3..a7305b639ea 100644
--- a/app/controllers/shares_controller.rb
+++ b/app/controllers/shares_controller.rb
@@ -29,16 +29,17 @@
class SharesController < ApplicationController
include OpTurbo::ComponentStream
include OpTurbo::DialogStreamHelper
- include Shares::WorkPackages::Authorization
include MemberHelper
before_action :load_entity
before_action :load_shares, only: %i[index dialog]
before_action :load_selected_shares, only: %i[bulk_update bulk_destroy]
before_action :load_share, only: %i[destroy update resend_invite]
- before_action :authorize
before_action :enterprise_check, only: %i[index]
+ # TODO: Permission checks need to be implemented correctly depending on entity
+ before_action :authorize
+
def dialog
@sharing_manageable = sharing_manageable?
@available_roles = available_roles
@@ -305,11 +306,16 @@ class SharesController < ApplicationController
def load_entity
@entity = if params["work_package_id"]
WorkPackage.visible.find(params["work_package_id"])
- # TODO: Add support for other entities
+ # TODO: Add support for other entities
+ elsif params["query_id"] && request.path.starts_with?("/projects/queries")
+ Queries::Projects::ProjectQuery.visible.find(params["query_id"])
else
raise ArgumentError, <<~ERROR
Nested the SharesController under an entity controller that is not yet configured to support sharing.
Edit the SharesController#load_entity method to load the entity from the correct parent.
+
+ Params: #{params.to_unsafe_h}
+ Request Path: #{request.path}
ERROR
end
@@ -381,4 +387,19 @@ class SharesController < ApplicationController
Shares::WorkPackages
end
end
+
+ def sharing_manageable?
+ # TODO: Fix this to check based on the entity
+ case @entity
+ when WorkPackage
+ User.current.allowed_in_project?(:share_work_packages, @entity.project)
+ when Queries::Projects::ProjectQuery
+ @entity.editable?
+ else
+ raise ArgumentError, <<~ERROR
+ Checking sharing capabilities for an unsupported entity:
+ - #{@entity.class}
+ ERROR
+ end
+ end
end
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index e4020a900f8..7c67b6aa1a6 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -39,7 +39,7 @@ See COPYRIGHT and LICENSE files for more details.
%>
<%= render(Projects::IndexSubHeaderComponent.new(query:, current_user:, disable_buttons: state === :rename)) %>
<%# TODO: Temporary %>
- <%- if @query %>
+ <%- if @query.persisted? %>
<%= render(Primer::Beta::Button.new(
tag: :a,
href: dialog_projects_query_members_path(@query),
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 8b4ab0de971..51abafd3c0b 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -331,7 +331,7 @@ Rails.application.reloader.to_prepare do
map.permission :share_work_packages,
{
members: %i[destroy_by_principal],
- shares: %i[index create destroy update resend_invite bulk_update bulk_destroy]
+ shares: %i[dialog index create destroy update resend_invite bulk_update bulk_destroy]
},
permissible_on: :project,
dependencies: %i[edit_work_packages view_shared_work_packages],
diff --git a/config/routes.rb b/config/routes.rb
index 10d63e1decb..515a3e592f1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -79,12 +79,13 @@ Rails.application.routes.draw do
# Shared route concerns
# TODO: Add description how to configure controller to support shares
concern :shareable do
- resources :members, path: :shares, controller: "shares", only: %i[index create update destroy] do
+ resources :members, path: "shares", controller: "shares", only: %i[index create update destroy] do
member do
post "resend_invite" => "shares#resend_invite"
end
collection do
+ get :dialog, to: "shares#dialog"
patch :bulk, to: "shares#bulk_update"
put :bulk, to: "shares#bulk_update"
delete :bulk, to: "shares#bulk_destroy"
@@ -537,7 +538,9 @@ Rails.application.routes.draw do
get "/bulk" => "bulk#destroy"
end
- resources :work_packages, only: [:index], concerns: [:shareable] do
+ resources :work_packages, only: [:index] do
+ concerns :shareable
+
# move bulk of wps
get "move/new" => "work_packages/moves#new", on: :collection, as: "new_move"
post "move" => "work_packages/moves#create", on: :collection, as: "move"