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

Only add one endpoint to toggle public flag on product query

Klaus Zanders23990f04d41c
diff --git a/app/components/projects/index_page_header_component.html.erb b/app/components/projects/index_page_header_component.html.erb
index df5641ccd3e..8762ae35bd2 100644
--- a/app/components/projects/index_page_header_component.html.erb
+++ b/app/components/projects/index_page_header_component.html.erb
@@ -101,29 +101,6 @@
end
if query.persisted?
- # TODO: Remove section when the sharing modal is implemented (https://community.openproject.org/projects/openproject/work_packages/55163)
- if can_publish?
- if query.public?
- menu.with_item(
- label: t(:button_unpublish),
- scheme: :danger,
- href: unpublish_project_query_path(query),
- content_arguments: { data: { method: :post } }
- ) do |item|
- item.with_leading_visual_icon(icon: 'eye-closed')
- end
- else
- menu.with_item(
- label: t(:button_publish),
- scheme: :default,
- href: publish_project_query_path(query),
- content_arguments: { data: { method: :post } }
- ) do |item|
- item.with_leading_visual_icon(icon: 'eye')
- end
- end
- end
-
menu.with_item(
label: t(:button_delete),
scheme: :danger,
diff --git a/app/components/projects/index_page_header_component.rb b/app/components/projects/index_page_header_component.rb
index 6d4d5b12119..77b94c0b286 100644
--- a/app/components/projects/index_page_header_component.rb
+++ b/app/components/projects/index_page_header_component.rb
@@ -96,12 +96,6 @@ class Projects::IndexPageHeaderComponent < ApplicationComponent
end
end
- def can_publish?
- OpenProject::FeatureDecisions.project_list_sharing_active? &&
- current_user.allowed_globally?(:manage_public_project_queries) &&
- query.persisted?
- end
-
def show_state?
state == :show
end
diff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rb
index abbc67b2c4f..e1111712033 100644
--- a/app/controllers/projects/queries_controller.rb
+++ b/app/controllers/projects/queries_controller.rb
@@ -30,9 +30,9 @@ class Projects::QueriesController < ApplicationController
include Projects::QueryLoading
# No need for a more specific authorization check. That is carried out in the contracts.
- no_authorization_required! :show, :new, :create, :rename, :update, :publish, :unpublish, :destroy
+ no_authorization_required! :show, :new, :create, :rename, :update, :toggle_public, :destroy
before_action :require_login
- before_action :find_query, only: %i[show rename update destroy publish unpublish]
+ before_action :find_query, only: %i[show rename update destroy toggle_public]
before_action :build_query_or_deny_access, only: %i[new create]
current_menu_item [:new, :rename, :create, :update] do
@@ -71,20 +71,15 @@ class Projects::QueriesController < ApplicationController
render_result(call, success_i18n_key: "lists.update.success", error_i18n_key: "lists.update.failure")
end
- def publish
- call = Queries::Projects::ProjectQueries::PublishService
- .new(user: current_user, model: @query)
- .call(public: true)
-
- render_result(call, success_i18n_key: "lists.publish.success", error_i18n_key: "lists.publish.failure")
- end
+ def toggle_public
+ to_be_public = [email protected]?
+ i18n_key = to_be_public ? "lists.publish" : "lists.unpublish"
- def unpublish
call = Queries::Projects::ProjectQueries::PublishService
.new(user: current_user, model: @query)
- .call(public: false)
+ .call(public: to_be_public)
- render_result(call, success_i18n_key: "lists.unpublish.success", error_i18n_key: "lists.unpublish.failure")
+ render_result(call, success_i18n_key: "#{i18n_key}.success", error_i18n_key: "#{i18n_key}.failure")
end
def destroy
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 51abafd3c0b..89482abc2c2 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -180,7 +180,7 @@ Rails.application.reloader.to_prepare do
map.permission :manage_public_project_queries,
{
- "projects/queries": %i[publish unpublish]
+ "projects/queries": %i[toggle_public]
},
permissible_on: :global,
require: :loggedin,
diff --git a/config/routes.rb b/config/routes.rb
index 4ee44cf9a21..00cc6837a74 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -201,9 +201,7 @@ Rails.application.routes.draw do
member do
get :rename
-
- post :publish
- post :unpublish
+ post :toggle_public
end
end