Q: check for REST API access (user impersonation or remote IP) in workflow #280

This commit is contained in:
Karel Pičman 2022-09-27 12:39:58 +02:00
parent 607b614c8c
commit a481cfb212
45 changed files with 428 additions and 75 deletions

View File

@ -112,6 +112,14 @@ E.g.:
self.custom_workflow_messages[:error] = 'Custom workflow error'
```
Some environmental variables are available in observable objects.
E.g.:
```ruby
self.custom_workflow_env[:remote_ip]
```
Enabling custom workflows for projects
--------------------------------------

View File

@ -130,6 +130,7 @@
<div class="splitcontent">
<div class="splitcontentleft">
<%= f.text_area :before_destroy, cols: 40, rows: 20, wrap: 'off', class: 'custom_workflow_script' %>
<em class="info"><%= l(:text_custom_workflow_before_destroy_note) %></em>
</div>
<div class="splitcontentright">
<%= f.text_area :after_destroy, cols: 40, rows: 20, wrap: 'off', class: 'custom_workflow_script' %>

View File

@ -66,7 +66,7 @@ cs:
text_select_project_custom_workflows: Vyberte uživatelský skript projektu
text_custom_workflow_before_save_note: Zde můžete měnit vlastnosti úkolu. Ve skriptu nevytvářejte ani neměňte
související úkoly. Pro ukončení skriptu chybou použijte `raise WorkflowError, 'Zpráva uživateli'`.
související úkoly. Pro ukončení skriptu chybou použijte `raise RedmineCustomWorkflows::Errors::WorkflowError, 'Zpráva uživateli'`.
text_custom_workflow_after_save_note: Zde můžete aktualizovat nebo vytvářet souvissející úkoly. Mějte na paměti, že
tento skript bude také vykonán pro nově vytvořené úkoly. Takže nezapomeňte udělat vhodné kontroly pro zabránění
rekurzivnímu volání.
@ -102,6 +102,7 @@ cs:
se maže. Můžete přímo použít metody a vlastnosti objektu.
text_custom_workflow_version_code_note: Skripty jsou vykonávány v rámci objektu verze, když se mění nebo se maže.
Můžete přímo použít metody a vlastnosti objektu.
text_custom_workflow_before_destroy_note: Zabránit smazání objektu lze pomocí `return false`.
text_no_enabled_projects: Žádné projekty
text_custom_workflow_author: Bude zahrnuto do exportovaného XML

View File

@ -66,7 +66,7 @@ en:
text_select_project_custom_workflows: Select project custom workflows
text_custom_workflow_before_save_note: You can change properties of the issues here. Do not create or update related
issues in this script. To finish with error, use `raise WorkflowError, 'Message to user'`.
issues in this script. To finish with error, use `raise RedmineCustomWorkflows::Errors::WorkflowError, 'Message to user'`.
text_custom_workflow_after_save_note: You can update or create related issues here. Note that this script will be
also executed for the newly created issues. So make appropriate checks to prevent infinite recursion.
@ -102,6 +102,7 @@ en:
object changes (destroys). Use methods and properties of the time entry directly (or through `self`)
text_custom_workflow_version_code_note: Scripts are executed in the context of Version object when version object
changes (destroys). Use methods and properties of the version directly (or through `self`)
text_custom_workflow_before_destroy_note: To prevent destroying of the object use `return false`.
text_no_enabled_projects: No projects
text_custom_workflow_author: Will be included in exported XML

View File

@ -66,7 +66,7 @@ es:
text_select_project_custom_workflows: Seleccione un workflow personalizado de proyecto
text_custom_workflow_before_save_note: Aquí puede cambiar propiedades de las peticiones. No cree ni actualice peticiones
relacionadas en este script. Para acabar con error, use `raise WorkflowError, 'Message to user'`.
relacionadas en este script. Para acabar con error, use `raise RedmineCustomWorkflows::Errors::WorkflowError, 'Message to user'`.
text_custom_workflow_after_save_note: Puede actualizar o crear peticiones relacionadas aquí. Tenga en cuenta que este script
también se ejecutará para las peticiones recién creadas. Así que haga las comprobaciones oportunas para evitar la recursión infinita.
@ -102,6 +102,7 @@ es:
cambia (destruye). Utilice los métodos y propiedades de la entrada de tiempo directamente (o a través de `self`)
text_custom_workflow_version_code_note: Los scripts se ejecutan en el contexto del objeto Version cuando la versión
cambia (destruye). Utilizar métodos y propiedades de la versión directamente (o a través de `self`)
text_custom_workflow_before_destroy_note: To prevent destroying of the object use `return false`.
text_no_enabled_projects: Sin proyectos
text_custom_workflow_author: Se incluirá en el XML exportado

View File

@ -66,7 +66,7 @@ pt-BR:
text_select_project_custom_workflows: Selecione o projeto para os fluxos de trabalho
text_custom_workflow_before_save_note: Você pode alterar as propriedades das tarefas aqui. Não crie ou atualize
tarefas relacionadas neste script. Para terminar com o erro, utilize a `raise WorkflowError, 'Mensagem para o usuário'`.
tarefas relacionadas neste script. Para terminar com o erro, utilize a `raise RedmineCustomWorkflows::Errors::WorkflowError, 'Mensagem para o usuário'`.
text_custom_workflow_after_save_note: Você pode atualizar ou criar tarefas relacionadas aqui. Note que esse script
também será executado para as tarefas criadas recentemente. Então, faça as verificações adequadas para evitar que
entre em recursividade infinita.
@ -102,6 +102,7 @@ pt-BR:
object changes (destroys). Use methods and properties of the time entry directly (or through `self`)
text_custom_workflow_version_code_note: Scripts are executed in the context of Version object when version object
changes (destroys). Use methods and properties of the version directly (or through `self`)
text_custom_workflow_before_destroy_note: To prevent destroying of the object use `return false`.
text_no_enabled_projects: Não há projeto
text_custom_workflow_author: Será incluído no XML exportado

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @attachments
objects = @attachments
elsif @attachment
objects = [@attachment]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @attachments
objects = @attachments
elsif @attachment
objects = [@attachment]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @groups
objects = @groups
elsif @group
objects = [@group]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @groups
objects = @groups
elsif @group
objects = [@group]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @relations
objects = @relations
elsif @relation
objects = [@relation]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @relations
objects = @relations
elsif @relation
objects = [@relation]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @issues
objects = @issues
elsif @issue
objects = [@issue]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @issues
objects = @issues
elsif @issue
objects = [@issue]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @projects
objects = @projects
elsif @project
objects = [@project]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @projects
objects = @projects
elsif @project
objects = [@project]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @time_entries
objects = @time_entries
elsif @time_entry
objects = [@time_entry]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @time_entries
objects = @time_entries
elsif @time_entry
objects = [@time_entry]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @users
objects = @users
elsif @user
objects = [@user]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,17 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @users
objects = @users
elsif @user
objects = [@user]
end
objects
end
end
end
end

View File

@ -31,21 +31,27 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def display_custom_workflow_messages
if @versions
objects = @versions
elsif @version
objects = [@version]
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -57,6 +63,16 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @versions
objects = @versions
elsif @version
objects = [@version]
end
end
end
end
end

View File

@ -31,25 +31,29 @@ module RedmineCustomWorkflows
def self.prepended(base)
base.class_eval do
before_action :set_env
after_action :display_custom_workflow_messages
end
end
def set_env
objects = get_model_objects
if objects&.any?
objects.each do |o|
if request.remote_ip.present?
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
end
def display_custom_workflow_messages
if @pages
objects = @pages
elsif @page
objects = [@page]
end
if @content
objects ||= []
objects << @content
end
objects = get_model_objects
if objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
o.custom_workflow_messages.each do |key, value|
if value.empty?
unless value&.present?
flash.delete key
else
flash[key] = value
@ -61,6 +65,21 @@ module RedmineCustomWorkflows
end
end
private
def get_model_objects
if @pages
objects = @pages
elsif @page
objects = [@page]
end
if @content
objects ||= []
objects << @content
end
objects
end
end
end
end

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module AttachmentPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module GroupPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module IssuePatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module IssueRelationPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module ProjectPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
has_and_belongs_to_many :custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module TimeEntryPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module UserPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module VersionPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module WikiContentPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
before_save :before_save_custom_workflows

View File

@ -26,11 +26,16 @@ module RedmineCustomWorkflows
module WikiPagePatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
def custom_workflow_env
@custom_workflow_env ||= {}
end
def self.prepended(base)
base.class_eval do
def self.attachments_callback(event, page, attachment)

View File

@ -1,7 +1,8 @@
---
custom_workflows_001:
id: 1
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_save: ''
name: 'Issue CW test'
description: 'Testing workflow'
@ -23,7 +24,8 @@ custom_workflows_001:
custom_workflows_002:
id: 2
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_save: ''
name: 'Version CW test'
description: 'Testing workflow'
@ -44,7 +46,8 @@ custom_workflows_002:
custom_workflows_003:
id: 3
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_save: ''
name: 'User CW test'
description: 'Testing workflow'
@ -65,7 +68,8 @@ custom_workflows_003:
custom_workflows_004:
id: 4
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_save: ''
name: 'Project CW test'
description: 'Testing workflow'
@ -86,7 +90,8 @@ custom_workflows_004:
custom_workflows_005:
id: 5
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_save: ''
name: 'Group CW test'
description: 'Testing workflow'
@ -123,7 +128,8 @@ custom_workflows_006:
after_add: NULL
before_remove: NULL
after_remove: NULL
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_destroy : ''
custom_workflows_007:
@ -144,7 +150,8 @@ custom_workflows_007:
after_add: NULL
before_remove: NULL
after_remove: NULL
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_destroy : ''
custom_workflows_008:
@ -165,14 +172,17 @@ custom_workflows_008:
after_add: NULL
before_remove: NULL
after_remove: NULL
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]"
after_destroy : ''
custom_workflows_009:
id: 9
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'\n
self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]\n
Rails.logger.info \">>> #{self.class.name} #{self.id }#{self.custom_workflow_env[:remote_ip]}\""
after_save: ''
name: 'Wiki CW test'
name: 'Wiki content CW test'
description: 'Testing workflow'
position: 9
is_for_all: 0
@ -186,5 +196,28 @@ custom_workflows_009:
after_add: NULL
before_remove: NULL
after_remove: NULL
before_destroy: ''
before_destroy: "self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]\n
Rails.logger.info \">>> #{self.class.name} #{self.id }#{self.custom_workflow_env[:remote_ip]}\""
after_destroy : ''
custom_workflows_010:
id: 10
before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'"
after_save: ''
name: 'Wiki page CW test'
description: 'Testing workflow'
position: 10
is_for_all: 0
author: 'karel.picman@kontron.com'
created_at: 2018-12-20 14:01:27 +02:00
updated_at: 2018-12-20 14:01:27 +02:00
active: 1
observable: 'wiki_page'
shared_code: NULL
before_add: NULL
after_add: NULL
before_remove: NULL
after_remove: NULL
before_destroy: "self.custom_workflow_messages[:warning] = self.custom_workflow_env[:remote_ip]\n
Rails.logger.info \">>> #{self.class.name} #{self.id }#{self.custom_workflow_env[:remote_ip]}\""
after_destroy: ''

View File

@ -18,3 +18,7 @@ custom_workflows_projects_004:
custom_workflows_projects_005:
project_id: 1
custom_workflow_id: 9 # Wiki content
custom_workflows_projects_006:
project_id: 1
custom_workflow_id: 10 # Wiki page

View File

@ -34,9 +34,15 @@ class AttachmentsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
end
def test_delete_with_cw
delete :destroy, params: { id: @attachment8 }
delete :destroy, params: { id: @attachment8.id }
assert_response :redirect
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
delete :destroy, params: { id: @attachment8.id }
assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -41,4 +41,11 @@ class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
@request.headers['Referer'] = edit_group_path(id: @group10.id)
put :update, params: { id: @group10.id, group: { name: 'Updated name' } }
assert_redirected_to edit_group_path(id: @group10.id)
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -40,4 +40,10 @@ class IssueRelationsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
delete :destroy, params: { id: @ir1 }
assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -47,4 +47,10 @@ class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert Issue.find_by(id: @issue1.id)
end
def test_cw_env
put :update, params: { id: @issue1.id, issue: { subject: 'Updated subject' } }
assert_redirected_to action: 'show', id: @issue1.id
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -38,4 +38,10 @@ class ProjectsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
post :update, params: { id: @project1.id, project: { name: 'Updated name' } }
assert_redirected_to settings_project_path(@project1)
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -40,4 +40,10 @@ class TimelogControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
delete :destroy, params: { id: @te1 }
assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -37,4 +37,10 @@ class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' }}
assert_redirected_to edit_user_path(id: @jsmith.id)
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -38,4 +38,10 @@ class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice]
end
def test_cw_env
put :update, params: { id: @version1.id, version: { name: 'Updated version' } }
assert_redirected_to settings_project_path(id: @project1, tab: 'versions')
assert_equal request.remote_ip, @controller.flash[:warning]
end
end

View File

@ -38,4 +38,9 @@ class AttachmentPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @attachment1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@attachment1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @attachment1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class GroupPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @group10.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@group10.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @group10.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class IssuePatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @issue1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@issue1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @issue1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class IssueRelationPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @issue_relation1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@issue_relation1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @issue_relation1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class ProjectPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @project1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@project1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @project1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class TimeEntryPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @time_entry1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@time_entry1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @time_entry1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class UserPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @user1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@user1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @user1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class VersionPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @version1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@version1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @version1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class WikiContentPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @wiki_content1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@wiki_content1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @wiki_content1.custom_workflow_env[:remote_ip]
end
end

View File

@ -38,4 +38,9 @@ class WikiPagePatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @wiki_page1.custom_workflow_messages[:notice]
end
def test_custom_workflow_env
@wiki_page1.custom_workflow_env[:remote_ip] = '127.0.0.1'
assert_equal '127.0.0.1', @wiki_page1.custom_workflow_env[:remote_ip]
end
end