From 3acd8b8b085180c6c2535b1c846bd093f33f95b0 Mon Sep 17 00:00:00 2001
From: Alexandr Antonov
- - <%= text_field_tag "settings[trakers_list]", @settings["trakers_list"] %> -
+ + + + + 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