Commit 0be65110 authored by jplang's avatar jplang

Adds a scope to get issues assigned to a user.

git-svn-id: https://svn.redmine.org/redmine/trunk@14720 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 5343b386
......@@ -33,7 +33,7 @@ module MyHelper
def issuesassignedtome_items
Issue.visible.open.
where(:assigned_to_id => ([User.current.id] + User.current.group_ids)).
assigned_to(User.current).
limit(10).
includes(:status, :project, :tracker, :priority).
references(:status, :project, :tracker, :priority).
......
......@@ -95,6 +95,13 @@ class Issue < ActiveRecord::Base
ids = [versions].flatten.compact.map {|v| v.is_a?(Version) ? v.id : v}
ids.any? ? where(:fixed_version_id => ids) : where('1=0')
}
scope :assigned_to, lambda {|arg|
arg = Array(arg).uniq
ids = arg.map {|p| p.is_a?(Principal) ? p.id : p}
ids += arg.select {|p| p.is_a?(User)}.map(&:group_ids).flatten.uniq
ids.compact!
ids.any? ? where(:assigned_to_id => ids) : none
}
before_validation :clear_disabled_fields
before_create :default_assign
......
......@@ -27,7 +27,7 @@
<ul>
<li><%= link_to l(:label_assigned_issues),
issues_path(:set_filter => 1, :assigned_to_id => 'me', :sort => 'priority:desc,updated_on:desc') %>:
<%= Issue.visible.open.where(:assigned_to_id => ([@user.id] + @user.group_ids)).count %>
<%= Issue.visible.open.assigned_to(@user).count %>
<li><%= link_to l(:label_reported_issues),
issues_path(:set_filter => 1, :status_id => '*', :author_id => @user.id) %>:
<%= Issue.visible.where(:author_id => @user.id).count %>
......
......@@ -418,6 +418,22 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 0, Issue.fixed_version([]).count
end
def test_assigned_to_scope_should_return_issues_assigned_to_the_user
user = User.generate!
issue = Issue.generate!
Issue.where(:id => issue.id).update_all :assigned_to_id => user.id
assert_equal [issue], Issue.assigned_to(user).to_a
end
def test_assigned_to_scope_should_return_issues_assigned_to_the_user_groups
group = Group.generate!
user = User.generate!
group.users << user
issue = Issue.generate!
Issue.where(:id => issue.id).update_all :assigned_to_id => group.id
assert_equal [issue], Issue.assigned_to(user).to_a
end
def test_errors_full_messages_should_include_custom_fields_errors
field = IssueCustomField.find_by_name('Database')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment