Redmine 5.1

This commit is contained in:
Karel Pičman 2023-11-10 07:47:52 +01:00
parent bf87b60215
commit 0b4ab8302d
26 changed files with 58 additions and 61 deletions

View File

@ -65,8 +65,6 @@ class CustomWorkflowsController < ApplicationController
end end
end end
def edit; end
def new def new
@workflow = CustomWorkflow.new @workflow = CustomWorkflow.new
@workflow.author = cookies[:custom_workflows_author] @workflow.author = cookies[:custom_workflows_author]
@ -75,6 +73,8 @@ class CustomWorkflowsController < ApplicationController
end end
end end
def edit; end
def import def import
xml = params[:file].read xml = params[:file].read
begin begin

View File

@ -15,7 +15,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GN73U General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@ -70,7 +70,7 @@ class CustomWorkflow < ApplicationRecord
end end
def self.log_message(str, object) def self.log_message(str, object)
Rails.logger.info "#{str} for #{object.class} (\##{object.id}) \"#{object}\"" Rails.logger.info "#{str} for #{object.class} (##{object.id}) \"#{object}\""
end end
def self.run_shared_code(object) def self.run_shared_code(object)

View File

@ -25,7 +25,7 @@ class CreateCustomWorkflows < ActiveRecord::Migration[4.2]
create_table :custom_workflows, force: true do |t| create_table :custom_workflows, force: true do |t|
t.references :project t.references :project
t.text :script, null: true, default: nil t.text :script, null: true, default: nil
t.boolean :is_enabled t.boolean :is_enabled, null: false, default: false
t.timestamps t.timestamps
t.index :project_id, unique: true t.index :project_id, unique: true
end end

View File

@ -34,7 +34,7 @@ class AlterCustomWorkflows < ActiveRecord::Migration[4.2]
def down def down
change_table(:custom_workflows, bulk: true) do |t| change_table(:custom_workflows, bulk: true) do |t|
t.references :project t.references :project
t.boolean :is_enabled t.boolean :is_enabled, null: false, default: false
t.remove :name t.remove :name
t.remove :description t.remove :description
t.remove :position t.remove :position

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -52,7 +52,7 @@ module RedmineCustomWorkflows
next if o&.custom_workflow_messages&.empty? next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value| o.custom_workflow_messages.each do |key, value|
if value&.present? if value.present?
flash[key] = value flash[key] = value
else else
flash.delete key flash.delete key

View File

@ -28,18 +28,18 @@ class AttachmentsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@attachment8 = Attachment.find 8 @attachment8 = Attachment.find 8
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = AttachmentsController.new @controller = AttachmentsController.new
end end
def test_delete_with_cw def test_delete_with_cw
delete :destroy, params: { id: @attachment8.id } delete "/attachments/#{@attachment8.id}"
assert_response :redirect assert_response :redirect
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
delete :destroy, params: { id: @attachment8.id } delete "/attachments/#{@attachment8.id}"
assert_response :redirect assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end

View File

@ -28,8 +28,6 @@ class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@cw1 = CustomWorkflow.find 1 @cw1 = CustomWorkflow.find 1
User.current = nil
@request.session[:user_id] = @admin.id
end end
def test_truth def test_truth
@ -37,13 +35,14 @@ class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase
end end
def test_index_admin def test_index_admin
get :index post '/login', params: { username: 'admin', password: 'admin' }
get '/custom_workflows'
assert_response :success assert_response :success
end end
def test_index_non_admin def test_index_non_admin
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
get :index get '/custom_workflows'
assert_response :forbidden assert_response :forbidden
end end
end end

View File

@ -28,22 +28,22 @@ class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@group10 = Group.find 10 @group10 = Group.find 10
@request.session[:user_id] = @admin.id post '/login', params: { username: 'admin', password: 'admin' }
@controller = GroupsController.new @controller = GroupsController.new
default_url_options[:host] = 'test.host' default_url_options[:host] = 'www.example.com'
end end
def test_update_with_cw def test_update_with_cw
@request.headers['Referer'] = edit_group_path(id: @group10.id) @request.headers['Referer'] = edit_group_path(id: @group10.id)
put :update, params: { id: @group10.id, group: { name: 'Updated name' } } put "/groups/#{@group10.id}", params: { group: { name: 'Updated name' } }
assert_redirected_to edit_group_path(id: @group10.id) assert_redirected_to groups_path
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
@request.headers['Referer'] = edit_group_path(id: @group10.id) @request.headers['Referer'] = edit_group_path(id: @group10.id)
put :update, params: { id: @group10.id, group: { name: 'Updated name' } } put "/groups/#{@group10.id}/", params: { group: { name: 'Updated name' } }
assert_redirected_to edit_group_path(id: @group10.id) assert_redirected_to groups_path
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end
end end

View File

@ -29,18 +29,18 @@ class IssueRelationsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@ir1 = IssueRelation.find 1 @ir1 = IssueRelation.find 1
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = AttachmentsController.new @controller = AttachmentsController.new
end end
def test_delete_with_cw def test_delete_with_cw
delete :destroy, params: { id: @ir1 } delete "/relations/#{@ir1.id}"
assert_response :redirect assert_response :redirect
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
delete :destroy, params: { id: @ir1 } delete "/relations/#{@ir1.id}"
assert_response :redirect assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end

View File

@ -29,26 +29,26 @@ class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@issue1 = Issue.find 1 @issue1 = Issue.find 1
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = IssuesController.new @controller = IssuesController.new
end end
def test_update_with_cw def test_update_with_cw
put :update, params: { id: @issue1.id, issue: { subject: 'Updated subject' } } put "/issues/#{@issue1.id}", params: { issue: { subject: 'Updated subject' } }
assert_redirected_to action: 'show', id: @issue1.id assert_redirected_to issue_path(@issue1)
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_delete_with_cw def test_delete_with_cw
delete :destroy, params: { id: @issue1.id, todo: 'destroy' } delete "/issues/#{@issue1.id}", params: { todo: 'destroy' }
assert_response :redirect assert_response :redirect
assert_equal 'Issue cannot be deleted', @controller.flash[:error] assert_equal 'Issue cannot be deleted', @controller.flash[:error]
assert Issue.find_by(id: @issue1.id) assert Issue.find_by(id: @issue1.id)
end end
def test_cw_env def test_cw_env
put :update, params: { id: @issue1.id, issue: { subject: 'Updated subject' } } put "/issues/#{@issue1.id}", params: { issue: { subject: 'Updated subject' } }
assert_redirected_to action: 'show', id: @issue1.id assert_redirected_to issue_path(@issue1)
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end
end end

View File

@ -27,18 +27,18 @@ class MembersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@member1 = Member.find 1 @member1 = Member.find 1
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = MembersController.new @controller = MembersController.new
end end
def test_delete_with_cw def test_delete_with_cw
delete :destroy, params: { id: @member1 } delete "/memberships/#{@member1.id}"
assert_response :redirect assert_response :redirect
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
delete :destroy, params: { id: @member1 } delete "/memberships/#{@member1.id}"
assert_response :redirect assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end

View File

@ -27,18 +27,18 @@ class ProjectsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = ProjectsController.new @controller = ProjectsController.new
end end
def test_update_with_cw def test_update_with_cw
post :update, params: { id: @project1.id, project: { name: 'Updated name' } } patch "/projects/#{@project1.id}", params: { project: { name: 'Updated name' } }
assert_redirected_to settings_project_path(@project1) assert_redirected_to settings_project_path(@project1)
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
post :update, params: { id: @project1.id, project: { name: 'Updated name' } } patch "/projects/#{@project1.id}", params: { project: { name: 'Updated name' } }
assert_redirected_to settings_project_path(@project1) assert_redirected_to settings_project_path(@project1)
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end

View File

@ -29,18 +29,18 @@ class TimelogControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@te1 = TimeEntry.find 1 @te1 = TimeEntry.find 1
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = TimelogController.new @controller = TimelogController.new
end end
def test_delete_with_cw def test_delete_with_cw
delete :destroy, params: { id: @te1 } delete "/time_entries/#{@te1.id}"
assert_response :redirect assert_response :redirect
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
delete :destroy, params: { id: @te1 } delete "/time_entries/#{@te1.id}"
assert_response :redirect assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end

View File

@ -26,19 +26,19 @@ class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@request.session[:user_id] = @admin.id post '/login', params: { username: 'admin', password: 'admin' }
@controller = UsersController.new @controller = UsersController.new
end end
def test_update_with_cw def test_update_with_cw
put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' } } put "/users/#{@jsmith.id}", params: { user: { lastname: 'updated_lastname' } }
assert_redirected_to edit_user_path(id: @jsmith.id) assert_redirected_to edit_user_path(@jsmith)
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' } } put "/users/#{@jsmith.id}", params: { user: { lastname: 'updated_lastname' } }
assert_redirected_to edit_user_path(id: @jsmith.id) assert_redirected_to edit_user_path(@jsmith)
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end
end end

View File

@ -27,18 +27,18 @@ class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@version1 = Version.find 1 @version1 = Version.find 1
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = VersionsController.new @controller = VersionsController.new
end end
def test_update_with_cw def test_update_with_cw
put :update, params: { id: @version1.id, version: { name: 'Updated version' } } put "/versions/#{@version1.id}", params: { version: { name: 'Updated version' } }
assert_redirected_to settings_project_path(id: @project1, tab: 'versions') assert_redirected_to settings_project_path(id: @project1, tab: 'versions')
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end end
def test_cw_env def test_cw_env
put :update, params: { id: @version1.id, version: { name: 'Updated version' } } put "/versions/#{@version1.id}", params: { version: { name: 'Updated version' } }
assert_redirected_to settings_project_path(id: @project1, tab: 'versions') assert_redirected_to settings_project_path(id: @project1, tab: 'versions')
assert_equal request.remote_ip, @controller.flash[:warning] assert_equal request.remote_ip, @controller.flash[:warning]
end end

View File

@ -29,15 +29,13 @@ class WikiControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
def setup def setup
super super
@wp1 = WikiPage.find 1 @wp1 = WikiPage.find 1
@request.session[:user_id] = @jsmith.id post '/login', params: { username: 'jsmith', password: 'jsmith' }
@controller = WikiController.new @controller = WikiController.new
end end
def test_update_with_cw def test_update_with_cw
put :update, put "/projects/#{@projects1.id}/wiki/Another_page",
params: { params: {
project_id: @project1.id,
id: 'Another_page',
content: { comments: 'my comments', text: 'edited', version: 1 } content: { comments: 'my comments', text: 'edited', version: 1 }
} }
assert_response :redirect assert_response :redirect

View File

@ -22,7 +22,7 @@
module RedmineCustomWorkflows module RedmineCustomWorkflows
module Test module Test
# Test case base class # Test case base class
class TestCase < ActionController::TestCase class TestCase < ActionDispatch::IntegrationTest
fixtures :users, :email_addresses, :projects fixtures :users, :email_addresses, :projects
# Allow us to override the fixtures method to implement fixtures for our plugin. # Allow us to override the fixtures method to implement fixtures for our plugin.