-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[OP#73838] Introducing the Wikis::PageLinkRepresenter #22745
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f49ab0
Adds view and manage permissions on work package wiki links plus api …
mereghost 5793071
Adds provisional method named #author? for easy handling of the rende…
mereghost 44bbc3c
Adding representer basics
mereghost 8c2050f
Adds linkable to the response, not polymorphic yet
mereghost 51cf1f6
Adds provider to the PageLink resource. Barebones Provider Representer
mereghost 7c5c125
Rename link parameters, make author? into render_author? as more inte…
mereghost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
modules/wikis/lib/api/v3/page_links/page_link_representer.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # 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 API | ||
| module V3 | ||
| module PageLinks | ||
| class PageLinkRepresenter < Decorators::Single | ||
| include Decorators::LinkedResource | ||
| include Decorators::DateProperty | ||
| include Caching::CachedRepresenter | ||
|
|
||
| property :id | ||
| property :identifier | ||
|
|
||
| date_time_property :created_at | ||
| date_time_property :updated_at | ||
|
|
||
| # Title being the identifier is kind of a placeholder until we have actual page names | ||
|
NobodysNightmare marked this conversation as resolved.
|
||
| self_link(path: :wiki_page_link, title_getter: ->(*) { represented.identifier }) | ||
|
NobodysNightmare marked this conversation as resolved.
|
||
|
|
||
| link :delete, cache_if: ->(*) { user_allowed_to_manage?(represented) } do | ||
| { | ||
| href: api_v3_paths.wiki_page_link(represented.id), | ||
| method: :delete | ||
| } | ||
| end | ||
|
|
||
| link :author do | ||
| next unless represented.render_author? | ||
|
|
||
| { | ||
| href: api_v3_paths.user(represented.author_id), | ||
| title: represented.author.name | ||
| } | ||
| end | ||
|
|
||
| associated_resource :provider, v3_path: :wiki_provider | ||
|
|
||
| # TODO: Make this truly polymorphic - @mereghost 2026-04-13 | ||
| associated_resource :linkable, | ||
| v3_path: :work_package, | ||
| representer: ::API::V3::WorkPackages::WorkPackageRepresenter, | ||
| skip_render: ->(*) { represented.linkable_id.nil? || represented.linkable_type != "WorkPackage" } | ||
|
|
||
| def _type = represented.class.name.demodulize | ||
|
|
||
| private | ||
|
|
||
| def user_allowed_to_manage?(model) | ||
| if model.linkable.present? | ||
| current_user.allowed_in_project?(:manage_wiki_page_links, model.linkable.project) | ||
| else | ||
| current_user == model.author | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
48 changes: 48 additions & 0 deletions
48
modules/wikis/lib/api/v3/providers/provider_representer.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # 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 API | ||
| module V3 | ||
| module Providers | ||
| class ProviderRepresenter < Decorators::Single | ||
| include Decorators::LinkedResource | ||
| include Decorators::DateProperty | ||
|
|
||
| property :id | ||
| property :name | ||
|
|
||
| date_time_property :created_at | ||
| date_time_property :updated_at | ||
|
|
||
| self_link(path: :wiki_provider) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
modules/wikis/spec/lib/api/v3/page_links/page_link_representer_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # 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" | ||
|
|
||
| module API | ||
| module V3 | ||
| module PageLinks | ||
| RSpec.describe PageLinkRepresenter, :rendering do | ||
| include Utilities::PathHelper | ||
|
|
||
| let(:inline_page_link) { build_stubbed(:inline_wiki_page_link) } | ||
| let(:relation_page_link) { build_stubbed(:relation_wiki_page_link) } | ||
| let(:current_user) { build_stubbed(:user) } | ||
|
|
||
| let(:represented) { relation_page_link } | ||
| let(:project) { represented.linkable.project } | ||
|
|
||
| let(:embed_links) { false } | ||
| let(:representer) { described_class.new(represented, current_user:, embed_links:) } | ||
|
|
||
| subject(:resulting_json) { representer.to_json } | ||
|
|
||
| describe "_links" do | ||
| describe "self" do | ||
| it_behaves_like "has a titled link" do | ||
| let(:link) { "self" } | ||
| let(:href) { "/api/v3/wiki_page_links/#{represented.id}" } | ||
| let(:title) { represented.identifier } | ||
| end | ||
| end | ||
|
|
||
| describe "provider" do | ||
| it_behaves_like "has a titled link" do | ||
| let(:link) { "provider" } | ||
| let(:href) { "/api/v3/wiki_providers/#{represented.provider_id}" } | ||
| let(:title) { represented.provider.name } | ||
| end | ||
| end | ||
|
|
||
| describe "delete" do | ||
| let(:permission) { :manage_wiki_page_links } | ||
|
|
||
| let(:link) { "delete" } | ||
| let(:href) { "/api/v3/wiki_page_links/#{represented.id}" } | ||
| let(:method) { :delete } | ||
|
|
||
| it_behaves_like "has an untitled action link" | ||
|
|
||
| context "when there is no associated linkable" do | ||
| before { represented.linkable = nil } | ||
|
|
||
| it_behaves_like "has no link" | ||
|
|
||
| context "and the current user is creator of the file link" do | ||
| let(:current_user) { represented.author } | ||
|
|
||
| it { is_expected.to have_json_path("_links/#{link}") } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "author" do | ||
| context "when the page link is an InlinePageLink" do | ||
| let(:represented) { inline_page_link } | ||
|
|
||
| it "does not render the author link" do | ||
| expect(resulting_json).not_to have_json_path("author") | ||
| end | ||
| end | ||
|
|
||
| it_behaves_like "has a titled link" do | ||
| let(:link) { "author" } | ||
| let(:href) { "/api/v3/users/#{represented.author_id}" } | ||
| let(:title) { represented.author.name } | ||
| end | ||
| end | ||
|
|
||
| describe "linkable" do | ||
| it_behaves_like "has a titled link" do | ||
| let(:link) { "linkable" } | ||
| let(:href) { "/api/v3/work_packages/#{represented.linkable_id}" } | ||
| let(:title) { represented.linkable.name } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "properties" do | ||
| describe "_type" do | ||
| context "when InlinePageLink" do | ||
| let(:represented) { inline_page_link } | ||
|
|
||
| it_behaves_like "property", :_type do | ||
| let(:value) { "InlinePageLink" } | ||
| end | ||
| end | ||
|
|
||
| context "when RelationPageLink" do | ||
| it_behaves_like "property", :_type do | ||
| let(:value) { "RelationPageLink" } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| it_behaves_like "property", :identifier do | ||
| let(:value) { represented.identifier } | ||
| end | ||
|
|
||
| it_behaves_like "datetime property", :createdAt do | ||
| let(:value) { represented.created_at } | ||
| end | ||
|
|
||
| it_behaves_like "datetime property", :updatedAt do | ||
| let(:value) { represented.updated_at } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.