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' 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 Enabling custom workflows for projects
-------------------------------------- --------------------------------------

View File

@ -130,6 +130,7 @@
<div class="splitcontent"> <div class="splitcontent">
<div class="splitcontentleft"> <div class="splitcontentleft">
<%= f.text_area :before_destroy, cols: 40, rows: 20, wrap: 'off', class: 'custom_workflow_script' %> <%= 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>
<div class="splitcontentright"> <div class="splitcontentright">
<%= f.text_area :after_destroy, cols: 40, rows: 20, wrap: 'off', class: 'custom_workflow_script' %> <%= 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_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 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 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í 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í. rekurzivnímu volání.
@ -102,6 +102,7 @@ cs:
se maže. Můžete přímo použít metody a vlastnosti objektu. 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. 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. 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_no_enabled_projects: Žádné projekty
text_custom_workflow_author: Bude zahrnuto do exportovaného XML 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_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 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 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. 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`) 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 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`) 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_no_enabled_projects: No projects
text_custom_workflow_author: Will be included in exported XML 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_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 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 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. 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`) 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 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`) 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_no_enabled_projects: Sin proyectos
text_custom_workflow_author: Se incluirá en el XML exportado 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_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 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 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 também será executado para as tarefas criadas recentemente. Então, faça as verificações adequadas para evitar que
entre em recursividade infinita. 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`) 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 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`) 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_no_enabled_projects: Não há projeto
text_custom_workflow_author: Será incluído no XML exportado text_custom_workflow_author: Será incluído no XML exportado

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,8 @@
--- ---
custom_workflows_001: custom_workflows_001:
id: 1 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: '' after_save: ''
name: 'Issue CW test' name: 'Issue CW test'
description: 'Testing workflow' description: 'Testing workflow'
@ -23,7 +24,8 @@ custom_workflows_001:
custom_workflows_002: custom_workflows_002:
id: 2 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: '' after_save: ''
name: 'Version CW test' name: 'Version CW test'
description: 'Testing workflow' description: 'Testing workflow'
@ -44,7 +46,8 @@ custom_workflows_002:
custom_workflows_003: custom_workflows_003:
id: 3 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: '' after_save: ''
name: 'User CW test' name: 'User CW test'
description: 'Testing workflow' description: 'Testing workflow'
@ -65,7 +68,8 @@ custom_workflows_003:
custom_workflows_004: custom_workflows_004:
id: 4 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: '' after_save: ''
name: 'Project CW test' name: 'Project CW test'
description: 'Testing workflow' description: 'Testing workflow'
@ -86,7 +90,8 @@ custom_workflows_004:
custom_workflows_005: custom_workflows_005:
id: 5 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: '' after_save: ''
name: 'Group CW test' name: 'Group CW test'
description: 'Testing workflow' description: 'Testing workflow'
@ -123,7 +128,8 @@ custom_workflows_006:
after_add: NULL after_add: NULL
before_remove: NULL before_remove: NULL
after_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 : '' after_destroy : ''
custom_workflows_007: custom_workflows_007:
@ -144,7 +150,8 @@ custom_workflows_007:
after_add: NULL after_add: NULL
before_remove: NULL before_remove: NULL
after_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 : '' after_destroy : ''
custom_workflows_008: custom_workflows_008:
@ -165,14 +172,17 @@ custom_workflows_008:
after_add: NULL after_add: NULL
before_remove: NULL before_remove: NULL
after_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 : '' after_destroy : ''
custom_workflows_009: custom_workflows_009:
id: 9 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: '' after_save: ''
name: 'Wiki CW test' name: 'Wiki content CW test'
description: 'Testing workflow' description: 'Testing workflow'
position: 9 position: 9
is_for_all: 0 is_for_all: 0
@ -186,5 +196,28 @@ custom_workflows_009:
after_add: NULL after_add: NULL
before_remove: NULL before_remove: NULL
after_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: '' after_destroy: ''

View File

@ -18,3 +18,7 @@ custom_workflows_projects_004:
custom_workflows_projects_005: custom_workflows_projects_005:
project_id: 1 project_id: 1
custom_workflow_id: 9 # Wiki content 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 end
def test_delete_with_cw def test_delete_with_cw
delete :destroy, params: { id: @attachment8 } delete :destroy, params: { id: @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
delete :destroy, params: { id: @attachment8.id }
assert_response :redirect
assert_equal request.remote_ip, @controller.flash[:warning]
end
end end

View File

@ -41,4 +41,11 @@ class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end 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 end

View File

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

View File

@ -47,4 +47,10 @@ class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert Issue.find_by(id: @issue1.id) assert Issue.find_by(id: @issue1.id)
end 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 end

View File

@ -38,4 +38,10 @@ class ProjectsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end 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 end

View File

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

View File

@ -37,4 +37,10 @@ class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end 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 end

View File

@ -38,4 +38,10 @@ class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase
assert_equal 'Custom workflow', @controller.flash[:notice] assert_equal 'Custom workflow', @controller.flash[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class AttachmentPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @attachment1.custom_workflow_messages[:notice] assert_equal 'Okay', @attachment1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class GroupPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @group10.custom_workflow_messages[:notice] assert_equal 'Okay', @group10.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class IssuePatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @issue1.custom_workflow_messages[:notice] assert_equal 'Okay', @issue1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class IssueRelationPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @issue_relation1.custom_workflow_messages[:notice] assert_equal 'Okay', @issue_relation1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class ProjectPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @project1.custom_workflow_messages[:notice] assert_equal 'Okay', @project1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class TimeEntryPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @time_entry1.custom_workflow_messages[:notice] assert_equal 'Okay', @time_entry1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class UserPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @user1.custom_workflow_messages[:notice] assert_equal 'Okay', @user1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class VersionPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @version1.custom_workflow_messages[:notice] assert_equal 'Okay', @version1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class WikiContentPatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @wiki_content1.custom_workflow_messages[:notice] assert_equal 'Okay', @wiki_content1.custom_workflow_messages[:notice]
end 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 end

View File

@ -38,4 +38,9 @@ class WikiPagePatchTest < RedmineCustomWorkflows::Test::UnitTest
assert_equal 'Okay', @wiki_page1.custom_workflow_messages[:notice] assert_equal 'Okay', @wiki_page1.custom_workflow_messages[:notice]
end 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 end