Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ volumes:
tmp:
opdata:
bundle:
npm:
pgdata-test:
tmp-test:
fedata-test:
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/app/core/path-helper/path-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,11 @@ export class PathHelperService {
public externalRedirectPath(url:string) {
return `${this.staticBase}/external_redirect?url=${encodeURIComponent(url)}`;
}

public wikiPageLinkMacro(providerId:string, pageIdentifier:string, turboFrameId:string) {
const providerIdQuery = `provider_id=${encodeURIComponent(providerId)}`;
const pageIdentifierQuery = `page_identifier=${encodeURIComponent(pageIdentifier)}`;
const frameIdQuery = `turbo_frame_id=${encodeURIComponent(turboFrameId)}`;
return `${this.staticBase}/wiki_page_link_macro/load?${providerIdQuery}&${pageIdentifierQuery}&${frameIdQuery}`;
}
}
2 changes: 1 addition & 1 deletion frontend/src/vendor/ckeditor/ckeditor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/vendor/ckeditor/ckeditor.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%#-- 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.

++#%>

<%=
render(OpPrimer::InlineMacroComponent.new) do |inline_macro|
inline_macro.with_leading_visual_icon(icon: :"op-file-doc")

page_info_result.either(
->(page_info) do
render(Primer::Beta::Link.new(href: page_info.href)) { page_info.title }
end,
->(_error) do
render(Primer::Beta::Text.new(color: :muted)) { I18n.t("wikis.macro.page_not_found") }
end
)
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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
class InlinePageLinkMacroComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers

alias_method :page_info_result, :model
end
end
67 changes: 67 additions & 0 deletions modules/wikis/app/controllers/wikis/page_link_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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
class PageLinkController < ApplicationController
include Dry::Monads[:result]

# The view component shown in `load` will be rendered regardless of the current user's authorization status.
# The component itself handles the states of "unauthorized", "forbidden", and "not_found".
authorization_checked! :load
Comment thread
NobodysNightmare marked this conversation as resolved.

def load
provider = Provider.visible.find_by(id: params[:provider_id])
@page_info_result = page_info_result(provider)
@turbo_frame_id = turbo_frame_id

render layout: false
end

private

def page_info_result(provider)
return Failure() if provider.nil?

Adapters::Input::PageInfo.build(identifier:).bind do |input_data|
provider.auth_strategy_for(User.current).bind do |auth_strategy|
provider.resolve("queries.page_info").call(input_data:, auth_strategy:)
end
end
end

def identifier
params[:page_identifier]
end

def turbo_frame_id
params[:turbo_frame_id]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,24 @@ def initialize(provider_id:, identifier:)
end

def process
provider = Wikis::Provider.find_by(id: @provider_id)
provider = Provider.find_by(id: @provider_id)
view_context = ApplicationController.new.view_context
OpPrimer::InlineMacroComponent.new.render_in(view_context) do |component|
component.with_leading_visual_icon(icon: :"op-file-doc")
page_info_result = resolve_page(provider, @identifier)

resolve_page(provider, @identifier).either(
->(page_info) { render_page_info_macro(view_context, page_info) },
->(error) { render_error_macro(view_context, error) }
)
end
InlinePageLinkMacroComponent.new(page_info_result).render_in(view_context)
end

private

def resolve_page(provider, identifier)
return Failure() if provider.nil?

Wikis::Adapters::Input::PageInfo.build(identifier:).bind do |input|
Adapters::Input::PageInfo.build(identifier:).bind do |input_data|
provider.auth_strategy_for(User.current).bind do |auth_strategy|
provider.resolve("queries.page_info").call(input_data: input, auth_strategy:)
provider.resolve("queries.page_info").call(input_data:, auth_strategy:)
end
end
end

def render_page_info_macro(view_context, page_info)
Primer::Beta::Link.new(href: page_info.href).render_in(view_context) { page_info.title }
end

def render_error_macro(view_context, _error)
Primer::Beta::Text.new(color: :muted).render_in(view_context) { I18n.t("wikis.macro.page_not_found") }
end
end
end
end
32 changes: 32 additions & 0 deletions modules/wikis/app/views/wikis/page_link/load.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%#-- 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.

++#%>

<turbo-frame id="<%= @turbo_frame_id %>">
<%= render(::Wikis::InlinePageLinkMacroComponent.new(@page_info_result)) %>
</turbo-frame>
5 changes: 5 additions & 0 deletions modules/wikis/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
end
end
end

resource :wiki_page_link_macro, controller: "wikis/page_link" do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Last thing that I noticed so late, that it feels weird to bring this up now: I saw that the controller was called PageLinksController, which felt weird to me, because page_links#load could mean anything.

Seeing that the route is already called wiki_page_link_macro improves this a lot for me. I'd still prefer if the controller was equally named wikis/page_link_macro.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller was renamed in the follow up PR - #23193 - to be better distinguished to the other page link related controllers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Another thing that I noticed pretty late in the review, the use of resource adds a bunch of default routes here. None of which you need:

Image

What you want to do is add only: %i[], so that none of the default are auto-generated.

Also see the lines below for this.

Copy link
Copy Markdown
Member Author

@Kharonus Kharonus May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this was a flaw I also detected when working on the next iteration, the PR #23193 has some changes here, changing the route definition to

  resource :wiki_page_link_macro, controller: "wikis/inline_page_link_macro", only: [] do
    get :load
  end

get :load
end

resources :projects, only: %i[] do
resources :work_packages, only: %i[] do
resources :wikis, only: %i[] do
Expand Down
Loading