diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 7ad49b7..e23cd46 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -9,10 +9,10 @@ end class CustomWorkflow < ActiveRecord::Base OBSERVABLES = [:issue, :issue_attachments, :user, :attachment, :group, :group_users, :project, :project_attachments, - :wiki_content, :wiki_page_attachments, :shared] - PROJECT_OBSERVABLES = [:issue, :issue_attachments, :project, :project_attachments, :wiki_content, :wiki_page_attachments] + :wiki_content, :wiki_page_attachments, :time_entry, :shared] + PROJECT_OBSERVABLES = [:issue, :issue_attachments, :project, :project_attachments, :wiki_content, :wiki_page_attachments, :time_entry] COLLECTION_OBSERVABLES = [:group_users, :issue_attachments, :project_attachments, :wiki_page_attachments] - SINGLE_OBSERVABLES = [:issue, :user, :group, :attachment, :project, :wiki_content] + SINGLE_OBSERVABLES = [:issue, :user, :group, :attachment, :project, :wiki_content, :time_entry] attr_protected :id has_and_belongs_to_many :projects diff --git a/config/locales/en.yml b/config/locales/en.yml index e75ddfe..1e5921e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -62,6 +62,7 @@ en: text_custom_workflow_project_attachments_code_note: These scripts are executed when a file being added to project/removed from project. Use variables @project and @attachment to access appropriate objects in your scripts. text_custom_workflow_wiki_content_code_note: Scripts are executed in the context of Wiki Content object when project object changes (destroys). Use methods and properties of the project directly (or through "self") text_custom_workflow_wiki_page_attachments_code_note: These scripts are executed when a file being added to wiki page/removed from wiki page. Use variables @page and @attachment to access appropriate objects in your scripts. + text_custom_workflow_time_entry_code_note: Scripts are executed in the context of TimeEntry object when user object changes (destroys). Use methods and properties of the time entry directly (or through "self") text_no_enabled_projects: No projects text_custom_workflow_author: Will be included in exported XML @@ -79,3 +80,4 @@ en: custom_workflow_observable_wiki_content: "Wiki Content" custom_workflow_observable_wiki_page_attachments: "Wiki Page Attachments" custom_workflow_observable_group_users: "Group Users" + custom_workflow_observable_time_entry: "Time Entry" diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 3400530..fa799cf 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -62,6 +62,7 @@ ru: text_custom_workflow_project_attachments_code_note: Эти сценарии выполняются когда файл загружается в проект/удаляется из проекта. Используйте переменные @project и @attachment для доступа к соответствующим объектам из Ваших сценариев. text_custom_workflow_wiki_content_code_note: Эти сценарии исполняются в контексте объекта Wiki содержания когда объект Wiki содержания изменяется (удаляется). Используйте методы и свойства объекта содержания Wiki (WikiContent) напрямую или через ключевое слово self. text_custom_workflow_wiki_page_attachments_code_note: Эти сценарии выполняются когда файл загружается на Wiki страницу/удаляется с Wiki страницы. Используйте переменные @page и @attachment для доступа к соответствующим объектам из Ваших сценариев. + text_custom_workflow_time_entry_code_note: Эти сценарии исполняются в контексте объекта затраченного времени когда объект пользователя изменяется (удаляется). Используйте методы и свойства объекта затраченного времени (TimeEntry) напрямую или через ключевое слово self. text_no_enabled_projects: Нет проектов text_custom_workflow_author: Будет использован в XML файле при экспорте @@ -79,3 +80,4 @@ ru: custom_workflow_observable_wiki_content: "Содержание Wiki" custom_workflow_observable_wiki_page_attachments: "Вложения страниц Wiki" custom_workflow_observable_group_users: "Пользователи группы" + custom_workflow_observable_time_entry: "Затраченное время" diff --git a/lib/redmine_custom_workflows/time_entry_patch.rb b/lib/redmine_custom_workflows/time_entry_patch.rb new file mode 100644 index 0000000..f4aaabe --- /dev/null +++ b/lib/redmine_custom_workflows/time_entry_patch.rb @@ -0,0 +1,38 @@ +module RedmineCustomWorkflows + module TimeEntryPatch + + def self.included(base) + base.send(:include, InstanceMethods) + base.class_eval do + before_save :before_save_custom_workflows + after_save :after_save_custom_workflows + before_destroy :before_destroy_custom_workflows + after_destroy :after_destroy_custom_workflows + end + end + + module InstanceMethods + def before_save_custom_workflows + @time_entry = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code(self) + CustomWorkflow.run_custom_workflows(:time_entry, self, :before_save) + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows(:time_entry, self, :after_save) + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:time_entry, self, :before_destroy) + end + + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows(:time_entry, self, :after_destroy) + end + end + end +end