From 3acd8b8b085180c6c2535b1c846bd093f33f95b0 Mon Sep 17 00:00:00 2001 From: Alexandr Antonov Date: Mon, 20 Jun 2022 16:48:28 +0300 Subject: [PATCH] Added project and tracker settings to plugin settings --- .../settings/_rabbitmq_settings.html.erb | 29 ++++++++++++++++--- config/locales/en.yml | 1 - config/locales/ru.yml | 1 - init.rb | 8 ++--- lib/notifier_hook.rb | 27 +++++++++++++---- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/app/views/settings/_rabbitmq_settings.html.erb b/app/views/settings/_rabbitmq_settings.html.erb index c3699d9..7e807f2 100644 --- a/app/views/settings/_rabbitmq_settings.html.erb +++ b/app/views/settings/_rabbitmq_settings.html.erb @@ -25,8 +25,29 @@ <%= number_field_tag "settings[port]", @settings["port"] %>

-

- - <%= text_field_tag "settings[trakers_list]", @settings["trakers_list"] %> -

+ +
<%= toggle_checkboxes_link("#rabbitmq_trackers_tracker_ids input[type=checkbox]") %><%=l(:label_tracker_plural)%> +<% tracker_ids = settings['rabbitmq_trackers'] %> +<% if !tracker_ids + tracker_ids = "0" + end %> +<% Tracker.sorted.each do |tracker| %> + <%= check_box_tag 'settings[rabbitmq_trackers][]', tracker.id, tracker_ids.include?(tracker.id.to_s), :id => "rabbitmq_trackers_tracker_ids_#{tracker.id}" -%> + <%= tracker.name %> + <% end %> +
+ +
<%= toggle_checkboxes_link("#rabbitmq_project_ids input[type=checkbox]:enabled") %><%= l(:label_project_plural) %> +
+ <% project_ids = settings['rabbitmq_projects'] %> + <% if !project_ids + project_ids = "0" + end %> + <%= render_project_nested_lists(Project.all) do |p| %> + <%= check_box_tag('settings[rabbitmq_projects][]', p.id, project_ids.include?(p.id.to_s), :id => nil) %> + <%= p.name %> + <%end %> +
+
+ diff --git a/config/locales/en.yml b/config/locales/en.yml index 8e84148..8dae6b4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -6,4 +6,3 @@ en: rabbitmq_label_exchange: Exchange rabbitmq_label_server: Server rabbitmq_label_port: Port - rabbitmq_label_trakers: Allowed for trackers(id) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 725b1fc..e29263f 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -6,4 +6,3 @@ ru: rabbitmq_label_exchange: Канал обмена rabbitmq_label_server: Сервер rabbitmq_label_port: Порт - rabbitmq_label_trakers: Разрешено для трекеров(id) diff --git a/init.rb b/init.rb index aff3d7e..fcda93f 100644 --- a/init.rb +++ b/init.rb @@ -14,12 +14,8 @@ Redmine::Plugin.register :rabbitmq do "exchange" => "redmine", "server" => "rabbitmq", "port" => 5672, - "trakers_list" => "0" + "rabbitmq_trackers" => "0", + "rabbitmq_projects" => "0" }, :partial => "settings/rabbitmq_settings" - -project_module :rabbitmq do - permission :send_rabbitmq, { rabbitmq_queries: [:new, :create, :edit, :update, :destroy] }, global: true - end - end diff --git a/lib/notifier_hook.rb b/lib/notifier_hook.rb index 6e45f23..a6aa6f8 100644 --- a/lib/notifier_hook.rb +++ b/lib/notifier_hook.rb @@ -1,14 +1,24 @@ class NotifierHook < Redmine::Hook::Listener def controller_issues_new_after_save(context = {}) - tracker_list = settings["trakers_list"].split(",") - if User.current.allowed_to?(:send_rabbitmq, context[:issue].project, global: true) and tracker_list.include?(context[:issue].tracker.id.to_s) + if settings['rabbitmq_trackers'].nil? + settings['rabbitmq_trackers'] = "0" + end + if settings['rabbitmq_projects'].nil? + settings['rabbitmq_projects'] = "0" + end + if settings['rabbitmq_projects'].include?(context[:issue].project.id.to_s) and settings['rabbitmq_trackers'].include?(context[:issue].tracker.id.to_s) deliver(make_msg(context[:issue]), make_key("issue", context[:issue].project.id, context[:issue].tracker.id, context[:project].parent_id, "new")) unless !validate_settings? end end def controller_issues_edit_after_save(context = {}) - tracker_list = settings["trakers_list"].split(",") - if User.current.allowed_to?(:send_rabbitmq, context[:issue].project, global: true) and tracker_list.include?(context[:issue].tracker.id.to_s) + if settings['rabbitmq_trackers'].nil? + settings['rabbitmq_trackers'] = "0" + end + if settings['rabbitmq_projects'].nil? + settings['rabbitmq_projects'] = "0" + end + if settings['rabbitmq_projects'].include?(context[:issue].project.id.to_s) and settings['rabbitmq_trackers'].include?(context[:issue].tracker.id.to_s) deliver(make_msg(context[:issue]), make_key("issue", context[:issue].project.id, context[:issue].tracker.id, context[:project].parent_id, "update")) unless !validate_settings? if context[:time_entry] deliver(make_msg(context[:time_entry]), make_key("time_entry", context[:time_entry].issue.project.id, context[:time_entry].issue.tracker.id, context[:project].parent_id, "update")) unless !validate_settings? @@ -17,8 +27,13 @@ class NotifierHook < Redmine::Hook::Listener end def controller_timelog_edit_before_save(context = {}) - tracker_list = settings["trakers_list"].split(",") - if User.current.allowed_to?(:send_rabbitmq, context[:time_entry].issue.project, global: true) and tracker_list.include?(context[:time_entry].issue.tracker.id.to_s) + if settings['rabbitmq_trackers'].nil? + settings['rabbitmq_trackers'] = "0" + end + if settings['rabbitmq_projects'].nil? + settings['rabbitmq_projects'] = "0" + end + if settings['rabbitmq_projects'].include?(context[:time_entry].issue.project.id.to_s) and settings['rabbitmq_trackers'].include?(context[:time_entry].issue.tracker.id.to_s) deliver(make_msg(context[:time_entry]), make_key("time_entry", context[:time_entry].issue.project.id, context[:time_entry].issue.tracker.id, context[:project].parent_id, "update")) unless !validate_settings? end end