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

Merge branch 'release/10.6' into dev

ulferts42d5ec7df828
diff --cc app/models/work_package.rb
index f8c67c340cb,d74b28b6a95..78f41411834
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@@ -379,11 -379,10 +379,10 @@@ class WorkPackage < ApplicationRecor
end
# check if user is allowed to edit WorkPackage Journals.
- # see Redmine::Acts::Journalized::Permissions#journal_editable_by
+ # see Acts::Journalized::Permissions#journal_editable_by
- def editable_by?(user)
- project = self.project
+ def journal_editable_by?(journal, user)
user.allowed_to?(:edit_work_package_notes, project, global: project.present?) ||
- user.allowed_to?(:edit_own_work_package_notes, project, global: project.present?)
+ user.allowed_to?(:edit_own_work_package_notes, project, global: project.present?) && journal.user_id == user.id
end
# Adds the 'virtual' attribute 'hours' to the result set. Using the
diff --cc spec/lib/acts_as_journalized/journaled_spec.rb
index 2577b85f125,65a9c4412ca..396b0afeda1
--- a/spec/lib/acts_as_journalized/journaled_spec.rb
+++ b/spec/lib/acts_as_journalized/journaled_spec.rb
@@@ -29,31 -29,104 +29,21 @@@
require 'spec_helper'
describe 'Journalized Objects' do
- before(:each) do
- @project ||= FactoryBot.create(:project_with_types)
- @type ||= @project.types.first
- @current = FactoryBot.create(:user, login: 'user1', mail: '[email protected]')
- allow(User).to receive(:current).and_return(@current)
- end
-
- it 'should work with work packages' do
- @status_open ||= FactoryBot.create(:status, name: 'Open', is_default: true)
- @work_package ||= FactoryBot.create(:work_package, project: @project, status: @status_open, type: @type, author: @current)
-
- initial_journal = @work_package.journals.first
- recreated_journal = @work_package.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
- it 'should work with news' do
- @news ||= FactoryBot.create(:news, project: @project, author: @current, title: 'Test', summary: 'Test', description: 'Test')
-
- initial_journal = @news.journals.first
- recreated_journal = @news.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
- it 'should work with wiki content' do
- @wiki_content ||= FactoryBot.create(:wiki_content, author: @current)
-
- initial_journal = @wiki_content.journals.first
- recreated_journal = @wiki_content.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
- it 'should work with messages' do
- @message ||= FactoryBot.create(:message, content: 'Test', subject: 'Test', author: @current)
-
- initial_journal = @message.journals.first
- recreated_journal = @message.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
- it 'should work with time entries' do
- @status_open ||= FactoryBot.create(:status, name: 'Open', is_default: true)
- @work_package ||= FactoryBot.create(:work_package, project: @project, status: @status_open, type: @type, author: @current)
-
- @time_entry ||= FactoryBot.create(:time_entry, work_package: @work_package, project: @project, spent_on: Time.now, hours: 5, user: @current, activity: FactoryBot.create(:time_entry_activity))
-
- initial_journal = @time_entry.journals.first
- recreated_journal = @time_entry.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
- it 'should work with attachments' do
- @attachment ||= FactoryBot.create(:attachment, container: FactoryBot.create(:work_package), author: @current)
-
- initial_journal = @attachment.journals.first
- recreated_journal = @attachment.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
- it 'should work with changesets' do
- Setting.enabled_scm = ['subversion']
- @repository ||= FactoryBot.create(:repository_subversion, url: 'http://svn.test.com')
- @changeset ||= FactoryBot.create(:changeset, committer: @current.login, repository: @repository)
-
- initial_journal = @changeset.journals.first
- recreated_journal = @changeset.recreate_initial_journal!
-
- expect(initial_journal).to be_identical(recreated_journal)
- end
-
describe 'journal_editable_by?' do
context 'when the journable is a work package' do
-- let!(:user) { FactoryBot.create(:user) }
++ let!(:user) { FactoryBot.create(:user, member_in_project: project, member_with_permissions: []) }
let!(:project) { FactoryBot.create(:project_with_types) }
- let!(:role) { FactoryBot.create(:role, permissions: [:edit_work_packages]) }
- let!(:role) { FactoryBot.create(:role, permissions: []) }
-- let!(:member) do
- FactoryBot.create(:member, project: project,
- roles: [role],
- principal: user)
- FactoryBot.create(:member,
- project: project,
- roles: [role],
- principal: user)
-- end
let!(:work_package) do
- FactoryBot.build(:work_package,
- type: project.types.first,
- author: user,
- project: project,
- description: '')
+ FactoryBot.create(:work_package,
+ type: project.types.first,
+ author: user,
+ project: project,
+ description: '')
end
- subject { work_package.journal_editable_by?(user) }
+ subject { work_package.journal_editable_by?(work_package.journals.first, user) }
context 'and the user has no permission to "edit_work_packages"' do
- before do
- role.remove_permission! :edit_work_packages
- end
-
it { is_expected.to be_falsey }
end
end