Redmine 4.1.1
This commit is contained in:
parent
33e7b881a5
commit
3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2019 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -20,48 +22,21 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||
class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest
|
||||
tests TimelogController
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:users, :email_addresses,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issue_statuses,
|
||||
:issues, :issue_statuses,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:workflows
|
||||
|
||||
def setup
|
||||
field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all}
|
||||
@fields = []
|
||||
@fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
|
||||
@fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
|
||||
@fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
|
||||
@issue = Issue.generate!(
|
||||
:author_id => 1,
|
||||
:project_id => 1,
|
||||
:tracker_id => 1,
|
||||
:custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
|
||||
)
|
||||
TimeEntry.generate!(:issue => @issue)
|
||||
|
||||
@user_with_role_on_other_project = User.generate!
|
||||
User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3))
|
||||
|
||||
@users_to_test = {
|
||||
User.find(1) => [@field1, @field2, @field3],
|
||||
User.find(3) => [@field1, @field2],
|
||||
@user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
|
||||
User.generate! => [@field1],
|
||||
User.anonymous => [@field1]
|
||||
}
|
||||
|
||||
Member.where(:project_id => 1).each do |member|
|
||||
member.destroy unless @users_to_test.keys.include?(member.principal)
|
||||
end
|
||||
end
|
||||
:time_entries, :enumerations,
|
||||
:workflows,
|
||||
:custom_fields, :custom_values, :custom_fields_trackers
|
||||
|
||||
def test_index_should_show_visible_custom_fields_only
|
||||
prepare_test_data
|
||||
|
||||
@users_to_test.each do |user, fields|
|
||||
@request.session[:user_id] = user.id
|
||||
get :index, :params => {
|
||||
|
@ -80,6 +55,8 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest
|
|||
end
|
||||
|
||||
def test_index_as_csv_should_show_visible_custom_fields_only
|
||||
prepare_test_data
|
||||
|
||||
@users_to_test.each do |user, fields|
|
||||
@request.session[:user_id] = user.id
|
||||
get :index, :params => {
|
||||
|
@ -99,8 +76,11 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest
|
|||
end
|
||||
|
||||
def test_index_with_partial_custom_field_visibility_should_show_visible_custom_fields_only
|
||||
prepare_test_data
|
||||
|
||||
Issue.delete_all
|
||||
TimeEntry.delete_all
|
||||
CustomValue.delete_all
|
||||
p1 = Project.generate!
|
||||
p2 = Project.generate!
|
||||
user = User.generate!
|
||||
|
@ -127,4 +107,53 @@ class TimelogCustomFieldsVisibilityTest < Redmine::ControllerTest
|
|||
assert_select 'td', :text => "ValueC"
|
||||
assert_select 'td', :text => "ValueB", :count => 0
|
||||
end
|
||||
|
||||
def test_edit_should_not_show_custom_fields_not_visible_for_user
|
||||
time_entry_cf = TimeEntryCustomField.find(10)
|
||||
time_entry_cf.visible = false
|
||||
time_entry_cf.role_ids = [2]
|
||||
time_entry_cf.save!
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
get :edit, :params => {
|
||||
:id => 3,
|
||||
:project_id => 1
|
||||
}
|
||||
|
||||
assert_response :success
|
||||
assert_select 'select#time_entry_custom_field_values_10', 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_test_data
|
||||
field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all}
|
||||
@fields = []
|
||||
@fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true)))
|
||||
@fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2])))
|
||||
@fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3])))
|
||||
@issue = Issue.generate!(
|
||||
:author_id => 1,
|
||||
:project_id => 1,
|
||||
:tracker_id => 1,
|
||||
:custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'}
|
||||
)
|
||||
TimeEntry.generate!(:issue => @issue)
|
||||
|
||||
@user_with_role_on_other_project = User.generate!
|
||||
User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3))
|
||||
|
||||
@users_to_test = {
|
||||
User.find(1) => [@field1, @field2, @field3],
|
||||
User.find(3) => [@field1, @field2],
|
||||
@user_with_role_on_other_project => [@field1], # should see field1 only on Project 1
|
||||
User.generate! => [@field1],
|
||||
User.anonymous => [@field1]
|
||||
}
|
||||
|
||||
Member.where(:project_id => 1).each do |member|
|
||||
member.destroy unless @users_to_test.key?(member.principal)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue