Patch #44795 ยป 0001-Exclude-email-addresses-from-the-project-members-filter-44581.patch
| app/models/member.rb | ||
|---|---|---|
|
joins(:project).
|
||
|
where(Project.allowed_to_condition(args.shift || User.current, :view_members, *args))
|
||
|
end)
|
||
|
# Members whose principal matches the given string
|
||
|
# Members whose principal name or login matches the given string
|
||
|
# (email addresses are not searched since they are not displayed in the members list)
|
||
|
scope :like, (lambda do |arg|
|
||
|
if arg.present?
|
||
|
where(:user_id => Principal.like(arg).select(:id))
|
||
|
where(:user_id => Principal.like(arg, mail: false).select(:id))
|
||
|
end
|
||
|
end)
|
||
|
# Members having the given role, inherited or not
|
||
| app/models/principal.rb | ||
|---|---|---|
|
end
|
||
|
end)
|
||
|
scope :like, (lambda do |q|
|
||
|
# Principals whose login, name or email address matches the given string.
|
||
|
# Email addresses are not searched when mail is false.
|
||
|
scope :like, (lambda do |q, mail: true|
|
||
|
q = q.to_s
|
||
|
if q.blank?
|
||
|
where({})
|
||
|
else
|
||
|
pattern = "%#{sanitize_sql_like q}%"
|
||
|
sql = "LOWER(#{table_name}.login) LIKE LOWER(:p) ESCAPE :s"
|
||
|
sql << " OR #{table_name}.id IN (SELECT user_id FROM #{EmailAddress.table_name} WHERE LOWER(address) LIKE LOWER(:p) ESCAPE :s)"
|
||
|
if mail
|
||
|
sql << " OR #{table_name}.id IN (SELECT user_id FROM #{EmailAddress.table_name} WHERE LOWER(address) LIKE LOWER(:p) ESCAPE :s)"
|
||
|
end
|
||
|
params = {:p => pattern, :s => '\\'}
|
||
|
tokens = q.split(/\s+/).reject(&:blank?).map {|token| "%#{sanitize_sql_like token}%"}
|
||
| test/functional/members_controller_test.rb | ||
|---|---|---|
|
assert_select 'tr#member-1'
|
||
|
end
|
||
|
def test_index_html_filter_by_email_address_should_not_find_the_member
|
||
|
with_settings :login_required => '0' do
|
||
|
@request.session[:user_id] = nil
|
||
|
get(:index, :params => {:project_id => 1, :member_name => 'jsmith@somenet'})
|
||
|
assert_response :success
|
||
|
assert_select 'tr#member-1', :count => 0
|
||
|
end
|
||
|
end
|
||
|
def test_index_html_filter_by_role
|
||
|
get(:index, :params => {:project_id => 1, :member_role_id => 2})
|
||
|
assert_response :success
|
||
| test/unit/member_test.rb | ||
|---|---|---|
|
assert_equal [9], Project.find(2).memberships.like('B Team').ids
|
||
|
end
|
||
|
def test_like_scope_should_match_login
|
||
|
assert_equal [1], Project.find(1).memberships.like('jsmi').ids
|
||
|
end
|
||
|
def test_like_scope_should_not_match_email_addresses
|
||
|
assert_empty Project.find(1).memberships.like('jsmith@somenet').ids
|
||
|
end
|
||
|
def test_like_scope_with_blank_value_should_return_all_the_members
|
||
|
project = Project.find(1)
|
||
|
assert_equal project.memberships.ids.sort, project.memberships.like('').ids.sort
|
||
| test/unit/principal_test.rb | ||
|---|---|---|
|
assert results.all? {|u| u.mail.match(/somenet/i)}
|
||
|
end
|
||
|
test "like scope should not search mail if mail option is false" do
|
||
|
assert_include User.find(2), Principal.like('jsmith@somenet')
|
||
|
assert_not_include User.find(2), Principal.like('jsmith@somenet', mail: false)
|
||
|
assert_include User.find(2), Principal.like('jsmi', mail: false)
|
||
|
assert_include User.find(2), Principal.like('john smi', mail: false)
|
||
|
end
|
||
|
test "like scope should search firstname and lastname" do
|
||
|
results = Principal.like('john smi')
|
||