diff options
author | Go MAEDA <maeda@farend.jp> | 2020-02-06 08:19:13 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-02-06 08:19:13 +0000 |
commit | b995014c495b36102f36ec80618f50f3763bcd6f (patch) | |
tree | 85c230cf16c300f51f9716299ff7bc48d300c4cf /app | |
parent | 29433771b45319a0b50f182f0dcaf72db1275a30 (diff) | |
download | redmine-b995014c495b36102f36ec80618f50f3763bcd6f.tar.gz redmine-b995014c495b36102f36ec80618f50f3763bcd6f.zip |
Allow adding user groups as watchers for issues (#4511).
Patch by Yuichi HARADA.
git-svn-id: http://svn.redmine.org/redmine/trunk@19498 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/watchers_controller.rb | 12 | ||||
-rw-r--r-- | app/helpers/avatars_helper.rb | 6 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 7 | ||||
-rw-r--r-- | app/helpers/watchers_helper.rb | 2 | ||||
-rw-r--r-- | app/models/group.rb | 1 | ||||
-rw-r--r-- | app/models/query.rb | 4 | ||||
-rw-r--r-- | app/models/watcher.rb | 5 |
7 files changed, 27 insertions, 10 deletions
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index f0692e31d..e0de27464 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -42,7 +42,9 @@ class WatchersController < ApplicationController else user_ids << params[:user_id] end - users = User.active.visible.where(:id => user_ids.flatten.compact.uniq) + user_ids = user_ids.flatten.compact.uniq + users = User.active.visible.where(:id => user_ids).to_a + users += Group.givable.active.visible.where(:id => user_ids).to_a users.each do |user| @watchables.each do |watchable| Watcher.create(:watchable => watchable, :user => user) @@ -59,6 +61,7 @@ class WatchersController < ApplicationController if params[:watcher] user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] @users = User.active.visible.where(:id => user_ids).to_a + @users += Group.givable.active.visible.where(:id => user_ids).to_a end if @users.blank? head 200 @@ -66,7 +69,7 @@ class WatchersController < ApplicationController end def destroy - user = User.find(params[:user_id]) + user = Principal.find(params[:user_id]) @watchables.each do |watchable| watchable.set_watcher(user, false) end @@ -119,13 +122,16 @@ class WatchersController < ApplicationController end def users_for_new_watcher - scope = nil + scope, scope_groups = nil if params[:q].blank? && @project.present? scope = @project.users + scope_groups = @project.principals.merge(Group.givable) else scope = User.all.limit(100) + scope_groups = Group.givable.limit(100) end users = scope.active.visible.sorted.like(params[:q]).to_a + users += scope_groups.active.visible.sorted.like(params[:q]).to_a if @watchables && @watchables.size == 1 users -= @watchables.first.watcher_users end diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb index 7e2a1fffd..49be006a8 100644 --- a/app/helpers/avatars_helper.rb +++ b/app/helpers/avatars_helper.rb @@ -51,6 +51,8 @@ module AvatarsHelper gravatar(email.to_s.downcase, options) rescue nil elsif user.is_a?(AnonymousUser) anonymous_avatar(options) + elsif user.is_a?(Group) + group_avatar(options) else nil end @@ -72,4 +74,8 @@ module AvatarsHelper def anonymous_avatar(options={}) image_tag 'anonymous.png', GravatarHelper::DEFAULT_OPTIONS.except(:default, :rating, :ssl).merge(options) end + + def group_avatar(options={}) + image_tag 'group.png', GravatarHelper::DEFAULT_OPTIONS.except(:default, :rating, :ssl).merge(options) + end end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 2ea81d566..0f327b77e 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -365,8 +365,11 @@ module IssuesHelper # on the new issue form def users_for_new_issue_watchers(issue) users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE} - if issue.project.users.count <= 20 - users = (users + issue.project.users.sort).uniq + project = issue.project + scope_users = project.users + scope_groups = project.principals.merge(Group.givable) + if scope_users.count + scope_groups.count <= 20 + users = (users + scope_users.sort + scope_groups.sort).uniq end users end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index dab5e6b76..ac732c339 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -47,7 +47,7 @@ module WatchersHelper def watchers_list(object) remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) content = ''.html_safe - lis = object.watcher_users.preload(:email_address).collect do |user| + lis = object.watcher_users.collect do |user| s = ''.html_safe s << avatar(user, :size => "16").to_s s << link_to_user(user, :class => 'user') diff --git a/app/models/group.rb b/app/models/group.rb index 21166f1af..c1106e07f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -115,6 +115,7 @@ class Group < Principal return if self.id.nil? Issue.where(['assigned_to_id = ?', id]).update_all('assigned_to_id = NULL') + Watcher.where('user_id = ?', id).delete_all end end diff --git a/app/models/query.rb b/app/models/query.rb index 0e38b47d8..5672a6e9e 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -600,7 +600,7 @@ class Query < ActiveRecord::Base def watcher_values watcher_values = [["<< #{l(:label_me)} >>", "me"]] - watcher_values += users.sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] } if User.current.allowed_to?(:view_issue_watchers, self.project) + watcher_values += principals.sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] } if User.current.allowed_to?(:view_issue_watchers, self.project) watcher_values end @@ -913,7 +913,7 @@ class Query < ActiveRecord::Base if v.delete("me") if User.current.logged? v.push(User.current.id.to_s) - v += User.current.group_ids.map(&:to_s) if field == 'assigned_to_id' + v += User.current.group_ids.map(&:to_s) if %w(assigned_to_id watcher_id).include?(field) else v.push("0") end diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 8ea457060..15bfaa6db 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -19,7 +19,7 @@ class Watcher < ActiveRecord::Base belongs_to :watchable, :polymorphic => true - belongs_to :user + belongs_to :user, :class_name => 'Principal' validates_presence_of :user validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id] @@ -54,7 +54,8 @@ class Watcher < ActiveRecord::Base protected def validate_user - errors.add :user_id, :invalid unless user.nil? || user.active? + errors.add :user_id, :invalid \ + unless user.nil? || (user.is_a?(User) && user.active?) || (user.is_a?(Group) && user.givable?) end def self.prune_single_user(user, options={}) |