-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[74542] Implement PageInfo query
#23092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
0972e7b
e667dcf
73ccfa8
9caa992
cec558c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,5 +29,5 @@ | |
| #++ | ||
|
|
||
| module Wikis::Adapters::Input | ||
| UserQuery = Data.define(:access_token) | ||
| User = Data.define(:access_token) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,8 +54,12 @@ def user_connected?(user) | |
| OAuthClientToken.for_user_and_client(user, oauth_client).exists? | ||
| end | ||
|
|
||
| def user_access_token(user) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To give one example why I am skeptical of the approach of merging this PR first and then taking care of authentication: This is a method that's now added to the public interface of every provider. In my mind, this method has to be removed in a subsequent PR and it's existence is only temporary. But I have no clue whether this is how you think about this method. You might want to keep it and then one of two things would happen at a later point:
|
||
| OAuthClientToken.find_by(user:, oauth_client:)&.access_token | ||
| end | ||
|
|
||
| def extract_origin_user_id(token) | ||
| resolve("queries.user").call(Wikis::Adapters::Input::UserQuery.new(access_token: token.access_token)) | ||
| resolve("queries.user").call(Wikis::Adapters::Input::User.new(access_token: token.access_token)) | ||
| end | ||
|
|
||
| def authenticate_via_two_way_oauth2? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # 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 XWiki | ||
| # Represents a parsed XWiki stable page identifier in canonical document reference format: | ||
| # "wikiName:Space1.Space2.PageName" — e.g. "xwiki:Main.WebHome" | ||
| # Maps to the REST API path: /wikis/{wiki}/spaces/{s1}/spaces/{s2}/pages/{page} | ||
| PageReference = Data.define(:wiki, :spaces, :page) do | ||
| def self.parse(identifier) | ||
| wiki, page_path = identifier.split(":", 2) | ||
| return nil if page_path.blank? | ||
|
|
||
| parts = page_path.split(".") | ||
| page = parts.pop | ||
| return nil if parts.empty? | ||
|
|
||
| new(wiki:, spaces: parts, page:) | ||
| end | ||
|
|
||
| def rest_path | ||
| spaces_path = spaces.map { "/spaces/#{CGI.escapeURIComponent(it)}" }.join | ||
| "/wikis/#{CGI.escapeURIComponent(wiki)}#{spaces_path}/pages/#{CGI.escapeURIComponent(page)}" | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # 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" | ||
| require_module_spec_helper | ||
|
|
||
| RSpec.describe Wikis::Adapters::Providers::XWiki::PageReference do | ||
| describe ".parse" do | ||
| subject { described_class.parse(identifier) } | ||
|
|
||
| context "with a standard identifier" do | ||
| let(:identifier) { "xwiki:Main.WebHome" } | ||
|
|
||
| it { is_expected.to have_attributes(wiki: "xwiki", spaces: ["Main"], page: "WebHome") } | ||
| end | ||
|
|
||
| context "with a nested space identifier" do | ||
| let(:identifier) { "xwiki:MySpace.SubSpace.PageName" } | ||
|
|
||
| it { is_expected.to have_attributes(wiki: "xwiki", spaces: %w[MySpace SubSpace], page: "PageName") } | ||
| end | ||
|
|
||
| context "without a colon separator" do | ||
| let(:identifier) { "Main.WebHome" } | ||
|
|
||
| it { is_expected.to be_nil } | ||
| end | ||
|
|
||
| context "with a blank page path" do | ||
| let(:identifier) { "xwiki:" } | ||
|
|
||
| it { is_expected.to be_nil } | ||
| end | ||
|
|
||
| context "without a space segment" do | ||
| let(:identifier) { "xwiki:WebHome" } | ||
|
|
||
| it { is_expected.to be_nil } | ||
| end | ||
| end | ||
|
|
||
| describe "#rest_path" do | ||
| subject { described_class.parse(identifier).rest_path } | ||
|
|
||
| context "with a single-space identifier" do | ||
| let(:identifier) { "xwiki:Main.WebHome" } | ||
|
|
||
| it { is_expected.to eq("/wikis/xwiki/spaces/Main/pages/WebHome") } | ||
| end | ||
|
|
||
| context "with a nested-space identifier" do | ||
| let(:identifier) { "xwiki:MySpace.SubSpace.PageName" } | ||
|
|
||
| it { is_expected.to eq("/wikis/xwiki/spaces/MySpace/spaces/SubSpace/pages/PageName") } | ||
| end | ||
|
|
||
| context "with special characters in segments" do | ||
| let(:identifier) { "xwiki:My Space.My Page" } | ||
|
|
||
| it { is_expected.to eq("/wikis/xwiki/spaces/My%20Space/pages/My%20Page") } | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I read the headline of the PR, I suspected that I would find exactly this in here 🙈
Is the current action plan to temporarily expect this optional parameter and work on a proper implementation of authorization strategies as the immediate next thing?
The pain that I have with reviewing this is that there will be a lot of code in the wrong place right now and we need to be aligned that this code is planned to be moved to the right place.
The alternative would be to leave this PR in draft state and tackle authentication first, then return here to finish the querying off properly.
CC @mereghost @Kharonus