From 00874d66c0dad13fcd378f724b95941917a4656e Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Mon, 8 Jun 2026 14:29:02 +0200 Subject: [PATCH] wip --- .../services/wikis/adapters/base_command.rb | 55 +++++++++++++++++++ .../internal/commands/create_page.rb | 50 +++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 modules/wikis/app/services/wikis/adapters/base_command.rb create mode 100644 modules/wikis/app/services/wikis/adapters/providers/internal/commands/create_page.rb diff --git a/modules/wikis/app/services/wikis/adapters/base_command.rb b/modules/wikis/app/services/wikis/adapters/base_command.rb new file mode 100644 index 00000000000..3066f6d276e --- /dev/null +++ b/modules/wikis/app/services/wikis/adapters/base_command.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) the OpenProject GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See COPYRIGHT and LICENSE files for more details. +#++ + +module Wikis::Adapters + class BaseCommand + include Dry::Monads[:result] + + attr_reader :provider + + def initialize(model:) + @provider = model + end + + def call(auth_strategy:, **) # rubocop:disable Lint/UnusedMethodArgument + raise SubclassResponsibilityError + end + + private + + def success(result) + Success(result) + end + + def failure(code:) + Failure(Results::Error.new(source: self.class, code:)) + end + end +end diff --git a/modules/wikis/app/services/wikis/adapters/providers/internal/commands/create_page.rb b/modules/wikis/app/services/wikis/adapters/providers/internal/commands/create_page.rb new file mode 100644 index 00000000000..cac48dab9d8 --- /dev/null +++ b/modules/wikis/app/services/wikis/adapters/providers/internal/commands/create_page.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) the OpenProject GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See COPYRIGHT and LICENSE files for more details. +#++ + +module Wikis + module Adapters + module Providers + module Internal + module Commands + class CreatePage < BaseCommand + def call(input_data:, auth_strategy:) + Adapters::Authentication[auth_strategy].call do |user| + wiki_page = WikiPage.visible(user).find_by(id: input_data.identifier) + return failure(code: :not_found) if wiki_page.nil? + + success(self.class.wiki_page_to_page_info(wiki_page, provider:)) + end + end + end + end + end + end + end +end