diff --git a/app/components/work_packages/share/invite_user_form_component.html.erb b/app/components/work_packages/share/invite_user_form_component.html.erb index 7ebdd0367dee..2cff37583ab6 100644 --- a/app/components/work_packages/share/invite_user_form_component.html.erb +++ b/app/components/work_packages/share/invite_user_form_component.html.erb @@ -3,7 +3,7 @@ if sharing_manageable? primer_form_with( model: new_share, - url: work_package_shares_path(@work_package), + url: url_for([@work_package, Member]), data: { controller: 'user-limit ' \ 'work-packages--share--user-selected', 'application-target': 'dynamic', diff --git a/app/components/work_packages/share/modal_body_component.rb b/app/components/work_packages/share/modal_body_component.rb index e8a3c661d94a..d3e59c2b11c2 100644 --- a/app/components/work_packages/share/modal_body_component.rb +++ b/app/components/work_packages/share/modal_body_component.rb @@ -108,7 +108,7 @@ def role_filter_option_active?(_option) end def filter_url(type_option: nil, role_option: nil) - return work_package_shares_path(@work_package) if type_option.nil? && role_option.nil? + return url_for([@work_package, Member]) if type_option.nil? && role_option.nil? args = {} filter = [] @@ -118,7 +118,7 @@ def filter_url(type_option: nil, role_option: nil) args[:filters] = filter.to_json unless filter.empty? - work_package_shares_path(@work_package, **args) + url_for([@work_package, Member, **args]) end def apply_role_filter(_option) diff --git a/app/components/work_packages/share/permission_button_component.rb b/app/components/work_packages/share/permission_button_component.rb index 8205a1d6b07e..07c8f242f8e1 100644 --- a/app/components/work_packages/share/permission_button_component.rb +++ b/app/components/work_packages/share/permission_button_component.rb @@ -45,7 +45,7 @@ def initialize(share:, **system_arguments) # or be passive and work like a select inside a form. def update_path if share.persisted? - work_packages_share_path(share) + url_for([share.entity, share]) end end diff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erb index ff4061b2ea69..539819842104 100644 --- a/app/components/work_packages/share/share_row_component.html.erb +++ b/app/components/work_packages/share/share_row_component.html.erb @@ -27,7 +27,7 @@ end user_row_grid.with_area(:remove, tag: :div) do - form_with url: work_packages_share_path(share), method: :delete do + form_with url: url_for([work_package, share]), method: :delete do render(Primer::Beta::IconButton.new(icon: "trash", type: :submit, scheme: :danger, diff --git a/app/components/work_packages/share/user_details_component.rb b/app/components/work_packages/share/user_details_component.rb index a9c549c78530..11c9b3fce510 100644 --- a/app/components/work_packages/share/user_details_component.rb +++ b/app/components/work_packages/share/user_details_component.rb @@ -78,7 +78,7 @@ def principal_show_path end def resend_invite_path - resend_invite_work_package_share_path(share.entity, share) + url_for([:resend_invite, share.entity, share]) end def user_is_a_group? diff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rb index c539a7185685..930f2fc8dfc6 100644 --- a/app/controllers/work_packages/shares_controller.rb +++ b/app/controllers/work_packages/shares_controller.rb @@ -30,7 +30,7 @@ class WorkPackages::SharesController < ApplicationController include OpTurbo::ComponentStream include MemberHelper - before_action :find_work_package, only: %i[index create resend_invite] + before_action :find_work_package, only: %i[index create destroy update resend_invite] before_action :find_share, only: %i[destroy update resend_invite] before_action :find_project before_action :authorize @@ -200,8 +200,7 @@ def find_work_package end def find_share - @share = Member.of_any_work_package.find(params[:id]) - @work_package = @share.entity + @share = @work_package.members.find(params[:id]) end def find_shares diff --git a/config/routes.rb b/config/routes.rb index 2c8206aceff0..8c273c0506c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -517,8 +517,6 @@ # FIXME: this is kind of evil!! We need to remove this soonest and # cover the functionality. Route is being used in work-package-service.js:331 get "/bulk" => "bulk#destroy" - - resources :shares, only: %i[destroy update] end resources :work_packages, only: [:index] do @@ -532,7 +530,7 @@ get "details/*state" => "work_packages#index", on: :collection, as: :details # Rails managed sharing route - resources :shares, controller: "work_packages/shares", only: %i[index create] do + resources :members, path: :shares, controller: "work_packages/shares", only: %i[index create update destroy] do member do post "resend_invite" => "work_packages/shares#resend_invite" end diff --git a/spec/routing/work_package/shares/bulk_spec.rb b/spec/routing/work_package/shares/bulk_spec.rb deleted file mode 100644 index f4c44164d347..000000000000 --- a/spec/routing/work_package/shares/bulk_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -# -- copyright -# OpenProject is an open source project management software. -# Copyright (C) 2023 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. -# ++ - -require "spec_helper" - -RSpec.describe "Work package bulk sharing routing" do - describe "DELETE /work_packages/:work_package_id/shares" do - it "routes to work_packages/shares/bulk#destroy" do - expect(delete("/work_packages/1/shares/bulk")) - .to route_to(controller: "work_packages/shares/bulk", - action: "destroy", - work_package_id: "1") - end - end - - describe "PATCH /work_packages/:work_package_id/shares" do - it "routes to work_packages/shares/bulk#update" do - expect(patch("/work_packages/1/shares/bulk")) - .to route_to(controller: "work_packages/shares/bulk", - action: "update", - work_package_id: "1") - end - end -end diff --git a/spec/routing/work_package/shares_spec.rb b/spec/routing/work_package/shares_spec.rb index 4231581980a8..61a7cd5d2f4f 100644 --- a/spec/routing/work_package/shares_spec.rb +++ b/spec/routing/work_package/shares_spec.rb @@ -29,15 +29,59 @@ require "spec_helper" RSpec.describe "work package share routes" do - it "connects DELETE /work_packages/shares/:id to work_packages/shares#delete" do - expect(delete("/work_packages/shares/5")).to route_to(controller: "work_packages/shares", - action: "destroy", - id: "5") + it "connects GET /work_packages/:wp_id/shares to work_packages/shares#index" do + expect(get("/work_packages/1/shares")).to route_to(controller: "work_packages/shares", + action: "index", + work_package_id: "1") end - it "connects PATCH /work_packages/shares/:id to work_packages/shares#update" do - expect(patch("/work_packages/shares/5")).to route_to(controller: "work_packages/shares", + it "connects POST /work_packages/:wp_id/shares to work_packages/shares#create" do + expect(post("/work_packages/1/shares")).to route_to(controller: "work_packages/shares", + action: "create", + work_package_id: "1") + end + + it "connects DELETE /work_packages/:wp_id/shares/:id to work_packages/shares#delete" do + expect(delete("/work_packages/1/shares/5")).to route_to(controller: "work_packages/shares", + action: "destroy", + id: "5", + work_package_id: "1") + end + + it "connects PATCH /work_packages/:wp_id/shares/:id to work_packages/shares#update" do + expect(patch("/work_packages/1/shares/5")).to route_to(controller: "work_packages/shares", + action: "update", + id: "5", + work_package_id: "1") + end + + it "connects PUT /work_packages/:wp_id/shares/:id to work_packages/shares#update" do + expect(put("/work_packages/1/shares/5")).to route_to(controller: "work_packages/shares", action: "update", - id: "5") + id: "5", + work_package_id: "1") + end + + it "connects POST /work_packages/:wp_id/shares/:id/resend_invite to work_packages/shares#resend_invite" do + expect(post("/work_packages/1/shares/5/resend_invite")).to route_to(controller: "work_packages/shares", + action: "resend_invite", + id: "5", + work_package_id: "1") + end + + context "on bulk actions" do + it "routes DELETE /work_packages/:work_package_id/shares/bulk to work_packages/shares/bulk#destroy" do + expect(delete("/work_packages/1/shares/bulk")) + .to route_to(controller: "work_packages/shares/bulk", + action: "destroy", + work_package_id: "1") + end + + it "routes PATCH /work_packages/:work_package_id/shares/bulk to work_packages/shares/bulk#update" do + expect(patch("/work_packages/1/shares/bulk")) + .to route_to(controller: "work_packages/shares/bulk", + action: "update", + work_package_id: "1") + end end end