Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put all sharing functionality into the scoped route and an extractable route concern #15843

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions app/components/work_packages/share/modal_body_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/work_packages/shares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 0 additions & 51 deletions spec/routing/work_package/shares/bulk_spec.rb

This file was deleted.

58 changes: 51 additions & 7 deletions spec/routing/work_package/shares_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading