Added project and tracker settings to plugin settings

This commit is contained in:
Alexandr Antonov 2022-06-20 16:48:28 +03:00
parent 99a7259494
commit 3acd8b8b08
5 changed files with 48 additions and 18 deletions

View File

@ -25,8 +25,29 @@
<%= number_field_tag "settings[port]", @settings["port"] %>
</p>
<p>
<label><%= l(:rabbitmq_label_trakers) %></label>
<%= text_field_tag "settings[trakers_list]", @settings["trakers_list"] %>
</p>
</fieldset>
<fieldset class="box" id="rabbitmq_trackers_tracker_ids"><legend><%= toggle_checkboxes_link("#rabbitmq_trackers_tracker_ids input[type=checkbox]") %><%=l(:label_tracker_plural)%></legend>
<% 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 %>
</fieldset>
<fieldset class="box" id="rabbitmq_project_ids"><legend><%= toggle_checkboxes_link("#rabbitmq_project_ids input[type=checkbox]:enabled") %><%= l(:label_project_plural) %></legend>
<div id="custom_field_project_ids">
<% 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 %>
</div>
</fieldset>

View File

@ -6,4 +6,3 @@ en:
rabbitmq_label_exchange: Exchange
rabbitmq_label_server: Server
rabbitmq_label_port: Port
rabbitmq_label_trakers: Allowed for trackers(id)

View File

@ -6,4 +6,3 @@ ru:
rabbitmq_label_exchange: Канал обмена
rabbitmq_label_server: Сервер
rabbitmq_label_port: Порт
rabbitmq_label_trakers: Разрешено для трекеров(id)

View File

@ -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

View File

@ -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