diff --git a/modules/wikis/app/controllers/wikis/admin/internal_wiki_provider_controller.rb b/modules/wikis/app/controllers/wikis/admin/internal_wiki_provider_controller.rb new file mode 100644 index 000000000000..babc03aebc6f --- /dev/null +++ b/modules/wikis/app/controllers/wikis/admin/internal_wiki_provider_controller.rb @@ -0,0 +1,57 @@ +# 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 Admin + class InternalWikiProviderController < ApplicationController + layout "admin" + + before_action :require_admin + + menu_item :internal_wiki_provider + + def show + @provider = Wikis::InternalProvider.first + end + + def update + provider = Wikis::InternalProvider.first + provider.update!(enabled: internal_provider_params[:enabled]) + redirect_to admin_settings_internal_wiki_provider_path + end + + private + + def internal_provider_params + params.expect(wikis_internal_provider: :enabled) + end + end + end +end diff --git a/modules/wikis/app/controllers/wikis/admin/wiki_providers_controller.rb b/modules/wikis/app/controllers/wikis/admin/wiki_providers_controller.rb index e509182c55eb..0475bf0ce382 100644 --- a/modules/wikis/app/controllers/wikis/admin/wiki_providers_controller.rb +++ b/modules/wikis/app/controllers/wikis/admin/wiki_providers_controller.rb @@ -39,7 +39,7 @@ class WikiProvidersController < ApplicationController before_action :require_admin before_action :find_wiki_provider, only: %i[edit update destroy confirm_destroy edit_general_info replace_oauth_application] - menu_item :wiki_providers + menu_item :external_wiki_providers def index @wiki_providers = editable_wiki_providers diff --git a/modules/wikis/app/forms/wikis/admin/internal_provider_form.rb b/modules/wikis/app/forms/wikis/admin/internal_provider_form.rb new file mode 100644 index 000000000000..61e7e8df168c --- /dev/null +++ b/modules/wikis/app/forms/wikis/admin/internal_provider_form.rb @@ -0,0 +1,43 @@ +# 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::Admin + class InternalProviderForm < ApplicationForm + form do |f| + f.check_box( + name: :enabled, + label: I18n.t("wikis.admin.internal_provider_form.checkbox_label"), + caption: I18n.t("wikis.admin.internal_provider_form.checkbox_caption") + ) + + f.submit(name: :save, label: I18n.t("button_save"), scheme: :primary) + end + end +end diff --git a/modules/wikis/app/seeders/basic_data/wikis/internal_provider_seeder.rb b/modules/wikis/app/seeders/basic_data/wikis/internal_provider_seeder.rb new file mode 100644 index 000000000000..639c93f5d539 --- /dev/null +++ b/modules/wikis/app/seeders/basic_data/wikis/internal_provider_seeder.rb @@ -0,0 +1,43 @@ +# 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 BasicData + module Wikis + class InternalProviderSeeder < Seeder + def seed_data! + ::Wikis::InternalProvider.create!(universal_identifier: "internal", name: "internal", enabled: true) + end + + def applicable? + !::Wikis::InternalProvider.exists? + end + end + end +end diff --git a/modules/wikis/app/views/wikis/admin/internal_wiki_provider/show.html.erb b/modules/wikis/app/views/wikis/admin/internal_wiki_provider/show.html.erb new file mode 100644 index 000000000000..bff9216d6a91 --- /dev/null +++ b/modules/wikis/app/views/wikis/admin/internal_wiki_provider/show.html.erb @@ -0,0 +1,48 @@ +<%#-- 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. + +++#%> + +<% html_title t(:label_administration), Wikis::InternalProvider.model_name.human %> + +<% content_for :content_header do %> + <%= render(Primer::OpenProject::PageHeader.new) do |header| %> + <% header.with_title { Wikis::InternalProvider.model_name.human } %> + <% header.with_description { t(".description") } %> + <% header.with_breadcrumbs([ + { href: admin_index_path, text: t(:label_administration) }, + { href: admin_settings_wiki_providers_path, text: t("menus.admin.wikis") }, + Wikis::InternalProvider.model_name.human + ]) %> + <% end %> +<% end %> + +<%= + primer_form_with(model: @provider, url: admin_settings_internal_wiki_provider_path) do |form| + render(Wikis::Admin::InternalProviderForm.new(form)) + end +%> diff --git a/modules/wikis/app/views/wikis/admin/wiki_providers/edit.html.erb b/modules/wikis/app/views/wikis/admin/wiki_providers/edit.html.erb index b8afd7cbb115..a2c995b122fa 100644 --- a/modules/wikis/app/views/wikis/admin/wiki_providers/edit.html.erb +++ b/modules/wikis/app/views/wikis/admin/wiki_providers/edit.html.erb @@ -43,6 +43,7 @@ See COPYRIGHT and LICENSE files for more details. header.with_breadcrumbs( [ { href: admin_index_path, text: t(:label_administration) }, + { href: admin_settings_wiki_providers_path, text: t("menus.admin.wikis") }, { href: admin_settings_wiki_providers_path, text: t(:project_module_wiki_platforms) }, page_title ] diff --git a/modules/wikis/app/views/wikis/admin/wiki_providers/index.html.erb b/modules/wikis/app/views/wikis/admin/wiki_providers/index.html.erb index fb08ec6d2e51..51dcb9214296 100644 --- a/modules/wikis/app/views/wikis/admin/wiki_providers/index.html.erb +++ b/modules/wikis/app/views/wikis/admin/wiki_providers/index.html.erb @@ -35,6 +35,7 @@ See COPYRIGHT and LICENSE files for more details. <% header.with_description { t("wikis.admin.wiki_providers.index_description") } %> <% header.with_breadcrumbs([ { href: admin_index_path, text: t(:label_administration) }, + { href: admin_settings_wiki_providers_path, text: t("menus.admin.wikis") }, t(:project_module_wiki_platforms) ]) %> <% end %> diff --git a/modules/wikis/app/views/wikis/admin/wiki_providers/new.html.erb b/modules/wikis/app/views/wikis/admin/wiki_providers/new.html.erb index 9128d2f50de7..eeefe9627261 100644 --- a/modules/wikis/app/views/wikis/admin/wiki_providers/new.html.erb +++ b/modules/wikis/app/views/wikis/admin/wiki_providers/new.html.erb @@ -36,6 +36,7 @@ See COPYRIGHT and LICENSE files for more details. <% header.with_breadcrumbs([ { href: admin_index_path, text: t(:label_administration) }, + { href: admin_settings_wiki_providers_path, text: t("menus.admin.wikis") }, { href: admin_settings_wiki_providers_path, text: t(:project_module_wiki_platforms) }, t("wikis.admin.wiki_providers.label_new_provider") ]) %> diff --git a/modules/wikis/config/locales/en.yml b/modules/wikis/config/locales/en.yml index 3f2d66317e40..909e0cbcab8f 100644 --- a/modules/wikis/config/locales/en.yml +++ b/modules/wikis/config/locales/en.yml @@ -31,6 +31,11 @@ en: wikis/xwiki_provider: one: XWiki provider other: XWiki providers + menus: + admin: + external_wiki_providers: Wiki providers + internal_wiki_provider: Internal wiki + wikis: "Wikis" permission_manage_wiki_page_links: Manage Wiki Page Links project_module_wiki_platforms: Wiki providers wikis: @@ -113,6 +118,12 @@ en: no_health_report: No report available no_health_report_description: Run the checks now for a full health status report for this wiki provider. title: Health Report + internal_provider_form: + checkbox_caption: Allow projects to use the internal OpenProject wiki along with external Wiki providers + checkbox_label: Enable the internal OpenProject wiki + internal_wiki_provider: + show: + description: Choose to enable or disable the internal OpenProject wiki oauth_application_info_component: confirm_replace_oauth_application: This action will reset the current OAuth credentials. After confirming you will have to reenter the credentials in your XWiki instance and all users will have to reauthorize. Are you sure you want to proceed? label_oauth_client_id: OAuth Client ID diff --git a/modules/wikis/config/routes.rb b/modules/wikis/config/routes.rb index 963162be7298..3c46a204401e 100644 --- a/modules/wikis/config/routes.rb +++ b/modules/wikis/config/routes.rb @@ -31,6 +31,7 @@ Rails.application.routes.draw do namespace :admin do namespace :settings do + resource :internal_wiki_provider, controller: "/wikis/admin/internal_wiki_provider", only: %i[show update] resources :wiki_providers, controller: "/wikis/admin/wiki_providers", except: [:show] do member do get :confirm_destroy diff --git a/modules/wikis/lib/open_project/wikis/engine.rb b/modules/wikis/lib/open_project/wikis/engine.rb index a8ce614c2cb3..350f335a883c 100644 --- a/modules/wikis/lib/open_project/wikis/engine.rb +++ b/modules/wikis/lib/open_project/wikis/engine.rb @@ -94,9 +94,23 @@ class Engine < ::Rails::Engine menu :admin_menu, :wiki_providers, { controller: "/wikis/admin/wiki_providers", action: :index }, - if: ->(_) { OpenProject::FeatureDecisions.wiki_enhancements_active? }, - caption: :project_module_wiki_platforms, + if: ->(_) { User.current.admin? && OpenProject::FeatureDecisions.wiki_enhancements_active? }, + caption: :"menus.admin.wikis", icon: :book + + menu :admin_menu, + :internal_wiki_provider, + { controller: "/wikis/admin/internal_wiki_provider", action: :show }, + parent: :wiki_providers, + if: ->(_) { User.current.admin? && OpenProject::FeatureDecisions.wiki_enhancements_active? }, + caption: :"menus.admin.internal_wiki_provider" + + menu :admin_menu, + :external_wiki_providers, + { controller: "/wikis/admin/wiki_providers", action: :index }, + parent: :wiki_providers, + if: ->(_) { User.current.admin? && OpenProject::FeatureDecisions.wiki_enhancements_active? }, + caption: :"menus.admin.external_wiki_providers" end patch_with_namespace :WikiPages, :CreateService diff --git a/modules/wikis/spec/features/admin/internal_provider_spec.rb b/modules/wikis/spec/features/admin/internal_provider_spec.rb new file mode 100644 index 000000000000..d3a7c68f6df9 --- /dev/null +++ b/modules/wikis/spec/features/admin/internal_provider_spec.rb @@ -0,0 +1,63 @@ +# 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. +#++ + +require "spec_helper" + +RSpec.describe "Updating internal wiki provider", :js, :selenium, driver: :firefox_en do + shared_let(:admin) { create(:admin, preferences: { time_zone: "Etc/UTC" }) } + shared_let(:auth_provider) { create(:oidc_provider) } + + let!(:provider) { create(:internal_wiki_provider, enabled: true) } + + current_user { admin } + + it "can enable and disable the internal provider", :aggregate_failures, with_ee: [:scim_api] do + visit admin_settings_internal_wiki_provider_path + expect(page).to be_axe_clean.within("#content") + + expect(page).to have_checked_field("Enable the internal OpenProject wiki") + + uncheck "Enable the internal OpenProject wiki" + click_on "Save" + + SeleniumHubWaiter.wait + + expect(page).to have_unchecked_field("Enable the internal OpenProject wiki") + expect(provider.reload).not_to be_enabled + + check "Enable the internal OpenProject wiki" + click_on "Save" + + SeleniumHubWaiter.wait + + expect(page).to have_checked_field("Enable the internal OpenProject wiki") + expect(provider.reload).to be_enabled + end +end