2019-03-16 15:03:47 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-02-27 13:34:41 +00:00
|
|
|
# Redmine - project management software
|
2023-01-01 06:19:35 +00:00
|
|
|
# Copyright (C) 2006-2023 Jean-Philippe Lang
|
2008-02-02 10:50:31 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
2011-05-16 22:55:14 +00:00
|
|
|
#
|
2008-02-02 10:50:31 +00:00
|
|
|
# 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.
|
2011-05-16 22:55:14 +00:00
|
|
|
#
|
2008-02-02 10:50:31 +00:00
|
|
|
# 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.
|
|
|
|
|
|
2023-01-01 07:13:39 +00:00
|
|
|
require_relative '../test_helper'
|
2008-02-02 10:50:31 +00:00
|
|
|
|
2016-07-14 09:35:49 +00:00
|
|
|
class JournalsControllerTest < Redmine::ControllerTest
|
2019-11-23 09:03:33 +00:00
|
|
|
fixtures :projects, :users, :members, :member_roles, :roles,
|
|
|
|
|
:issues, :journals, :journal_details, :enabled_modules,
|
|
|
|
|
:trackers, :issue_statuses, :enumerations, :custom_fields,
|
|
|
|
|
:custom_values, :custom_fields_projects, :projects_trackers
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2008-02-02 10:50:31 +00:00
|
|
|
def setup
|
|
|
|
|
User.current = nil
|
|
|
|
|
end
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2010-08-23 15:04:36 +00:00
|
|
|
def test_index
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:index, :params => {:project_id => 1})
|
2010-08-23 15:04:36 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/atom+xml', @response.media_type
|
2010-08-23 15:04:36 +00:00
|
|
|
end
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2014-12-05 08:08:00 +00:00
|
|
|
def test_index_with_invalid_query_id
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:index,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:query_id => 999
|
|
|
|
|
}
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2014-12-05 08:08:00 +00:00
|
|
|
assert_response 404
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-03 21:36:19 +00:00
|
|
|
def test_index_should_return_privates_notes_with_permission_only
|
|
|
|
|
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:index, :params => {:project_id => 1})
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
assert_select 'entry>id', :text => "http://test.host/issues/2?journal_id=#{journal.id}"
|
2012-10-03 21:36:19 +00:00
|
|
|
|
|
|
|
|
Role.find(1).remove_permission! :view_private_notes
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:index, :params => {:project_id => 1})
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
assert_select 'entry>id', :text => "http://test.host/issues/2?journal_id=#{journal.id}", :count => 0
|
2012-10-03 21:36:19 +00:00
|
|
|
end
|
|
|
|
|
|
2015-12-04 12:42:13 +00:00
|
|
|
def test_index_should_show_visible_custom_fields_only
|
2019-10-04 11:17:33 +00:00
|
|
|
set_tmp_attachments_directory
|
2015-12-04 12:42:13 +00:00
|
|
|
Issue.destroy_all
|
2017-05-31 17:32:34 +00:00
|
|
|
Journal.delete_all
|
2015-12-04 12:42:13 +00:00
|
|
|
field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all}
|
|
|
|
|
@fields = []
|
|
|
|
|
@fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
|
|
|
|
|
@fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
|
|
|
|
|
@fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
|
|
|
|
|
@issue = Issue.generate!(
|
|
|
|
|
:author_id => 1,
|
|
|
|
|
:project_id => 1,
|
|
|
|
|
:tracker_id => 1,
|
|
|
|
|
:custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
|
|
|
|
|
)
|
|
|
|
|
@issue.init_journal(User.find(1))
|
2017-05-31 17:32:34 +00:00
|
|
|
@issue.custom_field_values = {@field1.id => 'NewValue0', @field2.id => 'NewValue1', @field3.id => 'NewValue2'}
|
|
|
|
|
@issue.save!
|
2015-12-04 12:42:13 +00:00
|
|
|
|
|
|
|
|
user_with_role_on_other_project = User.generate!
|
|
|
|
|
User.add_to_project(user_with_role_on_other_project, Project.find(2), Role.find(3))
|
|
|
|
|
users_to_test = {
|
|
|
|
|
User.find(1) => [@field1, @field2, @field3],
|
|
|
|
|
User.find(3) => [@field1, @field2],
|
|
|
|
|
user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
|
|
|
|
|
User.generate! => [@field1],
|
|
|
|
|
User.anonymous => [@field1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
users_to_test.each do |user, visible_fields|
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:index,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:format => 'atom',
|
2022-03-19 09:56:46 +00:00
|
|
|
:key => user.atom_key
|
2017-05-31 17:32:34 +00:00
|
|
|
}
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2015-12-04 12:42:13 +00:00
|
|
|
@fields.each_with_index do |field, i|
|
|
|
|
|
if visible_fields.include?(field)
|
2020-10-03 15:37:22 +00:00
|
|
|
assert_select(
|
|
|
|
|
"content[type=html]",
|
|
|
|
|
{:text => /NewValue#{i}/, :count => 1},
|
|
|
|
|
"User #{user.id} was not able to view #{field.name} in API"
|
|
|
|
|
)
|
2015-12-04 12:42:13 +00:00
|
|
|
else
|
2020-10-03 15:37:22 +00:00
|
|
|
assert_select(
|
|
|
|
|
"content[type=html]",
|
|
|
|
|
{:text => /NewValue#{i}/, :count => 0},
|
|
|
|
|
"User #{user.id} was able to view #{field.name} in API"
|
|
|
|
|
)
|
2015-12-04 12:42:13 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2015-01-31 10:42:41 +00:00
|
|
|
def test_diff_for_description_change
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:diff, :params => {:id => 3, :detail_id => 4})
|
2011-02-27 13:34:41 +00:00
|
|
|
assert_response :success
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2014-11-20 19:57:06 +00:00
|
|
|
assert_select 'span.diff_out', :text => /removed/
|
|
|
|
|
assert_select 'span.diff_in', :text => /added/
|
2011-02-27 13:34:41 +00:00
|
|
|
end
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2015-01-31 10:42:41 +00:00
|
|
|
def test_diff_for_custom_field
|
|
|
|
|
field = IssueCustomField.create!(:name => "Long field", :field_format => 'text')
|
|
|
|
|
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Notes', :user_id => 1)
|
|
|
|
|
detail = JournalDetail.create!(:journal => journal, :property => 'cf', :prop_key => field.id,
|
|
|
|
|
:old_value => 'Foo', :value => 'Bar')
|
|
|
|
|
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:diff,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => journal.id,
|
|
|
|
|
:detail_id => detail.id
|
|
|
|
|
}
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2015-01-31 10:42:41 +00:00
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
assert_select 'span.diff_out', :text => /Foo/
|
|
|
|
|
assert_select 'span.diff_in', :text => /Bar/
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_diff_for_custom_field_should_be_denied_if_custom_field_is_not_visible
|
|
|
|
|
field = IssueCustomField.create!(:name => "Long field", :field_format => 'text', :visible => false, :role_ids => [1])
|
|
|
|
|
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Notes', :user_id => 1)
|
|
|
|
|
detail = JournalDetail.create!(:journal => journal, :property => 'cf', :prop_key => field.id,
|
|
|
|
|
:old_value => 'Foo', :value => 'Bar')
|
|
|
|
|
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:diff,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => journal.id,
|
|
|
|
|
:detail_id => detail.id
|
|
|
|
|
}
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2015-01-31 10:42:41 +00:00
|
|
|
assert_response 302
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-05 08:08:00 +00:00
|
|
|
def test_diff_should_default_to_description_diff
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:diff, :params => {:id => 3})
|
2014-12-05 08:08:00 +00:00
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
assert_select 'span.diff_out', :text => /removed/
|
|
|
|
|
assert_select 'span.diff_in', :text => /added/
|
|
|
|
|
end
|
|
|
|
|
|
2010-08-16 16:25:04 +00:00
|
|
|
def test_reply_to_issue
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:new, :params => {:id => 6}, :xhr => true)
|
2010-08-16 16:25:04 +00:00
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_include '> This is an issue', response.body
|
2010-08-16 16:25:04 +00:00
|
|
|
end
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2010-12-18 17:11:41 +00:00
|
|
|
def test_reply_to_issue_without_permission
|
|
|
|
|
@request.session[:user_id] = 7
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:new, :params => {:id => 6}, :xhr => true)
|
2010-12-18 17:11:41 +00:00
|
|
|
assert_response 403
|
|
|
|
|
end
|
2010-08-16 16:25:04 +00:00
|
|
|
|
|
|
|
|
def test_reply_to_note
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:new,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 6,
|
2019-06-02 15:58:32 +00:00
|
|
|
:journal_id => 4,
|
|
|
|
|
:journal_indice => 1
|
2017-05-31 17:32:34 +00:00
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2010-08-16 16:25:04 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2019-06-02 13:29:54 +00:00
|
|
|
assert_include 'Redmine Admin wrote in #note-1:', response.body
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_include '> A comment with a private version', response.body
|
2010-08-16 16:25:04 +00:00
|
|
|
end
|
|
|
|
|
|
2012-10-03 21:36:19 +00:00
|
|
|
def test_reply_to_private_note_should_fail_without_permission
|
|
|
|
|
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:new,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal_id => journal.id
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_include '> Privates notes', response.body
|
|
|
|
|
|
|
|
|
|
Role.find(1).remove_permission! :view_private_notes
|
2020-11-17 12:40:24 +00:00
|
|
|
get(
|
|
|
|
|
:new,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal_id => journal.id
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_response 404
|
|
|
|
|
end
|
|
|
|
|
|
2012-07-19 19:10:18 +00:00
|
|
|
def test_edit_xhr
|
2008-02-02 10:50:31 +00:00
|
|
|
@request.session[:user_id] = 1
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:edit, :params => {:id => 2}, :xhr => true)
|
2008-02-02 10:50:31 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_include 'textarea', response.body
|
2008-02-02 10:50:31 +00:00
|
|
|
end
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2012-10-03 21:36:19 +00:00
|
|
|
def test_edit_private_note_should_fail_without_permission
|
|
|
|
|
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true)
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
Role.find(1).add_permission! :edit_issue_notes
|
|
|
|
|
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:edit, :params => {:id => journal.id}, :xhr => true)
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_include 'textarea', response.body
|
|
|
|
|
|
|
|
|
|
Role.find(1).remove_permission! :view_private_notes
|
2020-11-17 12:40:24 +00:00
|
|
|
get(:edit, :params => {:id => journal.id}, :xhr => true)
|
2012-10-03 21:36:19 +00:00
|
|
|
assert_response 404
|
|
|
|
|
end
|
|
|
|
|
|
2012-07-19 19:10:18 +00:00
|
|
|
def test_update_xhr
|
2008-02-02 10:50:31 +00:00
|
|
|
@request.session[:user_id] = 1
|
2020-11-17 12:40:24 +00:00
|
|
|
post(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal => {
|
|
|
|
|
:notes => 'Updated notes'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2008-02-02 10:50:31 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2008-02-02 10:50:31 +00:00
|
|
|
assert_equal 'Updated notes', Journal.find(2).notes
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_include 'journal-2-notes', response.body
|
2019-06-21 07:23:16 +00:00
|
|
|
# response should include journal_indice param for quote link
|
|
|
|
|
assert_include 'journal_indice=2', response.body
|
2008-02-02 10:50:31 +00:00
|
|
|
end
|
2011-05-16 22:55:14 +00:00
|
|
|
|
2016-07-10 10:33:48 +00:00
|
|
|
def test_update_xhr_with_private_notes_checked
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-11-17 12:40:24 +00:00
|
|
|
post(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal => {
|
|
|
|
|
:private_notes => '1'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2016-07-10 10:33:48 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2016-07-10 10:33:48 +00:00
|
|
|
assert_equal true, Journal.find(2).private_notes
|
|
|
|
|
assert_include 'change-2', response.body
|
|
|
|
|
assert_include 'journal-2-private_notes', response.body
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_update_xhr_with_private_notes_unchecked
|
2019-08-17 08:14:36 +00:00
|
|
|
Journal.find(2).update(:private_notes => true)
|
2016-07-10 10:33:48 +00:00
|
|
|
@request.session[:user_id] = 1
|
2020-11-17 12:40:24 +00:00
|
|
|
post(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal => {
|
|
|
|
|
:private_notes => '0'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2016-07-10 10:33:48 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2016-07-10 10:33:48 +00:00
|
|
|
assert_equal false, Journal.find(2).private_notes
|
|
|
|
|
assert_include 'change-2', response.body
|
|
|
|
|
assert_include 'journal-2-private_notes', response.body
|
|
|
|
|
end
|
|
|
|
|
|
2016-07-10 10:58:00 +00:00
|
|
|
def test_update_xhr_without_set_private_notes_permission_should_ignore_private_notes
|
2016-07-10 10:33:48 +00:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
Role.find(1).add_permission! :edit_issue_notes
|
|
|
|
|
Role.find(1).add_permission! :view_private_notes
|
|
|
|
|
Role.find(1).remove_permission! :set_notes_private
|
|
|
|
|
|
2020-11-17 12:40:24 +00:00
|
|
|
post(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal => {
|
|
|
|
|
:private_notes => '1'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2016-07-10 10:58:00 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_equal false, Journal.find(2).private_notes
|
2016-07-10 10:33:48 +00:00
|
|
|
end
|
|
|
|
|
|
2012-07-19 19:10:18 +00:00
|
|
|
def test_update_xhr_with_empty_notes_should_delete_the_journal
|
2008-02-16 13:19:33 +00:00
|
|
|
@request.session[:user_id] = 1
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_difference 'Journal.count', -1 do
|
2020-11-17 12:40:24 +00:00
|
|
|
post(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 2,
|
|
|
|
|
:journal => {
|
|
|
|
|
:notes => ''
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
:xhr => true
|
2020-11-17 12:40:24 +00:00
|
|
|
)
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'text/javascript', response.media_type
|
2012-07-19 19:10:18 +00:00
|
|
|
end
|
2008-02-16 13:19:33 +00:00
|
|
|
assert_nil Journal.find_by_id(2)
|
2012-07-19 19:10:18 +00:00
|
|
|
assert_include 'change-2', response.body
|
2008-02-16 13:19:33 +00:00
|
|
|
end
|
2008-02-02 10:50:31 +00:00
|
|
|
end
|