Feature #4511 » 0004-Use-scope-assignable_watchers.patch
| app/controllers/watchers_controller.rb | ||
|---|---|---|
| 43 | 43 |
user_ids << params[:user_id] |
| 44 | 44 |
end |
| 45 | 45 |
user_ids = user_ids.flatten.compact.uniq |
| 46 |
users = Principal.active.visible.where(:id => user_ids).where(:users => {:type => ['User', 'Group']}).to_a
|
|
| 46 |
users = Principal.assignable_watchers.where(:id => user_ids).to_a
|
|
| 47 | 47 |
users.each do |user| |
| 48 | 48 |
@watchables.each do |watchable| |
| 49 | 49 |
Watcher.create(:watchable => watchable, :user => user) |
| ... | ... | |
| 59 | 59 |
def append |
| 60 | 60 |
if params[:watcher] |
| 61 | 61 |
user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] |
| 62 |
@users = Principal.active.visible.where(:id => user_ids).where(:users => {:type => ['User', 'Group']}).to_a
|
|
| 62 |
@users = Principal.assignable_watchers.where(:id => user_ids).to_a
|
|
| 63 | 63 |
end |
| 64 | 64 |
if @users.blank? |
| 65 | 65 |
head 200 |
| ... | ... | |
| 122 | 122 |
def users_for_new_watcher |
| 123 | 123 |
scope = nil |
| 124 | 124 |
if params[:q].blank? && @project.present? |
| 125 |
scope = @project.principals.where(:users => {:type => ['User', 'Group']})
|
|
| 125 |
scope = @project.principals.assignable_watchers
|
|
| 126 | 126 |
else |
| 127 |
scope = Principal.where(:users => {:type => ['User', 'Group']}).limit(100)
|
|
| 127 |
scope = Principal.assignable_watchers.limit(100)
|
|
| 128 | 128 |
end |
| 129 |
users = scope.active.visible.sorted.like(params[:q]).to_a
|
|
| 129 |
users = scope.sorted.like(params[:q]).to_a |
|
| 130 | 130 |
if @watchables && @watchables.size == 1 |
| 131 | 131 |
users -= @watchables.first.watcher_users |
| 132 | 132 |
end |
| app/helpers/issues_helper.rb | ||
|---|---|---|
| 364 | 364 |
# on the new issue form |
| 365 | 365 |
def users_for_new_issue_watchers(issue) |
| 366 | 366 |
users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}
|
| 367 |
project_principals = issue.project.principals.where(:users => {:type => ['User', 'Group']}).limit(21)
|
|
| 368 |
if project_principals.size <= 20
|
|
| 369 |
users += project_principals.sort
|
|
| 367 |
assignable_watchers = issue.project.principals.assignable_watchers.limit(21)
|
|
| 368 |
if assignable_watchers.size <= 20
|
|
| 369 |
users += assignable_watchers.sort
|
|
| 370 | 370 |
end |
| 371 | 371 |
users.uniq |
| 372 | 372 |
end |
| app/models/principal.rb | ||
|---|---|---|
| 114 | 114 |
} |
| 115 | 115 |
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
|
| 116 | 116 | |
| 117 |
# Principals that can be added as watchers |
|
| 118 |
scope :assignable_watchers, lambda { active.visible.where(:type => ['User', 'Group']) }
|
|
| 119 | ||
| 117 | 120 |
before_create :set_default_empty_values |
| 118 | 121 |
before_destroy :nullify_projects_default_assigned_to |
| 119 | 122 | |
| lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb | ||
|---|---|---|
| 31 | 31 | |
| 32 | 32 |
# Returns an array of users that are proposed as watchers |
| 33 | 33 |
def addable_watcher_users |
| 34 |
users = self.project.principals.where(:users => {:type => ['User', 'Group']}).sort - self.watcher_users
|
|
| 34 |
users = self.project.principals.assignable_watchers.sort - self.watcher_users
|
|
| 35 | 35 |
if respond_to?(:visible?) |
| 36 | 36 |
users.reject! {|user| user.is_a?(User) && !visible?(user)}
|
| 37 | 37 |
end |