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

Render sharing modal for project lists

Aaron Contreras48a3aec64788
diff --git a/app/components/projects/index_page_header_component.html.erb b/app/components/projects/index_page_header_component.html.erb
index e7eda9f7fc0..63c90ec6b29 100644
--- a/app/components/projects/index_page_header_component.html.erb
+++ b/app/components/projects/index_page_header_component.html.erb
@@ -21,12 +21,16 @@
)
end
- header.with_action_icon_button(
- icon: "share-android",
- mobile_icon: "share-android",
- label: t(:label_share),
- data: { show_dialog_id: Projects::ExportListModalComponent::MODAL_ID }
- )
+ if query.persisted?
+ header.with_action_icon_button(
+ tag: :a,
+ href: dialog_project_query_members_path(query),
+ icon: "share-android",
+ mobile_icon: "share-android",
+ label: t(:label_share),
+ data: { controller: "async-dialog" }
+ )
+ end
header.with_action_menu(menu_arguments: {
anchor_align: :end
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb
index a7305b639ea..7e0e2d140b7 100644
--- a/app/controllers/shares_controller.rb
+++ b/app/controllers/shares_controller.rb
@@ -156,7 +156,7 @@ class SharesController < ApplicationController
create_contract_class: sharing_contract_scope::CreateContract,
update_contract_class: sharing_contract_scope::UpdateContract
)
- .call(entity: @entity, user_id:, role_ids:)
+ .call(entity: @entity, user_id:, role_ids:)
end
def respond_with_replace_modal
@@ -306,9 +306,8 @@ 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
- elsif params["query_id"] && request.path.starts_with?("/projects/queries")
- Queries::Projects::ProjectQuery.visible.find(params["query_id"])
+ elsif params["project_query_id"]
+ ProjectQuery.visible.find(params["project_query_id"])
else
raise ArgumentError, <<~ERROR
Nested the SharesController under an entity controller that is not yet configured to support sharing.
@@ -336,8 +335,8 @@ class SharesController < ApplicationController
return @query if defined?(@query)
@query = ParamsToQueryService
- .new(Member, current_user, query_class: Queries::Members::EntityMemberQuery)
- .call(params)
+ .new(Member, current_user, query_class: Queries::Members::EntityMemberQuery)
+ .call(params)
# Set default filter on the entity
@query.where("entity_id", "=", @entity.id)
@@ -377,7 +376,20 @@ class SharesController < ApplicationController
description: I18n.t("work_package.permissions.view_description"),
default: true }
]
+ elsif @entity.is_a?(ProjectQuery)
+ role_mapping = ProjectQueryRole.unscoped.pluck(:builtin, :id).to_h
+
+ [
+ { label: I18n.t("work_package.permissions.edit"),
+ value: role_mapping[Role::BUILTIN_PROJECT_QUERY_EDIT],
+ description: I18n.t("work_package.permissions.edit_description") },
+ { label: I18n.t("work_package.permissions.view"),
+ value: role_mapping[Role::BUILTIN_PROJECT_QUERY_VIEW],
+ description: I18n.t("work_package.permissions.view_description"),
+ default: true }
+ ]
else
+
[]
end
end
@@ -393,7 +405,7 @@ class SharesController < ApplicationController
case @entity
when WorkPackage
User.current.allowed_in_project?(:share_work_packages, @entity.project)
- when Queries::Projects::ProjectQuery
+ when ProjectQuery
@entity.editable?
else
raise ArgumentError, <<~ERROR
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 7c67b6aa1a6..a469acb90f2 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -38,17 +38,6 @@ See COPYRIGHT and LICENSE files for more details.
)
%>
<%= render(Projects::IndexSubHeaderComponent.new(query:, current_user:, disable_buttons: state === :rename)) %>
- <%# TODO: Temporary %>
- <%- if @query.persisted? %>
- <%= render(Primer::Beta::Button.new(
- tag: :a,
- href: dialog_projects_query_members_path(@query),
- data: { controller: "async-dialog" }
-)) do |button|
- "TEMP: SHARE"
-end
-%>
- <%- end%>
<%= render Projects::TableComponent.new(
query:,
current_user: current_user,
diff --git a/app/views/shares/dialog.turbo_stream.erb b/app/views/shares/dialog.turbo_stream.erb
new file mode 100644
index 00000000000..7ca4449da4b
--- /dev/null
+++ b/app/views/shares/dialog.turbo_stream.erb
@@ -0,0 +1,15 @@
+<%= turbo_stream.dialog do
+ render(Primer::Alpha::Dialog.new(title: t(:label_sharing),
+ id: 'share_list',
+ size: :xlarge)) do |d|
+ d.with_header(variant: :large)
+ d.with_body do
+ render(Shares::ModalBodyComponent.new(entity: @entity,
+ shares: @shares,
+ errors: @errors,
+ sharing_manageable: @sharing_manageable,
+ available_roles: @available_roles))
+ end
+ end
+end
+%>
diff --git a/app/views/sharing/dialog.turbo_stream.erb b/app/views/sharing/dialog.turbo_stream.erb
deleted file mode 100644
index 5f8b164eb98..00000000000
--- a/app/views/sharing/dialog.turbo_stream.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-<%= turbo_stream.dialog do
- render(Primer::Alpha::Dialog.new(title: t(:label_sharing),
- id: 'share_list')) do |d|
- d.with_header(variant: :large)
- d.with_body do
- render(Shares::ModalBodyComponent.new( entity: @entity, shares: @shares, errors: @errors, sharing_manageable: @sharing_manageable, available_roles: @available_roles))
- end
- end
-end
-%>
diff --git a/config/routes.rb b/config/routes.rb
index 515a3e592f1..4ee44cf9a21 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -197,6 +197,8 @@ Rails.application.routes.draw do
end
resources :project_queries, only: %i[show new create update destroy], controller: "projects/queries" do
+ concerns :shareable
+
member do
get :rename