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

Fix publishing with more knowledge about Contracts

Klaus Zanders282d02b078c2
diff --git a/app/contracts/projects/queries/publish_contract.rb b/app/contracts/queries/projects/project_queries/publish_contract.rb
similarity index 82%
rename from app/contracts/projects/queries/publish_contract.rb
rename to app/contracts/queries/projects/project_queries/publish_contract.rb
index ccf53f5ff9b..98a9fe2844c 100644
--- a/app/contracts/projects/queries/publish_contract.rb
+++ b/app/contracts/queries/projects/project_queries/publish_contract.rb
@@ -26,14 +26,8 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Projects::Queries::PublishContract < BaseContract
- validate :allowed_to_modify_public_flag
-
- protected
-
- def allowed_to_modify_public_flag
- unless user.allowed_globally?(:manage_public_project_queries)
- errors.add :base, :error_unauthorized
- end
+module Queries::Projects::ProjectQueries
+ class PublishContract < BaseContract
+ attribute :public
end
end
diff --git a/app/services/queries/projects/project_queries/publish_service.rb b/app/services/queries/projects/project_queries/publish_service.rb
index ad68a1bc45d..e2c26fcda82 100644
--- a/app/services/queries/projects/project_queries/publish_service.rb
+++ b/app/services/queries/projects/project_queries/publish_service.rb
@@ -26,25 +26,24 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Queries::Projects::ProjectQueries::PublishService < BaseServices::BaseContracted
- include Contracted
+module Queries::Projects::ProjectQueries
+ class PublishService < BaseServices::Update
+ private
- def initialize(user:, model:, contract_class: Projects::Queries::PublishContract)
- super(user:, contract_class:)
- self.model = model
- end
-
- private
+ def after_validate(params, service_call)
+ model.public = params[:public]
- def after_validate(params, service_call)
- model.public = params[:public]
+ service_call
+ end
- service_call
- end
+ def persist(service_call)
+ model.save
- def persist(service_call)
- model.save
+ service_call
+ end
- service_call
+ def default_contract_class
+ Queries::Projects::ProjectQueries::PublishContract
+ end
end
end