Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

enable editing former versions of wiki page

ulferts0a33ee80ad4c
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index a47466b49ff..3a4076a02ca 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -130,7 +130,7 @@ class WikiController < ApplicationController
def create
call = attachable_create_call ::WikiPages::CreateService,
- args: permitted_params.wiki_page_with_content.to_h.merge(wiki: @wiki)
+ args: permitted_params.wiki_page.to_h.merge(wiki: @wiki)
@page = call.result
@@ -157,7 +157,7 @@ class WikiController < ApplicationController
call = attachable_update_call ::WikiPages::UpdateService,
model: @page,
- args: permitted_params.wiki_page_with_content.to_h
+ args: permitted_params.wiki_page.to_h
@page = call.result
diff --git a/app/helpers/wiki_pages/at_version.rb b/app/helpers/wiki_pages/at_version.rb
index d18bdaa140f..839f3ce0ab9 100644
--- a/app/helpers/wiki_pages/at_version.rb
+++ b/app/helpers/wiki_pages/at_version.rb
@@ -39,22 +39,33 @@ class WikiPages::AtVersion < SimpleDelegator
def initialize(wiki_page, version = nil)
super(wiki_page)
- self.version = (version || wiki_page.version).to_i.clamp(1, wiki_page.version)
self.latest_version = wiki_page.version
+ self.version = (version || wiki_page.version).to_i.clamp(0, latest_version)
end
- delegate :updated_at,
- to: :last_journal
-
delegate :text,
to: :data
- def lock_version
- last_journal.version
+ # The form_for helper will call the #to_model method on the object it is passed otherwise
+ # which will return the object itself. Any version handling intended by this class will be forfeit.
+
+ # rubocop:disable Style/OptionalBooleanParameter
+ # Overwriting a superclass method.
+ def respond_to?(method_name, include_all = false)
+ if method_name.to_s == 'to_model'
+ false
+ else
+ super
+ end
end
+ # rubocop:enable Style/OptionalBooleanParameter
def author
- last_journal.user
+ last_journal&.user
+ end
+
+ def updated_at
+ last_journal&.updated_at
end
def journals
@@ -74,7 +85,7 @@ class WikiPages::AtVersion < SimpleDelegator
end
def to_ary
- __getobj__.send(:to_ary)
+ object.send(:to_ary)
end
private
@@ -83,7 +94,7 @@ class WikiPages::AtVersion < SimpleDelegator
:version
def data
- last_journal.data
+ last_journal.present? ? last_journal.data : object
end
def last_journal
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 262653d1d42..15e7db58eeb 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -253,15 +253,7 @@ class PermittedParams
def wiki_page
permitted = permitted_attributes(:wiki_page)
- params.require(:content).require(:page).permit(*permitted)
- end
-
- def wiki_content
- params.require(:content).permit(*self.class.permitted_attributes[:wiki_content])
- end
-
- def wiki_page_with_content
- wiki_page.merge(wiki_content)
+ params.require(:page).permit(*permitted)
end
def pref
@@ -609,8 +601,6 @@ class PermittedParams
title
parent_id
redirect_existing_links
- ),
- wiki_content: %i(
text
lock_version
journal_notes
diff --git a/app/views/wiki/_page_form.html.erb b/app/views/wiki/_page_form.html.erb
index 567e814fcec..cee6cacde36 100644
--- a/app/views/wiki/_page_form.html.erb
+++ b/app/views/wiki/_page_form.html.erb
@@ -2,12 +2,10 @@
<% resource = ::API::V3::WikiPages::WikiPageRepresenter.new(@page, current_user: current_user, embed_links: true) %>
-<%= f.fields_for :page, @page do |page_form| %>
- <%= editable_toolbar(form: page_form, field_name: :title) do %>
- <li class="toolbar-item">
- <zen-mode-toggle-button></zen-mode-toggle-button>
- </li>
- <% end %>
+<%= editable_toolbar(form: f, field_name: :title) do %>
+ <li class="toolbar-item">
+ <zen-mode-toggle-button></zen-mode-toggle-button>
+ </li>
<% end %>
<div class="attributes-group wiki--content--attribute ckeditor--content-scrollable form--field -visible-overflow">
@@ -23,18 +21,16 @@
</div>
<div class="form--field -required">
- <%= f.fields_for :page, @page do |page_fields| %>
- <%= page_fields.hidden_field :parent_id %>
- <%= page_fields.select :parent_id,
- wiki_page_options_for_select(@wiki.pages),
- { label: WikiPage.human_attribute_name(:parent_title), include_blank: false, container_class: '-wide' } %>
- <% end%>
+ <%= f.hidden_field :parent_id %>
+ <%= f.select :parent_id,
+ wiki_page_options_for_select(@wiki.pages),
+ { label: WikiPage.human_attribute_name(:parent_title), include_blank: false, container_class: '-wide' } %>
</div>
<div class="form--field">
<%= f.text_field :journal_notes,
class: '-border-on-hover-only -hide-placeholder-on-focus',
- label_options: { class: 'hidden-for-sighted' },
+ label_options: { class: 'hidden-for-sighted', label: :'attributes.comment' },
autocomplete: 'off',
container_class: '-wide',
placeholder: t(:text_what_did_you_change_click_to_add_comment) %>
diff --git a/app/views/wiki/edit.html.erb b/app/views/wiki/edit.html.erb
index c4ec6ab69d2..b103fb41779 100644
--- a/app/views/wiki/edit.html.erb
+++ b/app/views/wiki/edit.html.erb
@@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t(:label_edit), @page.title %>
<% breadcrumb_paths(*(@page.ancestors.reverse.collect { |parent| link_to h(parent.breadcrumb_title), {id: parent, project_id: parent.project}} + [h(@page.breadcrumb_title)] )) %>
<%= labelled_tabular_form_for @page,
- as: :content,
+ as: :page,
url: {action: 'update', id: @page.slug.presence || @old_title},
html: {method: :put, multipart: true, id: 'wiki_form'} do |f| %>
<%= f.hidden_field :lock_version %>
diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb
index 63041602a66..56350a7cedc 100644
--- a/app/views/wiki/new.html.erb
+++ b/app/views/wiki/new.html.erb
@@ -30,7 +30,7 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t("create_new_page") %>
<%= labelled_tabular_form_for @page,
- as: :content,
+ as: :page,
url: create_project_wiki_index_path(project_id: @project),
html: { method: :post, multipart: true, id: 'wiki_form' } do |f| %>
diff --git a/spec/controllers/wiki_controller_spec.rb b/spec/controllers/wiki_controller_spec.rb
index d94e4b205db..e38624c84f4 100644
--- a/spec/controllers/wiki_controller_spec.rb
+++ b/spec/controllers/wiki_controller_spec.rb
@@ -347,7 +347,7 @@ describe WikiController do
post 'create',
params: {
project_id: project,
- content: { text: 'h1. abc', page: { title: 'abc' } }
+ page: { text: 'h1. abc', title: 'abc' }
}
expect(response).to redirect_to action: 'show', project_id: project, id: 'abc'
@@ -357,7 +357,7 @@ describe WikiController do
post 'create',
params: {
project_id: project,
- content: { text: 'h1. abc', page: { title: 'abc' } }
+ page: { text: 'h1. abc', title: 'abc' }
}
page = project.wiki.pages.find_by title: 'abc'
@@ -371,7 +371,7 @@ describe WikiController do
post 'create',
params: {
project_id: project,
- content: { text: 'h1. abc', page: { title: '' } }
+ page: { text: 'h1. abc', title: '' }
}
expect(response).to render_template('new')
@@ -381,7 +381,7 @@ describe WikiController do
post 'create',
params: {
project_id: project,
- content: { text: 'h1. abc', page: { title: '' } }
+ page: { text: 'h1. abc', title: '' }
}
expect(assigns[:project]).to eq(project)
@@ -391,7 +391,7 @@ describe WikiController do
post 'create',
params: {
project_id: project,
- content: { text: 'h1. abc', page: { title: '' } }
+ page: { text: 'h1. abc', title: '' }
}
expect(assigns[:wiki]).to eq(project.wiki)
@@ -402,7 +402,7 @@ describe WikiController do
post 'create',
params: {
project_id: project,
- content: { text: 'h1. abc', page: { title: '' } }
+ page: { text: 'h1. abc', title: '' }
}
expect(assigns[:page]).to be_new_record
@@ -425,7 +425,7 @@ describe WikiController do
params: {
project_id: project,
id: existing_page.title,
- content: { text: 'h1. abc', page: { title: 'foobar' } }
+ page: { text: 'h1. abc', title: 'foobar' }
}
expect(response).to redirect_to action: 'show', project_id: project, id: 'foobar'
diff --git a/spec/features/activities/wiki_activity_spec.rb b/spec/features/activities/wiki_activity_spec.rb
index 36dbf2cf058..5be1201808b 100644
--- a/spec/features/activities/wiki_activity_spec.rb
+++ b/spec/features/activities/wiki_activity_spec.rb
@@ -48,7 +48,7 @@ describe 'Wiki activities' do
# create a wiki page
visit project_wiki_path(project, 'mypage')
- fill_in 'content_page_title', with: 'My page'
+ fill_in 'page_title', with: 'My page'
editor.set_markdown('First content')
diff --git a/spec/features/wiki/adding_editing_history_spec.rb b/spec/features/wiki/adding_editing_history_spec.rb
index 577d1e4543d..9aee016361f 100644
--- a/spec/features/wiki/adding_editing_history_spec.rb
+++ b/spec/features/wiki/adding_editing_history_spec.rb
@@ -143,7 +143,7 @@ describe 'wiki pages', js: true, with_settings: { journal_aggregation_time_minut
find('.ck-content').set(content_third_version)
- fill_in 'Journal notes', with: other_user_comment
+ fill_in 'Comment', with: other_user_comment
SeleniumHubWaiter.wait
click_button 'Save'
diff --git a/spec/features/wiki/child_pages_spec.rb b/spec/features/wiki/child_pages_spec.rb
index b4d18a00558..e85fe0ec5c7 100644
--- a/spec/features/wiki/child_pages_spec.rb
+++ b/spec/features/wiki/child_pages_spec.rb
@@ -57,7 +57,7 @@ describe 'wiki child pages', js: true do
click_on 'Wiki page'
SeleniumHubWaiter.wait
- fill_in 'content_page_title', with: child_page_name
+ fill_in 'page_title', with: child_page_name
find('.ck-content').set('The child page\'s content')
diff --git a/spec/features/wiki/edit_new_page_spec.rb b/spec/features/wiki/edit_new_page_spec.rb
index 0d1690890c4..56dac7bc24c 100644
--- a/spec/features/wiki/edit_new_page_spec.rb
+++ b/spec/features/wiki/edit_new_page_spec.rb
@@ -38,7 +38,7 @@ describe 'Editing a new wiki page', js: true do
it 'allows creating a wiki page from link' do
visit project_wiki_path(project, id: :foobar)
- expect(page).to have_field 'content_page_title', with: 'Foobar'
+ expect(page).to have_field 'page_title', with: 'Foobar'
click_on 'Save'
expect(page).to have_selector('.flash.notice', text: 'Successful creation.', wait: 10)
diff --git a/spec/helpers/wiki_pages/at_version_spec.rb b/spec/helpers/wiki_pages/at_version_spec.rb
index 6c31d4f3cf6..7497d8b1bc3 100644
--- a/spec/helpers/wiki_pages/at_version_spec.rb
+++ b/spec/helpers/wiki_pages/at_version_spec.rb
@@ -114,9 +114,18 @@ describe WikiPages::AtVersion do
context 'with the version being less then 1' do
let(:version) { 0 }
- it 'is the first journal`s user' do
+ it 'is nil' do
expect(page_at_version.author)
- .to eq first_journal_user
+ .to be_nil
+ end
+ end
+
+ context 'with the version being less then 0' do
+ let(:version) { -1 }
+
+ it 'is nil' do
+ expect(page_at_version.author)
+ .to be_nil
end
end
end
@@ -161,9 +170,9 @@ describe WikiPages::AtVersion do
context 'with the version being less then 1' do
let(:version) { 0 }
- it 'is only the first journal' do
+ it 'is empty' do
expect(page_at_version.journals)
- .to contain_exactly(first_journal)
+ .to be_empty
end
end
end
@@ -172,45 +181,45 @@ describe WikiPages::AtVersion do
context 'without a version' do
let(:version) { nil }
- it 'is the last journals`s version' do
+ it 'is the page`s lock_version' do
expect(page_at_version.lock_version)
- .to eq second_journal.version
+ .to eq wiki_page.lock_version
end
end
context 'with the version set to the first one' do
let(:version) { 1 }
- it 'is the first journals`s version' do
+ it 'is the page`s lock_version' do
expect(page_at_version.lock_version)
- .to eq first_journal.version
+ .to eq wiki_page.lock_version
end
end
context 'with the version set to the last one' do
let(:version) { 2 }
- it 'is the last journals`s version' do
+ it 'is the page`s lock_version' do
expect(page_at_version.lock_version)
- .to eq second_journal.version
+ .to eq wiki_page.lock_version
end
end
context 'with the version being larger then the current one' do
let(:version) { 3 }
- it 'is the last journals`s version' do
+ it 'is the page`s lock_version' do
expect(page_at_version.lock_version)
- .to eq second_journal.version
+ .to eq wiki_page.lock_version
end
end
context 'with the version being less then 1' do
let(:version) { 0 }
- it 'is the first journals`s version' do
+ it 'is the page`s lock_version' do
expect(page_at_version.lock_version)
- .to eq first_journal.version
+ .to eq wiki_page.lock_version
end
end
end
@@ -255,9 +264,9 @@ describe WikiPages::AtVersion do
context 'with the version being less then 1' do
let(:version) { 0 }
- it 'is the first journals`s updated_at' do
+ it 'is nil' do
expect(page_at_version.updated_at)
- .to eq first_journal.updated_at
+ .to be_nil
end
end
end
@@ -290,12 +299,21 @@ describe WikiPages::AtVersion do
end
end
- context 'with the version being less then 1' do
+ context 'with the version being 0' do
let(:version) { 0 }
- it 'is first version' do
+ it 'is 0' do
+ expect(page_at_version.version)
+ .to eq 0
+ end
+ end
+
+ context 'with the version being less then 0' do
+ let(:version) { -1 }
+
+ it 'is 0' do
expect(page_at_version.version)
- .to eq 1
+ .to eq 0
end
end
end
@@ -360,9 +378,9 @@ describe WikiPages::AtVersion do
context 'with the version being less then 1' do
let(:version) { 0 }
- it 'is the first journals`s text' do
+ it 'is the wiki pages`s text' do
expect(page_at_version.text)
- .to eq first_journal_text
+ .to eq wiki_page.text
end
end
end
@@ -480,4 +498,13 @@ describe WikiPages::AtVersion do
end
end
end
+
+ describe '#respond_to?' do
+ let(:version) { 1 }
+
+ it 'returns false for #to_model' do
+ expect(page_at_version)
+ .not_to respond_to(:to_model)
+ end
+ end
end
diff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rb
index 4409721e7df..bd06286a62a 100644
--- a/spec/models/permitted_params_spec.rb
+++ b/spec/models/permitted_params_spec.rb
@@ -862,34 +862,28 @@ describe PermittedParams do
end
describe '#wiki_page' do
- let(:hash_key) { :content }
- let(:nested_key) { :page }
+ let(:hash_key) { :page }
let (:attribute) { :wiki_page }
describe 'title' do
let(:hash) { { 'title' => 'blubs' } }
- it_behaves_like 'allows nested params'
+ it_behaves_like 'allows params'
end
describe 'parent_id' do
let(:hash) { { 'parent_id' => '1' } }
- it_behaves_like 'allows nested params'
+ it_behaves_like 'allows params'
end
describe 'redirect_existing_links' do
let(:hash) { { 'redirect_existing_links' => '1' } }
- it_behaves_like 'allows nested params'
+ it_behaves_like 'allows params'
end
- end
-
- describe '#wiki_content' do
- let (:hash_key) { :content }
- let (:attribute) { :wiki_content }
- describe 'title' do
+ describe 'journal_notes' do
let(:hash) { { 'journal_notes' => 'blubs' } }
it_behaves_like 'allows params'
@@ -924,7 +918,7 @@ describe PermittedParams do
end
describe 'project_id' do
- let(:hash) { { 'user_id' => 'blubs' } }
+ let(:hash) { { 'project_id' => 'blubs' } }
it_behaves_like 'forbids params'
end