Project

General

Profile

Defect #26023 » 26023_tests_visibility_fix.patch

Felix Schäfer, 2018-10-01 21:37

View differences:

app/models/issue_category.rb
safe_attributes 'name', 'assigned_to_id'
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
scope :visible, lambda {|user = User.current|
joins(:project).
where(Project.allowed_to_condition(user, :view_issues))
}
alias :destroy_without_reassign :destroy
app/models/issue_query.rb
add_available_filter "category_id",
:type => :list_optional,
:values => lambda { project.issue_categories.collect{|s| [s.name, s.id.to_s] } } if project
:values => lambda { issue_category_values }
add_available_filter "subject", :type => :text
add_available_filter "description", :type => :text
app/models/project.rb
@users = nil
@shared_versions = nil
@rolled_up_versions = nil
@rolled_up_issue_categories = nil
@rolled_up_trackers = nil
@rolled_up_statuses = nil
@rolled_up_custom_fields = nil
......
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED)
end
def rolled_up_issue_categories
@rolled_up_issue_categories ||=
IssueCategory.
joins(:project).
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED)
end
# Returns a scope of the Versions used by the project
def shared_versions
if new_record?
app/models/query.rb
watcher_values
end
def issue_category_values
categories =
if project
project.rolled_up_issue_categories
else
IssueCategory
end
categories.visible.collect {|c| [c.name, c.id.to_s] }
end
# Returns a scope of issue custom fields that are available as columns or filters
def issue_custom_fields
if project
test/fixtures/issue_categories.yml
project_id: 2
assigned_to_id:
id: 4
issue_categories_005:
name: Services
project_id: 5
assigned_to_id:
id: 5
test/functional/queries_controller_test.rb
assert_include ["eCookbook - 2.0", "3", "open"], json
end
def test_issue_categories_filter_should_not_return_issue_categories_from_invisible_subprojects
# Remove "jsmith" user from "Private child of eCookbook" project
Project.find(5).memberships.find_by(:user_id => 2).destroy
@request.session[:user_id] = 2
get :filter, :params =>
{
:project_id => 1,
:name => 'category_id'
}
assert_response :success
assert_equal 'application/json', response.content_type
json = ActiveSupport::JSON.decode(response.body)
assert_include ["Printing", "1"], json
assert_include ["Recipes", "2"], json
assert_not_include ["Services", "5"], json
end
def test_version_filter_without_project_id_should_return_all_visible_fixed_versions
# Remove "jsmith" user from "Private child of eCookbook" project
Project.find(5).memberships.find_by(:user_id => 2).destroy
test/unit/project_test.rb
project.rolled_up_versions.sort
end
test "#rolled_up_issue_categories should include the categories for the current project" do
project = Project.generate!
current_category_1 = IssueCategory.create!(:name => 'Current Category 1' ,:project => project)
current_category_2 = IssueCategory.create!(:name => 'Current Category 2' ,:project => project)
expected_categories = [current_category_1, current_category_2].sort
assert_equal expected_categories, project.rolled_up_issue_categories.sort
end
test "#rolled_up_issue_categories should include categories for a subproject" do
project = Project.generate!
parent_category_1 = IssueCategory.create!(:name => 'Parent Category 1' ,:project => project)
parent_category_2 = IssueCategory.create!(:name => 'Parent Category 2' ,:project => project)
subproject = Project.generate_with_parent!(project)
subproject_category = IssueCategory.create!(:name => 'Subproject Category' ,:project => subproject)
expected_categories = [parent_category_1, parent_category_2, subproject_category].sort
assert_equal expected_categories, project.rolled_up_issue_categories.sort
end
test "#rolled_up_issue_categories should include categories for a sub-subproject" do
project = Project.generate!
parent_category_1 = IssueCategory.create!(:name => 'Parent Category 1' ,:project => project)
parent_category_2 = IssueCategory.create!(:name => 'Parent Category 2' ,:project => project)
subproject = Project.generate_with_parent!(project)
sub_subproject = Project.generate_with_parent!(subproject)
sub_subproject_category = IssueCategory.create!(:name => 'Sub Subproject Category' ,:project => sub_subproject)
project.reload
expected_categories = [parent_category_1, parent_category_2, sub_subproject_category].sort
assert_equal expected_categories, project.rolled_up_issue_categories.sort
end
test "#rolled_up_issue_categories should only check active projects" do
project = Project.generate!
parent_category_1 = IssueCategory.create!(:name => 'Parent Category 1' ,:project => project)
parent_category_2 = IssueCategory.create!(:name => 'Parent Category 2' ,:project => project)
subproject = Project.generate_with_parent!(project)
IssueCategory.create!(:name => 'Subproject Category' ,:project => subproject)
assert subproject.archive
project.reload
expected_categories = [parent_category_1, parent_category_2].sort
assert !subproject.active?
assert_equal expected_categories, project.rolled_up_issue_categories.sort
end
def test_shared_versions_none_sharing
p = Project.find(5)
v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none')
(4-4/5)