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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
enable editing former versions of wiki page
ulferts0a33ee80ad4c
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rbindex a47466b49ff..3a4076a02ca 100644--- a/app/controllers/wiki_controller.rb+++ b/app/controllers/wiki_controller.rb@@ -130,7 +130,7 @@ class WikiController < ApplicationControllerdef createcall = 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 < ApplicationControllercall = 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.resultdiff --git a/app/helpers/wiki_pages/at_version.rb b/app/helpers/wiki_pages/at_version.rbindex 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 < SimpleDelegatordef 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+ endend+ # rubocop:enable Style/OptionalBooleanParameterdef author- last_journal.user+ last_journal&.user+ end++ def updated_at+ last_journal&.updated_atenddef journals@@ -74,7 +85,7 @@ class WikiPages::AtVersion < SimpleDelegatorenddef to_ary- __getobj__.send(:to_ary)+ object.send(:to_ary)endprivate@@ -83,7 +94,7 @@ class WikiPages::AtVersion < SimpleDelegator:versiondef data- last_journal.data+ last_journal.present? ? last_journal.data : objectenddef last_journaldiff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex 262653d1d42..15e7db58eeb 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -253,15 +253,7 @@ class PermittedParamsdef wiki_pagepermitted = 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)enddef pref@@ -609,8 +601,6 @@ class PermittedParamstitleparent_idredirect_existing_links- ),- wiki_content: %i(textlock_versionjournal_notesdiff --git a/app/views/wiki/_page_form.html.erb b/app/views/wiki/_page_form.html.erbindex 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.erbindex 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.erbindex 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.rbindex d94e4b205db..e38624c84f4 100644--- a/spec/controllers/wiki_controller_spec.rb+++ b/spec/controllers/wiki_controller_spec.rb@@ -347,7 +347,7 @@ describe WikiController dopost '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 dopost '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 dopost '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 dopost '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 dopost '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 dopost '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 doparams: {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.rbindex 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 pagevisit 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.rbindex 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_minutfind('.ck-content').set(content_third_version)- fill_in 'Journal notes', with: other_user_comment+ fill_in 'Comment', with: other_user_commentSeleniumHubWaiter.waitclick_button 'Save'diff --git a/spec/features/wiki/child_pages_spec.rb b/spec/features/wiki/child_pages_spec.rbindex 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 doclick_on 'Wiki page'SeleniumHubWaiter.wait- fill_in 'content_page_title', with: child_page_name+ fill_in 'page_title', with: child_page_namefind('.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.rbindex 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 doit 'allows creating a wiki page from link' dovisit 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.rbindex 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 docontext 'with the version being less then 1' dolet(:version) { 0 }- it 'is the first journal`s user' do+ it 'is nil' doexpect(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_nilendendend@@ -161,9 +170,9 @@ describe WikiPages::AtVersion docontext 'with the version being less then 1' dolet(:version) { 0 }- it 'is only the first journal' do+ it 'is empty' doexpect(page_at_version.journals)- .to contain_exactly(first_journal)+ .to be_emptyendendend@@ -172,45 +181,45 @@ describe WikiPages::AtVersion docontext 'without a version' dolet(:version) { nil }- it 'is the last journals`s version' do+ it 'is the page`s lock_version' doexpect(page_at_version.lock_version)- .to eq second_journal.version+ .to eq wiki_page.lock_versionendendcontext 'with the version set to the first one' dolet(:version) { 1 }- it 'is the first journals`s version' do+ it 'is the page`s lock_version' doexpect(page_at_version.lock_version)- .to eq first_journal.version+ .to eq wiki_page.lock_versionendendcontext 'with the version set to the last one' dolet(:version) { 2 }- it 'is the last journals`s version' do+ it 'is the page`s lock_version' doexpect(page_at_version.lock_version)- .to eq second_journal.version+ .to eq wiki_page.lock_versionendendcontext 'with the version being larger then the current one' dolet(:version) { 3 }- it 'is the last journals`s version' do+ it 'is the page`s lock_version' doexpect(page_at_version.lock_version)- .to eq second_journal.version+ .to eq wiki_page.lock_versionendendcontext 'with the version being less then 1' dolet(:version) { 0 }- it 'is the first journals`s version' do+ it 'is the page`s lock_version' doexpect(page_at_version.lock_version)- .to eq first_journal.version+ .to eq wiki_page.lock_versionendendend@@ -255,9 +264,9 @@ describe WikiPages::AtVersion docontext 'with the version being less then 1' dolet(:version) { 0 }- it 'is the first journals`s updated_at' do+ it 'is nil' doexpect(page_at_version.updated_at)- .to eq first_journal.updated_at+ .to be_nilendendend@@ -290,12 +299,21 @@ describe WikiPages::AtVersion doendend- context 'with the version being less then 1' do+ context 'with the version being 0' dolet(: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' doexpect(page_at_version.version)- .to eq 1+ .to eq 0endendend@@ -360,9 +378,9 @@ describe WikiPages::AtVersion docontext 'with the version being less then 1' dolet(:version) { 0 }- it 'is the first journals`s text' do+ it 'is the wiki pages`s text' doexpect(page_at_version.text)- .to eq first_journal_text+ .to eq wiki_page.textendendend@@ -480,4 +498,13 @@ describe WikiPages::AtVersion doendendend++ 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+ endenddiff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rbindex 4409721e7df..bd06286a62a 100644--- a/spec/models/permitted_params_spec.rb+++ b/spec/models/permitted_params_spec.rb@@ -862,34 +862,28 @@ describe PermittedParams doenddescribe '#wiki_page' do- let(:hash_key) { :content }- let(:nested_key) { :page }+ let(:hash_key) { :page }let (:attribute) { :wiki_page }describe 'title' dolet(:hash) { { 'title' => 'blubs' } }- it_behaves_like 'allows nested params'+ it_behaves_like 'allows params'enddescribe 'parent_id' dolet(:hash) { { 'parent_id' => '1' } }- it_behaves_like 'allows nested params'+ it_behaves_like 'allows params'enddescribe 'redirect_existing_links' dolet(: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' dolet(:hash) { { 'journal_notes' => 'blubs' } }it_behaves_like 'allows params'@@ -924,7 +918,7 @@ describe PermittedParams doenddescribe 'project_id' do- let(:hash) { { 'user_id' => 'blubs' } }+ let(:hash) { { 'project_id' => 'blubs' } }it_behaves_like 'forbids params'end