Feature #44261 ยป mention_restrict_to_project_members.patch
| app/controllers/watchers_controller.rb | ||
|---|---|---|
| 175 | 175 |
q = params[:q].to_s.strip |
| 176 | 176 | |
| 177 | 177 |
scope = nil |
| 178 |
if params[:q].blank? && @project.present? |
|
| 179 |
scope = @project.principals.assignable_watchers.limit(100) |
|
| 178 |
if @project.present? |
|
| 179 |
scope = @project.principals.assignable_watchers |
|
| 180 |
scope = scope.limit(10) if params[:q].present? |
|
| 180 | 181 |
else |
| 181 | 182 |
scope = Principal.assignable_watchers.limit(10) |
| 182 | 183 |
end |
| lib/redmine/acts/mentionable.rb | ||
|---|---|---|
| 71 | 71 |
new_matches = (current_matches - previous_matches).flatten |
| 72 | 72 | |
| 73 | 73 |
if new_matches.any? |
| 74 |
self.mentioned_users = User.visible.active.where(login: new_matches) |
|
| 74 |
scope = User.visible.active.where(login: new_matches) |
|
| 75 |
if respond_to?(:project) && project |
|
| 76 |
scope = scope.where(admin: true).or(scope.where(id: project.principals.select(:id))) |
|
| 77 |
end |
|
| 78 |
self.mentioned_users = scope |
|
| 75 | 79 |
end |
| 76 | 80 |
end |
| 77 | 81 | |
| test/functional/watchers_controller_test.rb | ||
|---|---|---|
| 481 | 481 |
assert_equal ['dlopper', 'jsmith'], response.parsed_body.pluck('login')
|
| 482 | 482 |
end |
| 483 | 483 | |
| 484 |
def test_autocomplete_for_mention_with_query_should_not_return_users_outside_the_project |
|
| 485 |
# "someone" (id: 7) does not belong to any project |
|
| 486 |
@request.session[:user_id] = 1 |
|
| 487 |
get :autocomplete_for_mention, params: {
|
|
| 488 |
project_id: 'ecookbook', |
|
| 489 |
object_type: 'issue', |
|
| 490 |
object_id: '1', |
|
| 491 |
q: 'someone' |
|
| 492 |
}, xhr: true |
|
| 493 | ||
| 494 |
assert_response :success |
|
| 495 |
assert_equal [], response.parsed_body.pluck('login')
|
|
| 496 |
end |
|
| 497 | ||
| 484 | 498 |
def test_autocomplete_for_user_should_not_return_users_without_object_visibility |
| 485 | 499 |
@request.session[:user_id] = 1 |
| 486 | 500 |
get :autocomplete_for_user, :params => {
|
| test/unit/lib/redmine/acts/mentionable_test.rb | ||
|---|---|---|
| 72 | 72 |
assert_equal [User.find(2)], issue.mentioned_users |
| 73 | 73 |
end |
| 74 | 74 | |
| 75 |
def test_mentioned_users_should_not_include_users_outside_the_project |
|
| 76 |
# "someone" (id: 7) does not belong to any project |
|
| 77 |
issue = Issue.generate!(project_id: 1, description: '@jsmith @someone') |
|
| 78 | ||
| 79 |
assert_equal [User.find(2)], issue.mentioned_users |
|
| 80 |
end |
|
| 81 | ||
| 75 | 82 |
def test_mentioned_users_should_not_include_mentioned_users_in_existing_content |
| 76 | 83 |
issue = Issue.generate!(project_id: 1, description: 'Hello @dlopper') |
| 77 | 84 | |