Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
36b0b1d
Modifications for Rails 3-4
Oct 27, 2015
be1e7e9
fix when creatting new Issue
Oct 27, 2015
ec59ac1
Changed header in README.doc; added FOR REDMINE 3.x.x
Oct 27, 2015
f1d2fc8
fixed rendering for for new issue after change of tracker #4511
Nov 20, 2015
b3c9d88
add Japanese localization
hhokawa777 Nov 29, 2015
670e937
Merge pull request #1 from team888/ja_localization
foton Nov 30, 2015
0d316fe
CS translation added
Nov 30, 2015
13250d7
Fixed degradation of User::ActiveRecord_Associations_CollectionProxy …
Jun 21, 2017
7bc61de
Since any array manipulation will fudge the proxy object and degrade …
Jun 21, 2017
d8ecd26
Only add the reset() method if the object class actually changed, sin…
Jul 25, 2017
7c1c52d
Removed logging of user list class display
Jul 25, 2017
9514a8d
Applied correction sugested on http://www.redmine.org/issues/4511#not…
Jul 27, 2017
7f271d2
Merge pull request #2 from darksoul42/master
foton Aug 8, 2017
6383df7
Added German translation, fixing Czech language file
deining Aug 16, 2017
a53d6d4
Added support for log recording without redmine_advanced_issue_histor…
Aug 18, 2017
588a2fd
Merge branch 'master' into master
darksoul42 Aug 18, 2017
b50408d
Merge pull request #1 from deining/master
darksoul42 Aug 18, 2017
7f2bccd
Merge pull request #3 from darksoul42/master
foton Aug 19, 2017
8a50351
Added translation of labels for settings screen
Aug 21, 2017
3b2120c
Fixed the notification muting of individual users
Aug 21, 2017
8e114e0
Replaced reference to description label
Aug 21, 2017
9695ab0
Merge pull request #4 from darksoul42/master
foton Aug 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Redmine Watcher Groups
= Redmine Watcher Groups for Redmine 3.x.x

Plugin for Redmine that adds functionality to have Watcher Groups in addition to Watchers.

Expand Down
38 changes: 24 additions & 14 deletions app/controllers/watcher_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ def create
@watched.set_watcher_group(group, true)
find_watcher_users = find_watcher_users | group.users
end
if find_watcher_users.any? and Redmine::Plugin.installed? :redmine_advanced_issue_history
notes = []
find_watcher_users.each do |user|
notes.append("Watcher #{user.name} was added")
end
add_system_journal(notes, issue)
end
if find_watcher_users.any?
if Setting['plugin_redmine_watcher_groups']['redmine_watcher_groups_log_watchers_setting'] == 'yes'
if Redmine::Plugin.installed? :redmine_advanced_issue_history
notes = []
find_watcher_users.each do |user|
notes.append("Watcher #{user.name} was added")
end
add_system_journal(notes, issue)
else
issue.add_watcher_journal(:label_watcher_group_add, group_ids.flatten.compact.uniq.collect { |group_id| Group.find(group_id).name }.join(", "))
end
end
end
end
end
respond_to do |format|
Expand All @@ -49,12 +55,16 @@ def destroy
issue = Issue.find(params[:object_id])
group_users = group.users
if group_users.any?
if Redmine::Plugin.installed? :redmine_advanced_issue_history
notes = []
group_users.each do |user|
notes.append("Watcher #{user.name} was removed")
end
add_system_journal(notes, issue)
if Setting['plugin_redmine_watcher_groups']['redmine_watcher_groups_log_watchers_setting'] == 'yes'
if Redmine::Plugin.installed? :redmine_advanced_issue_history
notes = []
group_users.each do |user|
notes.append("Watcher #{user.name} was removed")
end
add_system_journal(notes, issue)
else
issue.add_watcher_journal(:label_watcher_group_remove, group.name)
end
end
end
end
Expand All @@ -66,7 +76,7 @@ def destroy
end

def autocomplete_for_group
@groups = Group.active.like(params[:q]).find(:all, :limit => 100)
@groups = Group.sorted.active.like(params[:q]).limit(100)
if @watched
@groups -= @watched.watcher_groups
end
Expand Down
18 changes: 12 additions & 6 deletions app/views/issues/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h2><%=l(:label_issue_new)%></h2>
<%= title l(:label_issue_new) %>

<%= call_hook(:view_issues_new_top, {:issue => @issue}) %>

<%= labelled_form_for @issue, :url => project_issues_path(@project),
<%= labelled_form_for @issue, :url => _project_issues_path(@project),
:html => {:id => 'issue-form', :multipart => true} do |f| %>
<%= error_messages_for 'issue' %>
<%= hidden_field_tag 'copy_from', params[:copy_from] if params[:copy_from] %>
Expand All @@ -11,6 +11,12 @@
<%= render :partial => 'issues/form', :locals => {:f => f} %>
</div>

<% if @copy_from && Setting.link_copied_issue == 'ask' %>
<p>
<label for="link_copy"><%= l(:label_link_copied_issue) %></label>
<%= check_box_tag 'link_copy', '1', @link_copy %>
</p>
<% end %>
<% if @copy_from && @copy_from.attachments.any? %>
<p>
<label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
Expand All @@ -26,10 +32,10 @@

<p id="attachments_form"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @issue} %></p>

<% if @issue.safe_attribute? 'watcher_user_ids' %>
<% if @issue.safe_attribute? 'watcher_user_ids' -%>
<p id="watchers_form"><label><%= l(:label_issue_watchers) %></label>
<span id="watchers_inputs">
<%= watchers_checkboxes(@issue, @available_watchers) %>
<%= watchers_checkboxes(@issue, users_for_new_issue_watchers(@issue)) %>
</span>
<span class="search_for_watchers">
<%= link_to l(:label_search_for_watchers),
Expand All @@ -49,9 +55,9 @@

<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
<%= preview_link preview_new_issue_path(:project_id => @project), 'issue-form' %>
<%= preview_link preview_new_issue_path(:project_id => @issue.project), 'issue-form' %>

<%= javascript_tag "$('#issue_subject').focus();" %>
<%#= javascript_tag "$('#issue_subject').focus();" %>
<% end %>

<div id="preview" class="wiki"></div>
Expand Down
10 changes: 10 additions & 0 deletions app/views/settings/_redmine_watcher_groups_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>
<%= label_tag 'redmine_watcher_groups_log_watchers_setting', l(:label_watcher_change_setlog) %>
<%=
select_tag 'settings[redmine_watcher_groups_log_watchers_setting]', options_for_select([
[l(:general_text_No), 'no'],
[l(:general_text_Yes), 'yes'],
], @settings['redmine_watcher_groups_log_watchers_setting']) %>
<%=l(:label_watcher_change_setlog_description) %>
</p>

2 changes: 1 addition & 1 deletion app/views/watcher_groups/_new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div id="groups_for_watcher">
<%= principals_check_box_tags 'watcher_group[group_ids][]', (
# watched ? watched.addable_watcher_groups :
Group.sorted.active.all(:limit => 100)) %>
Group.sorted.active.limit(100) ) %>
</div>

<p class="buttons">
Expand Down
3 changes: 3 additions & 0 deletions config/locales/bg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bg:
label_watcher_change_setlog: "Запис в историята на задачата? "
label_watcher_change_setlog_description: "Промяната ще бъде записана в историята на задачата"
4 changes: 4 additions & 0 deletions config/locales/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Czech strings go here for Rails i18n
cs:
label_issue_watcher_groups: "Sledováno skupinami"
label_group_search: "Vyhledání skupiny:"
7 changes: 7 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# German strings go here for Rails i18n
de:
my_label: "Meine Kennung"
label_issue_watcher_groups: "Beobachtergruppen"
label_group_search: "Suche nach Gruppe:"
label_watcher_change_setlog: "Änderung in Issue-History loggen? "
label_watcher_change_setlog_description: "Alle Änderungen werden in der Bearbeitungshistorie des Tickets nachvollziehbar geloggt"
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# English strings go here for Rails i18n
en:
my_label: "My label"
label_issue_watcher_groups: "Watcher Groups"
label_group_search: "Search for group:"
label_watcher_user_add: "'%{name}' added user(s) '%{target_name}' to watchers"
label_watcher_user_remove: "'%{name}' removed user(s) '%{target_name}' from watchers"
label_watcher_group_add: "'%{name}' added group(s) '%{target_name}' to watchers"
label_watcher_group_remove: "'%{name}' removed group(s) '%{target_name}' from watchers"
label_watcher_change_setlog: "Log in issue history? "
label_watcher_change_setlog_description: "Changes will be logged in history of that issue"
3 changes: 3 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
es:
label_watcher_change_setlog: "¿Registrar en el historial de la petición? "
label_watcher_change_setlog_description: "Los cambios serán registrados en el historial de la petición"
1 change: 0 additions & 1 deletion config/locales/it.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
it:
my_label: "Etichetta"
label_issue_watcher_groups: "Gruppi osservatori"
label_group_search: "Cerca un gruppo:"
10 changes: 10 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Japanese strings go here for Rails i18n
ja:
label_issue_watcher_groups: "ウォッチャーグループ"
label_group_search: "グループの検索:"
label_watcher_user_add: "「%{name}」がユーザ「%{target_name}」をウォッチャーに追加しました"
label_watcher_user_remove: "「%{name}」がユーザ「%{target_name}」をウォッチャーから外しました"
label_watcher_group_add: "「%{name}」がグループ「%{target_name}」をウォッチャーに追加しました"
label_watcher_group_remove: "「%{name}」がグループ「%{target_name}」をウォッチャーから外しました"
label_watcher_change_setlog: "チケット履歴に記録しますか? "
label_watcher_change_setlog_description: "変更はそのチケット履歴に記録されます"
3 changes: 3 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nl:
label_watcher_change_setlog: "Wijzigingen tonen in de geschiedenis? "
label_watcher_change_setlog_description: "Veranderingen zullen worden weergegeven in de geschiedenis van de ticket"
3 changes: 3 additions & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ru:
label_watcher_change_setlog: "Делать запись в журнал? "
label_watcher_change_setlog_description: "Измнение будет внесено в журнал данного документа"
3 changes: 3 additions & 0 deletions config/locales/tr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tr:
label_watcher_change_setlog: "Tarihçeye kayıt? "
label_watcher_change_setlog_description: "Evet seçilirse bu değişikliğin kimin tarafından ne zaman yapıldığı işin tarihçesine eklenir."
3 changes: 3 additions & 0 deletions config/locales/zh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zh:
label_watcher_change_setlog: "记录到问题历史? "
label_watcher_change_setlog_description: "更改将会记录到该问题历史里"
8 changes: 7 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
IssuesController.send(:include, WatcherGroupsIssuesControllerPatch)
end

unless WatchersController.included_modules.include?(WatcherGroupsWatchersControllerPatch)
WatchersController.send(:include, WatcherGroupsWatchersControllerPatch)
end

end

Redmine::Plugin.register :redmine_watcher_groups do
name 'Redmine Watcher Groups plugin'
author 'Kamen Ferdinandov, Massimo Rossello'
author 'Kamen Ferdinandov, Massimo Rossello, Stephane Lapie'
description 'This is a plugin for Redmine to add watcher groups functionality'
version '1.0.0'
url 'http://github.com/maxrossello/redmine_watcher_groups'
author_url 'http://github.com/maxrossello'

settings :default => {"redmine_watcher_groups_log_watchers_setting" => 'no'}, :partial => 'settings/redmine_watcher_groups_settings'
end
1 change: 1 addition & 0 deletions lib/watcher_groups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def watcher_groups_checkboxes(object, groups, checked=nil)
:class => "floating"
end.join.html_safe
end

def watchers_list(object)
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
content = ''.html_safe
Expand Down
26 changes: 15 additions & 11 deletions lib/watcher_groups_issue_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ def controller_issues_new_after_save(context={})
context[:issue].save
context[:issue].reload

notes = []
group_ids = context[:params][:issue]["watcher_group_ids"]
group_ids.each do |group_id|
group_users = Group.find(group_id.to_i).users.uniq
group_users.each do |user|
notes.append("Watcher #{user.name} was added")
end
end

if notes.any? and Redmine::Plugin.installed? :redmine_advanced_issue_history
add_system_journal(notes, context[:issue])
if Setting['plugin_redmine_watcher_groups']['redmine_watcher_groups_log_watchers_setting'] == 'yes'
group_ids = context[:params][:issue]["watcher_group_ids"]
if Redmine::Plugin.installed? :redmine_advanced_issue_history
notes = []
group_ids.each do |group_id|
group_users = Group.find(group_id.to_i).users.uniq
group_users.each do |user|
notes.append("Watcher #{user.name} was added")
end
end
add_system_journal(notes, context[:issue]) if notes.any?
else
watcher_name = group_ids.collect { |group_id| Group.find(group_id).name }.join(", ")
context[:issue].add_watcher_journal(:label_watcher_group_add, watcher_name)
end
end
end

Expand Down
43 changes: 29 additions & 14 deletions lib/watcher_groups_issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.included(base) # :nodoc:
alias_method_chain :notified_watchers , :groups
alias_method_chain :watched_by? , :groups
alias_method_chain :watcher_users, :users
alias_method_chain :set_watcher, :journal
end
end

Expand All @@ -19,10 +20,18 @@ def self.included(base) # :nodoc:
joins(:watchers).where("#{Watcher.table_name}.user_id IN (#{user.id} #{g.empty? ? "" : ","} #{g.map(&:id).join(',')})")
}

def add_watcher_journal(action, watcher_name)
if Setting['plugin_redmine_watcher_groups']['redmine_watcher_groups_log_watchers_setting'] == 'yes'
journal = self.init_journal(User.current, l(action, :name => User.current.name, :target_name => watcher_name).html_safe)
journal.save
end
end

def watcher_groups
if self.id
groups = Watcher.find(:all, :conditions => "watchable_type='#{self.class}' and watchable_id = #{self.id}")
Group.find_all_by_id(groups.map(&:user_id))
groups = Watcher.where("watchable_type='#{self.class}' and watchable_id = #{self.id}")
return [] if groups.empty?
Group.where(id: groups.map(&:user_id))
end
end

Expand Down Expand Up @@ -51,9 +60,7 @@ def addable_watcher_groups

# Adds group as a watcher
def add_watcher_group(group)
if Watcher.find(:all,
:conditions => "watchable_type='#{self.class}' and watchable_id = #{self.id} and user_id = '#{group.id}'",
:limit => 1).blank?
if Watcher.where("watchable_type='#{self.class}' and watchable_id = #{self.id} and user_id = '#{group.id}'").limit(1).blank?
# insert directly into table to avoid user type checking
Watcher.connection.execute("INSERT INTO #{Watcher.table_name} (user_id, watchable_id, watchable_type) VALUES (#{group.id}, #{self.id}, '#{self.class.name}')")
end
Expand All @@ -80,24 +87,24 @@ def watched_by_group?(group)
module InstanceMethods
def notified_watchers_with_groups
notified = []

w = Watcher.find(:all, :conditions => "watchable_type='#{self.class}' and watchable_id = #{self.id}")
groups = Group.find_all_by_id(w.map(&:user_id))
w = Watcher.where("watchable_type='#{self.class}' and watchable_id = #{self.id}")
groups = Group.where(id: w.map(&:user_id))

groups.each do |p|
group_users = p.users
group_users = p.users.to_a
group_users.reject! {|user| user.mail.blank? || user.mail_notification == 'none'}
if respond_to?(:visible?)
group_users.reject! {|user| !visible?(user)}
end
notified += group_users
notified |= group_users
end
notified += watcher_users

notified |= watcher_users.to_a
notified.reject! {|user| user.mail.blank? || user.mail_notification == 'none'}
if respond_to?(:visible?)
notified.reject! {|user| !visible?(user)}
end
notified.uniq
notified
end

def watched_by_with_groups?(user)
Expand All @@ -109,10 +116,18 @@ def watched_by_with_groups?(user)

def watcher_users_with_users
users = watcher_users_without_users
old_object = users
watcher_groups.each do |g|
users += g.users
users |= g.users
end if self.id?
users.uniq
users.define_singleton_method(:reset) do old_object.reset end if old_object.class != users.class
users
end

def set_watcher_with_journal(user, watching=true)
result = set_watcher_without_journal(user, watching)
self.add_watcher_journal((watching ? :label_watcher_user_add : :label_watcher_user_remove), user.name)
result
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/watcher_groups_issues_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ def self.included(base) # :nodoc:
base.class_eval do
helper :watcher_groups
include WatcherGroupsHelper

def new
respond_to do |format|
format.html {
render :action => 'new', :layout => !request.xhr?
}
format.js {
#this is needed for proper rendering /projects/:project/issues/new.js
render :action => 'new', formats: [:js], :layout => false
}
end
end
end
end

Expand Down
26 changes: 26 additions & 0 deletions lib/watcher_groups_watchers_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module WatcherGroupsWatchersControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :create, :journal
end
end

WatchersController.class_eval do
module InstanceMethods
def create_with_journal
create_without_journal
user_ids = []
if params[:watcher].is_a?(Hash)
user_ids << (params[:watcher][:user_ids] || params[:watcher][:user_id])
else
user_ids << params[:user_id]
end
@watchables.each do |watched|
watched.add_watcher_journal(:label_watcher_user_add, user_ids.flatten.compact.uniq.collect { |user_id| User.find(user_id).name }.join(", "))
end
end
end
end
end