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

use current user for wiki content update

ulferts32a19b622e44
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index af2c11df509..0ab7122a4b5 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -151,8 +151,6 @@ class WikiController < ApplicationController
end
@content = @page.content_for_version(params[:version])
- # don't keep previous comment
- @content.comments = nil
# To prevent StaleObjectError exception when reverting to a previous version
@content.lock_version = @page.content.lock_version
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 5df31300ea1..3cdf70b563b 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -601,9 +601,9 @@ class PermittedParams
redirect_existing_links
),
wiki_content: %i(
- comments
text
lock_version
+ journal_notes
),
move_to: [:move_to]
}
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index 9e77f5ae32b..850b894130f 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -33,11 +33,6 @@ class WikiContent < ApplicationRecord
belongs_to :page, class_name: 'WikiPage'
belongs_to :author, class_name: 'User'
- validates_length_of :comments, maximum: 255, allow_nil: true
-
- attr_accessor :comments
-
- before_save :comments_to_journal_notes
acts_as_journalized
@@ -63,9 +58,7 @@ class WikiContent < ApplicationRecord
page.visible?(user)
end
- def project
- page.project
- end
+ delegate :project, to: :page
def attachments
page.nil? ? [] : page.attachments
@@ -77,14 +70,7 @@ class WikiContent < ApplicationRecord
deprecated_alias :versions, :journals
- # REVIEW
def version
last_journal.nil? ? 0 : last_journal.version
end
-
- private
-
- def comments_to_journal_notes
- add_journal author, comments
- end
end
diff --git a/app/services/wiki_pages/set_attributes_service.rb b/app/services/wiki_pages/set_attributes_service.rb
index f1ab0d59daf..73545ff7b87 100644
--- a/app/services/wiki_pages/set_attributes_service.rb
+++ b/app/services/wiki_pages/set_attributes_service.rb
@@ -72,6 +72,6 @@ class WikiPages::SetAttributesService < ::BaseServices::SetAttributes
end
def content_attribute?(name)
- WikiContent.column_names.include?(name) || name.to_s == 'comments'
+ WikiContent.column_names.include?(name) || name.to_s == 'journal_notes'
end
end
diff --git a/app/services/wiki_pages/update_service.rb b/app/services/wiki_pages/update_service.rb
index df9089a0500..4dd8da61500 100644
--- a/app/services/wiki_pages/update_service.rb
+++ b/app/services/wiki_pages/update_service.rb
@@ -31,7 +31,7 @@
class WikiPages::UpdateService < ::BaseServices::Update
include Attachments::ReplaceAttachments
- private
+ protected
def persist(service_result)
service_result = super(service_result)
diff --git a/app/views/user_mailer/wiki_content_added.html.erb b/app/views/user_mailer/wiki_content_added.html.erb
index f51b4baaa97..6a5f5a43fe4 100644
--- a/app/views/user_mailer/wiki_content_added.html.erb
+++ b/app/views/user_mailer/wiki_content_added.html.erb
@@ -31,5 +31,5 @@ See COPYRIGHT and LICENSE files for more details.
<%=raw t(:mail_body_wiki_content_added,
id: link_to(@wiki_content.page.title, project_wiki_url(@wiki_content.page.project, @wiki_content.page)),
author: @wiki_content.author) %><br />
- <em><%= @wiki_content.comments %></em>
+ <em><%= @wiki_content.journals.last.notes %></em>
</p>
diff --git a/app/views/user_mailer/wiki_content_added.text.erb b/app/views/user_mailer/wiki_content_added.text.erb
index 953802e1312..710579ad999 100644
--- a/app/views/user_mailer/wiki_content_added.text.erb
+++ b/app/views/user_mailer/wiki_content_added.text.erb
@@ -30,6 +30,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= t(:mail_body_wiki_content_added,
id: @wiki_content.page.title,
author: @wiki_content.author) %>
-<%= @wiki_content.comments %>
+<%= @wiki_content.journals.last.notes %>
<%= project_wiki_url(@wiki_content.page.project, @wiki_content.page) %>
diff --git a/app/views/user_mailer/wiki_content_updated.html.erb b/app/views/user_mailer/wiki_content_updated.html.erb
index 6dbe5458367..574f1e341d3 100644
--- a/app/views/user_mailer/wiki_content_updated.html.erb
+++ b/app/views/user_mailer/wiki_content_updated.html.erb
@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
<%=raw t(:mail_body_wiki_content_updated,
id: link_to(@wiki_content.page.title, project_wiki_url(@wiki_content.page.project, @wiki_content.page)),
author: @wiki_content.author) %><br />
- <em><%= @wiki_content.comments %></em>
+ <em><%= @wiki_content.journals.last.notes %></em>
</p>
<p><%= t(:label_view_diff) %>: <%= link_to @wiki_diff_url, @wiki_diff_url %></p>
diff --git a/app/views/user_mailer/wiki_content_updated.text.erb b/app/views/user_mailer/wiki_content_updated.text.erb
index bfc370e3226..d0c6af6c2e2 100644
--- a/app/views/user_mailer/wiki_content_updated.text.erb
+++ b/app/views/user_mailer/wiki_content_updated.text.erb
@@ -30,7 +30,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= t(:mail_body_wiki_content_updated,
id: @wiki_content.page.title,
author: @wiki_content.author) %>
-<%= @wiki_content.comments %>
+<%= @wiki_content.journals.last.notes %>
<%= project_wiki_url(@wiki_content.page.project, @wiki_content.page) %>
diff --git a/app/views/wiki/_page_form.html.erb b/app/views/wiki/_page_form.html.erb
index d5f8c8c369d..567e814fcec 100644
--- a/app/views/wiki/_page_form.html.erb
+++ b/app/views/wiki/_page_form.html.erb
@@ -32,7 +32,7 @@
</div>
<div class="form--field">
- <%= f.text_field :comments,
+ <%= f.text_field :journal_notes,
class: '-border-on-hover-only -hide-placeholder-on-focus',
label_options: { class: 'hidden-for-sighted' },
autocomplete: 'off',
diff --git a/spec/features/wiki/adding_editing_history_spec.rb b/spec/features/wiki/adding_editing_history_spec.rb
index c918e2a2726..658278cabc4 100644
--- a/spec/features/wiki/adding_editing_history_spec.rb
+++ b/spec/features/wiki/adding_editing_history_spec.rb
@@ -37,6 +37,11 @@ describe 'wiki pages', type: :feature, js: true, with_settings: { journal_aggreg
member_in_project: project,
member_through_role: role
end
+ let(:other_user) do
+ FactoryBot.create :user,
+ member_in_project: project,
+ member_through_role: role
+ end
let(:role) do
FactoryBot.create(:role,
permissions: %i[view_wiki_pages
@@ -51,6 +56,12 @@ describe 'wiki pages', type: :feature, js: true, with_settings: { journal_aggreg
let(:content_second_version) do
'The new content, second version'
end
+ let(:content_third_version) do
+ 'The new content, third version'
+ end
+ let(:other_user_comment) do
+ 'Other users`s comment'
+ end
before do
login_as user
@@ -120,5 +131,30 @@ describe 'wiki pages', type: :feature, js: true, with_settings: { journal_aggreg
expect(page).to have_selector('.wiki-version--details', text: 'Version 2/2')
expect(page).to have_selector('.wiki-content', text: content_second_version)
+
+ login_as other_user
+
+ visit project_wiki_path(project, 'new page')
+
+ within '.toolbar-items' do
+ SeleniumHubWaiter.wait
+ click_on "Edit"
+ end
+
+ find('.ck-content').set(content_third_version)
+
+ fill_in 'Journal notes', with: other_user_comment
+
+ SeleniumHubWaiter.wait
+ click_button 'Save'
+
+ within '.toolbar-items' do
+ SeleniumHubWaiter.wait
+ click_on 'More'
+ click_on 'History'
+ end
+
+ expect(page).to have_selector('tr.wiki-page-version:last-of-type .author', text: other_user.name)
+ expect(page).to have_selector('tr.wiki-page-version:last-of-type .comments', text: other_user_comment)
end
end
diff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rb
index 6b12591683f..28dd97bfdad 100644
--- a/spec/models/permitted_params_spec.rb
+++ b/spec/models/permitted_params_spec.rb
@@ -890,7 +890,7 @@ describe PermittedParams, type: :model do
let (:attribute) { :wiki_content }
describe 'title' do
- let(:hash) { { 'comments' => 'blubs' } }
+ let(:hash) { { 'journal_notes' => 'blubs' } }
it_behaves_like 'allows params'
end
diff --git a/spec/services/wiki_pages/set_attributes_service_spec.rb b/spec/services/wiki_pages/set_attributes_service_spec.rb
index b940b6daa45..1df2e5b4c6c 100644
--- a/spec/services/wiki_pages/set_attributes_service_spec.rb
+++ b/spec/services/wiki_pages/set_attributes_service_spec.rb
@@ -65,7 +65,8 @@ describe WikiPages::SetAttributesService, type: :model do
{
text: 'some new text',
title: 'a new title',
- slug: 'a new slug'
+ slug: 'a new slug',
+ journal_notes: 'the journal notes'
}
end
@@ -82,7 +83,7 @@ describe WikiPages::SetAttributesService, type: :model do
subject { instance.call(call_attributes) }
it 'is successful' do
- expect(subject.success?).to be_truthy
+ expect(subject).to be_success
end
context 'for an existing wiki page' do
@@ -94,6 +95,9 @@ describe WikiPages::SetAttributesService, type: :model do
expect(wiki_page.content.attributes.slice(*wiki_page.content.changed).symbolize_keys)
.to eql call_attributes.slice(:text)
+
+ expect(wiki_page.content.journal_notes)
+ .to eql call_attributes[:journal_notes]
end
it 'does not persist the wiki_page' do
@@ -119,6 +123,19 @@ describe WikiPages::SetAttributesService, type: :model do
.to eql user
end
+ it 'sets the attributes' do
+ subject
+
+ expect(wiki_page.attributes.slice(*wiki_page.changed).symbolize_keys)
+ .to eql call_attributes.slice(:title, :slug)
+
+ expect(wiki_page.content.attributes.slice(*(wiki_page.content.changed - ['author_id'])).symbolize_keys)
+ .to eql call_attributes.slice(:text)
+
+ expect(wiki_page.content.journal_notes)
+ .to eql call_attributes[:journal_notes]
+ end
+
it 'marks the content author to be system changed' do
subject
diff --git a/spec_legacy/functional/wiki_controller_spec.rb b/spec_legacy/functional/wiki_controller_spec.rb
index 065653840a6..efae35dd07c 100644
--- a/spec_legacy/functional/wiki_controller_spec.rb
+++ b/spec_legacy/functional/wiki_controller_spec.rb
@@ -85,68 +85,6 @@ describe WikiController, type: :controller do
assert_template 'new'
end
- it 'should create page' do
- session[:user_id] = 2
- post :create, params: { project_id: 1,
- id: 'New page',
- content: { comments: 'Created the page',
- text: "h1. New page\n\nThis is a new page",
- page: { title: 'New page',
- parent_id: '' } } }
- assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'new-page'
- page = wiki.find_page('New page')
- assert !page.new_record?
- refute_nil page.content
- assert_equal 'Created the page', page.content.last_journal.notes
- end
-
- it 'should update page with failure' do
- session[:user_id] = 2
- assert_no_difference 'WikiPage.count' do
- assert_no_difference 'WikiContent.count' do
- assert_no_difference 'Journal.count' do
- put :update, params: { project_id: 1,
- id: 'Another page',
- content: {
- comments: 'a' * 300, # failure here, comment is too long
- text: 'edited',
- lock_version: 1,
- page: { title: 'Another page',
- parent_id: '' }
- } }
- end
- end
- end
- assert_response :success
- assert_template 'edit'
-
- assert_error_tag descendant: { content: /Comment is too long/ }
- assert_select 'textarea', attributes: { id: 'content_text' }, content: /edited/
- assert_select 'input', attributes: { id: 'content_lock_version', value: '1' }
- end
-
- it 'should history' do
- FactoryBot.create :wiki_content_journal,
- journable_id: 1,
- data: FactoryBot.build(:journal_wiki_content_journal,
- text: 'h1. CookBook documentation')
- FactoryBot.create :wiki_content_journal,
- journable_id: 1,
- data: FactoryBot.build(:journal_wiki_content_journal,
- text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...")
- FactoryBot.create :wiki_content_journal,
- journable_id: 1,
- data: FactoryBot.build(:journal_wiki_content_journal,
- text: "h1. CookBook documentation\nSome updated [[documentation]] here...")
-
- get :history, params: { project_id: 1, id: 'CookBook documentation' }
- assert_response :success
- assert_template 'history'
- refute_nil assigns(:versions)
- assert_equal 3, assigns(:versions).size
- assert_select 'input[type=submit][name=commit]'
- end
-
it 'should history with one version' do
FactoryBot.create :wiki_content_journal,
journable_id: 2,
diff --git a/spec_legacy/unit/wiki_content_spec.rb b/spec_legacy/unit/wiki_content_spec.rb
index b01a70786b5..4850336a1f5 100644
--- a/spec_legacy/unit/wiki_content_spec.rb
+++ b/spec_legacy/unit/wiki_content_spec.rb
@@ -39,18 +39,17 @@ describe WikiContent, type: :model do
it 'should create' do
page = WikiPage.new(wiki: @wiki, title: 'Page')
- page.content = WikiContent.new(text: 'Content text', author: User.find(1), comments: 'My comment')
+ page.content = WikiContent.new(text: 'Content text', author: User.find(1))
assert page.save
page.reload
content = page.content
assert_kind_of WikiContent, content
assert_equal 1, content.version
- assert_equal 1, content.versions.length
+ assert_equal 1, content.journals.length
assert_equal 'Content text', content.text
- assert_equal 'My comment', content.versions.last.notes
assert_equal User.find(1), content.author
- assert_equal content.text, content.versions.last.data.text
+ assert_equal content.text, content.journals.last.data.text
end
it 'should update' do
@@ -60,7 +59,7 @@ describe WikiContent, type: :model do
assert content.save
content.reload
assert_equal version_count + 1, content.version
- assert_equal version_count + 1, content.versions.length
+ assert_equal version_count + 1, content.journals.length
end
it 'should fetch history' do
@@ -84,7 +83,7 @@ describe WikiContent, type: :model do
specify 'new WikiContent is version 0' do
page = WikiPage.new(wiki: @wiki, title: 'Page')
- page.content = WikiContent.new(text: 'Content text', author: User.find(1), comments: 'My comment')
+ page.content = WikiContent.new(text: 'Content text', author: User.find(1))
assert_equal 0, page.content.version
end