Skip to content

Commit

Permalink
Fix loading of concern
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher authored and aaron-contreras committed Jun 27, 2024
1 parent e453b0b commit 6dafc14
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 59 deletions.
52 changes: 0 additions & 52 deletions app/controllers/concerns/shares/work_packages/authorization.rb

This file was deleted.

27 changes: 24 additions & 3 deletions app/controllers/shares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -305,11 +306,16 @@ def respond_with_bulk_removed_shares
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

Expand Down Expand Up @@ -381,4 +387,19 @@ def sharing_contract_scope
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
2 changes: 1 addition & 1 deletion app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
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],
Expand Down
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@
# 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"
Expand Down Expand Up @@ -536,7 +537,9 @@
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"
Expand Down

0 comments on commit 6dafc14

Please sign in to comment.