Feature #2055 ยป 2055_git.diff
| app/models/query.rb | ||
|---|---|---|
|
user_values = []
|
||
|
user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
|
||
|
if project
|
||
|
user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
|
||
|
user_values += User.in_project_hierarchy_of(project).sort.collect{|s| [s.name, s.id.to_s] }
|
||
|
else
|
||
|
project_ids = User.current.projects.collect(&:id)
|
||
|
if project_ids.any?
|
||
|
# members of the user's projects
|
||
|
user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort.collect{|s| [s.name, s.id.to_s] }
|
||
|
projects = User.current.projects
|
||
|
if projects.any?
|
||
|
# members of the user's projects and subprojects
|
||
|
user_values += User.in_project_hierarchy_of(projects).sort.collect{|s| [s.name, s.id.to_s] }
|
||
|
end
|
||
|
end
|
||
|
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
|
||
| app/models/user.rb | ||
|---|---|---|
|
find(:first, :conditions => ["LOWER(mail) = ?", mail.to_s.downcase])
|
||
|
end
|
||
|
|
||
|
# Active members of project or subprojects
|
||
|
def self.in_project_hierarchy_of(projects)
|
||
|
projects = [projects] unless projects.is_a?(Array)
|
||
|
#add the (visible) subprojects
|
||
|
projects = projects.map do |project|
|
||
|
project.self_and_descendants.all(:conditions => Project.visible_by(User.current))
|
||
|
end.flatten
|
||
|
#search active users in all these projects
|
||
|
active.all(
|
||
|
:conditions => [ "#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))",
|
||
|
projects.map(&:id) ]
|
||
|
)
|
||
|
end
|
||
|
|
||
|
def to_s
|
||
|
name
|
||
|
end
|
||
| test/fixtures/members.yml | ||
|---|---|---|
|
project_id: 2
|
||
|
user_id: 8
|
||
|
mail_notification: false
|
||
|
members_011:
|
||
|
id: 11
|
||
|
created_on: 2006-07-19 19:35:33 +02:00
|
||
|
project_id: 3
|
||
|
user_id: 8
|
||
|
mail_notification: false
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
assert !q.editable_by?(manager)
|
||
|
assert !q.editable_by?(developer)
|
||
|
end
|
||
|
context "#available_filters" do
|
||
|
should "include users of subprojects" do
|
||
|
query = Query.new(:project => Project.find(1), :name => '_')
|
||
|
users = query.available_filters["assigned_to_id"][:values]
|
||
|
assert users.map{|u|u[1]}.include?("8")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/unit/user_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
context "User#in_project_hierarchy_of" do
|
||
|
should "return users of projets AND subprojects" do
|
||
|
#Project(3) is child of Project(1)
|
||
|
#User(8) is only member of Project(3)
|
||
|
users = User.in_project_hierarchy_of(Project.find(1))
|
||
|
assert users.map(&:id).include?(8)
|
||
|
end
|
||
|
|
||
|
should "not return users of subprojects not visible by current user" do
|
||
|
#Project(5) is private child of Project(1)
|
||
|
#User(1) is in Project(5), but not current user (Anonymous)
|
||
|
users = User.in_project_hierarchy_of(Project.find(1))
|
||
|
assert !users.map(&:id).include?(1)
|
||
|
end
|
||
|
end
|
||
|
def test_roles_for_project
|
||
|
# user with a role
|
||
|
roles = @jsmith.roles_for_project(Project.find(1))
|
||