From 098abfd927df137c9e8c259b67df9092c73823ce Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Jul 2024 06:17:26 +0200 Subject: [PATCH 1/4] added hooks for time_entries --- lib/redmine_webhook/webhook_listener.rb | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index 7254f98..a038b55 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -43,6 +43,26 @@ def controller_issues_bulk_edit_after_save(context = {}) post(webhooks, journal_to_json(issue, journal, controller)) end + def controller_timelog_edit_before_save(context = {}) + return if skip_webhooks(context) + time_entry = context[:time_entry] + project = time_entry.project + webhooks = Webhook.where(:project_id => project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 + return unless webhooks + post(webhooks, timeentry_to_json(time_entry)) + end + + def controller_time_entries_bulk_edit_before_save(context = {}) + return if skip_webhooks(context) + time_entry = context[:time_entry] + project = time_entry.project + webhooks = Webhook.where(:project_id => project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 + return unless webhooks + post(webhooks, timeentry_to_json(time_entry)) + end + def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {}) issue = context[:issue] journal = issue.current_journal @@ -53,7 +73,7 @@ def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {}) end private - def issue_to_json(issue, controller) + def issue_to_json(issue, controller, time_entry) { :payload => { :action => 'opened', @@ -63,6 +83,15 @@ def issue_to_json(issue, controller) }.to_json end + def timeentry_to_json(time_entry) + { + :payload => { + :action => 'timeentry', + :time_entry => time_entry, + } + }.to_json + end + def journal_to_json(issue, journal, controller) { :payload => { From b40427106aaea0e8b907353ef3cb266c2b04c87c Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Jul 2024 06:21:45 +0200 Subject: [PATCH 2/4] added hooks for time_entries --- lib/redmine_webhook/webhook_listener.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index a038b55..6b39021 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -73,7 +73,7 @@ def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {}) end private - def issue_to_json(issue, controller, time_entry) + def issue_to_json(issue, controller) { :payload => { :action => 'opened', From 8c2dbcea945dc3fc2bfac1dbf6c6ac6fd6c955d8 Mon Sep 17 00:00:00 2001 From: "p.koevesdi" Date: Wed, 14 Aug 2024 23:50:33 +0200 Subject: [PATCH 3/4] added more verbosity to time_entry payload --- lib/redmine_webhook/webhook_listener.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index 6b39021..30a364c 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -82,12 +82,17 @@ def issue_to_json(issue, controller) } }.to_json end + def timeentry_to_json(time_entry) { :payload => { :action => 'timeentry', :time_entry => time_entry, + :custom_field_values => time_entry.custom_field_values.collect { |value| RedmineWebhook::CustomFieldValueWrapper.new(value).to_hash }, + :issue => RedmineWebhook::IssueWrapper.new(time_entry.issue).to_hash, + :activity => time_entry.activity, + :user => time_entry.user, } }.to_json end From 87214bc8afd1ace6ad9cd8c591e2a725cc4eae43 Mon Sep 17 00:00:00 2001 From: "p.koevesdi" Date: Sun, 15 Sep 2024 08:48:21 +0200 Subject: [PATCH 4/4] removed "controller_timelog_edit_before_save", in favour of "controller_timelog_edit_fter_save" --- lib/redmine_webhook/webhook_listener.rb | 46 ++++++++++++++++--------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/redmine_webhook/webhook_listener.rb b/lib/redmine_webhook/webhook_listener.rb index 30a364c..c1c8571 100644 --- a/lib/redmine_webhook/webhook_listener.rb +++ b/lib/redmine_webhook/webhook_listener.rb @@ -43,14 +43,24 @@ def controller_issues_bulk_edit_after_save(context = {}) post(webhooks, journal_to_json(issue, journal, controller)) end - def controller_timelog_edit_before_save(context = {}) + def controller_timelog_edit_before_destroy(context = {}) return if skip_webhooks(context) time_entry = context[:time_entry] project = time_entry.project webhooks = Webhook.where(:project_id => project.project.id) webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 return unless webhooks - post(webhooks, timeentry_to_json(time_entry)) + post(webhooks, timeentry_to_json(time_entry,'destroy')) + end + + def controller_timelog_edit_after_save(context = {}) + return if skip_webhooks(context) + time_entry = context[:time_entry] + project = time_entry.project + webhooks = Webhook.where(:project_id => project.project.id) + webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 + return unless webhooks + post(webhooks, timeentry_to_json(time_entry,'update')) end def controller_time_entries_bulk_edit_before_save(context = {}) @@ -60,7 +70,7 @@ def controller_time_entries_bulk_edit_before_save(context = {}) webhooks = Webhook.where(:project_id => project.project.id) webhooks = Webhook.where(:project_id => 0) unless webhooks && webhooks.length > 0 return unless webhooks - post(webhooks, timeentry_to_json(time_entry)) + post(webhooks, timeentry_to_json(time_entry,'update')) end def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {}) @@ -76,6 +86,7 @@ def model_changeset_scan_commit_for_issue_ids_pre_issue_update(context = {}) def issue_to_json(issue, controller) { :payload => { + :object => 'issue', :action => 'opened', :issue => RedmineWebhook::IssueWrapper.new(issue).to_hash, :url => controller.issue_url(issue) @@ -83,27 +94,30 @@ def issue_to_json(issue, controller) }.to_json end - - def timeentry_to_json(time_entry) + def journal_to_json(issue, journal, controller) { :payload => { - :action => 'timeentry', - :time_entry => time_entry, - :custom_field_values => time_entry.custom_field_values.collect { |value| RedmineWebhook::CustomFieldValueWrapper.new(value).to_hash }, - :issue => RedmineWebhook::IssueWrapper.new(time_entry.issue).to_hash, - :activity => time_entry.activity, - :user => time_entry.user, + :object => 'issue', + :action => 'updated', + :issue => RedmineWebhook::IssueWrapper.new(issue).to_hash, + :journal => RedmineWebhook::JournalWrapper.new(journal).to_hash, + :url => controller.nil? ? 'not yet implemented' : controller.issue_url(issue) } }.to_json end - def journal_to_json(issue, journal, controller) + + def timeentry_to_json(time_entry, action) { :payload => { - :action => 'updated', - :issue => RedmineWebhook::IssueWrapper.new(issue).to_hash, - :journal => RedmineWebhook::JournalWrapper.new(journal).to_hash, - :url => controller.nil? ? 'not yet implemented' : controller.issue_url(issue) + :object => 'timeentry', + :action => action, + :time_entry => time_entry, + :custom_field_values => time_entry.custom_field_values.collect { |value| RedmineWebhook::CustomFieldValueWrapper.new(value).to_hash }, + :issue => RedmineWebhook::IssueWrapper.new(time_entry.issue).to_hash, + :activity => time_entry.activity, + :user => time_entry.user, + :user_timezone => time_entry.user.time_zone } }.to_json end