Feature #44166 » tracker_lock_feature.patch
| app/controllers/projects_controller.rb | ||
|---|---|---|
|
def new
|
||
|
@issue_custom_fields = IssueCustomField.sorted.to_a
|
||
|
@trackers = Tracker.sorted.to_a
|
||
|
@trackers = Tracker.active.sorted.to_a
|
||
|
@project = Project.new
|
||
|
@project.safe_attributes = params[:project]
|
||
|
end
|
||
|
def create
|
||
|
@issue_custom_fields = IssueCustomField.sorted.to_a
|
||
|
@trackers = Tracker.sorted.to_a
|
||
|
@trackers = Tracker.active.sorted.to_a
|
||
|
@project = Project.new
|
||
|
@project.safe_attributes = params[:project]
|
||
| ... | ... | |
|
def copy
|
||
|
@issue_custom_fields = IssueCustomField.sorted.to_a
|
||
|
@trackers = Tracker.sorted.to_a
|
||
|
@trackers = Tracker.active.sorted.to_a
|
||
|
@source_project = Project.find(params[:id])
|
||
|
if request.get?
|
||
|
@project = Project.copy_from(@source_project)
|
||
| ... | ... | |
|
@issue_custom_fields = IssueCustomField.sorted.to_a
|
||
|
@issue_category ||= IssueCategory.new
|
||
|
@member ||= @project.members.new
|
||
|
@trackers = Tracker.sorted.to_a
|
||
|
# Show active trackers plus any inactive trackers already assigned to this project
|
||
|
@trackers = Tracker.sorted.where(:active => true).or(
|
||
|
Tracker.sorted.where(:id => @project.tracker_ids)
|
||
|
).sorted.to_a
|
||
|
@version_status = params[:version_status] || 'open'
|
||
|
@version_name = params[:version_name]
|
||
| app/controllers/trackers_controller.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def lock
|
||
|
@tracker = Tracker.find(params[:id])
|
||
|
@tracker.update!(:active => false)
|
||
|
redirect_to trackers_path
|
||
|
end
|
||
|
def unlock
|
||
|
@tracker = Tracker.find(params[:id])
|
||
|
@tracker.update!(:active => true)
|
||
|
redirect_to trackers_path
|
||
|
end
|
||
|
def destroy
|
||
|
@tracker = Tracker.find(params[:id])
|
||
|
if @tracker.issues.empty?
|
||
| app/models/issue.rb | ||
|---|---|---|
|
# Returns a scope of trackers that user can assign project issues to
|
||
|
def self.allowed_target_trackers(project, user=User.current, current_tracker=nil)
|
||
|
if project
|
||
|
scope = project.trackers.sorted
|
||
|
scope = project.trackers.sorted.active
|
||
|
# Always include the current tracker even if it is inactive
|
||
|
if current_tracker
|
||
|
scope = Tracker.sorted.where(
|
||
|
:id => scope.pluck(:id) | [current_tracker]
|
||
|
)
|
||
|
end
|
||
|
unless user.admin?
|
||
|
roles = user.roles_for_project(project).select {|r| r.has_permission?(:add_issues)}
|
||
|
unless roles.any? {|r| r.permissions_all_trackers?(:add_issues)}
|
||
| ... | ... | |
|
copy.author = author
|
||
|
copy.project = project
|
||
|
copy.parent_issue_id = copied_issue_ids[child.parent_id]
|
||
|
unless child.fixed_version.present? && child.fixed_version.status == 'open'
|
||
|
if fixed_version_id != @copied_from.fixed_version_id
|
||
|
copy.fixed_version_id = fixed_version_id
|
||
|
elsif !(child.fixed_version.present? && child.fixed_version.status == 'open')
|
||
|
copy.fixed_version_id = nil
|
||
|
end
|
||
|
unless child.assigned_to_id.present? &&
|
||
| app/models/project.rb | ||
|---|---|---|
|
if !initialized.key?('trackers') && !initialized.key?('tracker_ids')
|
||
|
default = Setting.default_projects_tracker_ids
|
||
|
if default.is_a?(Array)
|
||
|
self.trackers = Tracker.where(:id => default.map(&:to_i)).sorted.to_a
|
||
|
self.trackers = Tracker.where(:id => default.map(&:to_i)).active.sorted.to_a
|
||
|
else
|
||
|
self.trackers = Tracker.sorted.to_a
|
||
|
self.trackers = Tracker.active.sorted.to_a
|
||
|
end
|
||
|
end
|
||
|
# rubocop:enable Style/NegatedIf
|
||
| app/models/tracker.rb | ||
|---|---|---|
|
scope :sorted, lambda {order(:position)}
|
||
|
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
|
||
|
scope :active, lambda {where(:active => true)}
|
||
|
# Returns the trackers that are visible by the user.
|
||
|
#
|
||
| ... | ... | |
|
'default_status_id',
|
||
|
'is_in_roadmap',
|
||
|
'private_by_default',
|
||
|
'active',
|
||
|
'core_fields',
|
||
|
'position',
|
||
|
'custom_field_ids',
|
||
| app/views/trackers/index.html.erb | ||
|---|---|---|
|
<th><%=l(:field_default_status)%></th>
|
||
|
<th><%=l(:field_description)%></th>
|
||
|
<th></th>
|
||
|
<th></th>
|
||
|
<th class="tracker-buttons-col"></th>
|
||
|
</tr></thead>
|
||
|
<tbody>
|
||
|
<% for tracker in @trackers %>
|
||
|
<tr>
|
||
|
<tr class="<%= tracker.active? ? '' : 'tracker-locked' %>">
|
||
|
<td class="name"><%= link_to tracker.name, edit_tracker_path(tracker) %></td>
|
||
|
<td><%= tracker.default_status.name %></td>
|
||
|
<td class="description"><%= tracker.description %></td>
|
||
| ... | ... | |
|
</span>
|
||
|
<% end %>
|
||
|
</td>
|
||
|
<td class="buttons">
|
||
|
<td class="buttons tracker-buttons-col">
|
||
|
<%= reorder_handle(tracker) %>
|
||
|
<%= link_to sprite_icon('copy', l(:button_copy)), new_tracker_path(:copy => tracker), :class => 'icon icon-copy' %>
|
||
|
<% if tracker.active? %>
|
||
|
<%= link_to sprite_icon('lock', l(:button_lock)), lock_tracker_path(tracker), :method => :put, :class => 'icon icon-lock' %>
|
||
|
<% else %>
|
||
|
<%= link_to sprite_icon('unlock', l(:button_unlock)), unlock_tracker_path(tracker), :method => :put, :class => 'icon icon-unlock' %>
|
||
|
<% end %>
|
||
|
<%= delete_link tracker_path(tracker) %>
|
||
|
</td>
|
||
|
</tr>
|
||
| ... | ... | |
|
</tbody>
|
||
|
</table>
|
||
|
<style>
|
||
|
tr.tracker-locked td { opacity: 0.6; }
|
||
|
table.trackers th.tracker-buttons-col,
|
||
|
table.trackers td.tracker-buttons-col { width: 1%; white-space: nowrap; }
|
||
|
table.trackers td.tracker-buttons-col a.icon-lock,
|
||
|
table.trackers td.tracker-buttons-col a.icon-unlock { display: inline-block; min-width: 82px; }
|
||
|
</style>
|
||
|
<% html_title(l(:label_tracker_plural)) -%>
|
||
|
<%= javascript_tag do %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
label_tracker_plural: Trackers
|
||
|
label_tracker_all: All trackers
|
||
|
label_tracker_new: New tracker
|
||
|
label_tracker_locked: Locked
|
||
|
label_workflow: Workflow
|
||
|
label_issue_status: Issue status
|
||
|
label_issue_status_plural: Issue statuses
|
||
| config/locales/ja.yml | ||
|---|---|---|
|
label_no_preview: このファイルはプレビューできません
|
||
|
error_no_tracker_allowed_for_new_issue_in_project: このプロジェクトにはチケットの追加が許可されているトラッカーがありません
|
||
|
label_tracker_all: すべてのトラッカー
|
||
|
label_tracker_locked: ロック済み
|
||
|
label_new_project_issue_tab_enabled: '"新しいチケット" タブを表示'
|
||
|
setting_new_item_menu_tab: 新規オブジェクト作成タブ
|
||
|
label_new_object_tab_enabled: '"+" ドロップダウンを表示'
|
||
| config/routes.rb | ||
|---|---|---|
|
delete 'groups/:id/users/:user_id', :to => 'groups#remove_user', :id => /\d+/, :as => 'group_user'
|
||
|
resources :trackers, :except => :show do
|
||
|
member do
|
||
|
put 'lock'
|
||
|
put 'unlock'
|
||
|
end
|
||
|
collection do
|
||
|
match 'fields', :via => [:get, :post]
|
||
|
end
|
||
| db/migrate/20260612000000_add_active_to_trackers.rb | ||
|---|---|---|
|
class AddActiveToTrackers < ActiveRecord::Migration[8.1]
|
||
|
def change
|
||
|
add_column :trackers, :active, :boolean, :default => true, :null => false
|
||
|
end
|
||
|
end
|
||
| test/fixtures/trackers.yml | ||
|---|---|---|
|
id: 1
|
||
|
default_status_id: 1
|
||
|
position: 1
|
||
|
active: true
|
||
|
description: Description for Bug tracker
|
||
|
trackers_002:
|
||
|
name: Feature request
|
||
|
id: 2
|
||
|
default_status_id: 1
|
||
|
position: 2
|
||
|
active: true
|
||
|
description: Description for Feature request tracker
|
||
|
trackers_003:
|
||
|
name: Support request
|
||
|
id: 3
|
||
|
default_status_id: 1
|
||
|
position: 3
|
||
|
active: true
|
||
| test/functional/trackers_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_lock
|
||
|
tracker = Tracker.find(1)
|
||
|
assert tracker.active?
|
||
|
put :lock, :params => {:id => 1}
|
||
|
assert_redirected_to :action => 'index'
|
||
|
assert_not tracker.reload.active?
|
||
|
end
|
||
|
def test_unlock
|
||
|
tracker = Tracker.find(1)
|
||
|
tracker.update!(active: false)
|
||
|
put :unlock, :params => {:id => 1}
|
||
|
assert_redirected_to :action => 'index'
|
||
|
assert tracker.reload.active?
|
||
|
end
|
||
|
def test_lock_requires_admin
|
||
|
@request.session[:user_id] = 2
|
||
|
put :lock, :params => {:id => 1}
|
||
|
assert_response :forbidden
|
||
|
end
|
||
|
def test_index_shows_lock_button_for_active_tracker
|
||
|
get :index
|
||
|
assert_response :success
|
||
|
assert_select 'a[href=?]', lock_tracker_path(1)
|
||
|
end
|
||
|
def test_index_shows_unlock_button_for_locked_tracker
|
||
|
Tracker.find(1).update!(active: false)
|
||
|
get :index
|
||
|
assert_response :success
|
||
|
assert_select 'a[href=?]', unlock_tracker_path(1)
|
||
|
end
|
||
|
def test_post_fields
|
||
|
post :fields, :params => {
|
||
|
:trackers => {
|
||
| test/unit/issue_test.rb | ||
|---|---|---|
|
assert_equal [3, nil], copy.children.map(&:fixed_version_id)
|
||
|
end
|
||
|
def test_copy_should_propagate_version_change_to_subtasks
|
||
|
parent = Issue.generate!(:fixed_version_id => 3)
|
||
|
child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1', :fixed_version_id => 3)
|
||
|
child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2', :fixed_version_id => nil)
|
||
|
new_version = Version.generate!(:project => Project.find(1))
|
||
|
copy = parent.reload.copy(:fixed_version_id => new_version.id)
|
||
|
assert_difference 'Issue.count', 3 do
|
||
|
assert copy.save
|
||
|
end
|
||
|
assert_equal new_version.id, copy.fixed_version_id
|
||
|
assert_equal [new_version.id, new_version.id], copy.children.map(&:fixed_version_id)
|
||
|
end
|
||
|
def test_copy_should_clear_subtasks_assignee_if_is_locked
|
||
|
user = User.find(2)
|
||
| ... | ... | |
|
assert_equal [], issue.allowed_target_trackers(User.find(2)).ids
|
||
|
end
|
||
|
def test_allowed_target_trackers_excludes_locked_trackers
|
||
|
Tracker.find(1).update!(active: false)
|
||
|
issue = Issue.new(:project => Project.find(1))
|
||
|
ids = Issue.allowed_target_trackers(Project.find(1), User.find(1)).ids
|
||
|
assert_not_includes ids, 1
|
||
|
assert_includes ids, 2
|
||
|
assert_includes ids, 3
|
||
|
end
|
||
|
def test_allowed_target_trackers_includes_current_tracker_even_if_locked
|
||
|
tracker = Tracker.find(1)
|
||
|
tracker.update!(active: false)
|
||
|
issue = Issue.generate!(:project => Project.find(1), :tracker => tracker)
|
||
|
ids = issue.allowed_target_trackers(User.find(1)).ids
|
||
|
assert_includes ids, 1
|
||
|
end
|
||
|
def test_allowed_target_trackers_should_include_current_tracker
|
||
|
user = User.generate!
|
||
|
role = Role.generate!
|
||
| test/unit/tracker_test.rb | ||
|---|---|---|
|
assert tracker.respond_to?(:description)
|
||
|
assert_equal tracker.description, "Description for Bug tracker"
|
||
|
end
|
||
|
def test_active_scope_returns_only_active_trackers
|
||
|
Tracker.find(1).update!(active: false)
|
||
|
active_ids = Tracker.active.pluck(:id)
|
||
|
assert_not_includes active_ids, 1
|
||
|
assert_includes active_ids, 2
|
||
|
assert_includes active_ids, 3
|
||
|
end
|
||
|
def test_tracker_is_active_by_default
|
||
|
tracker = Tracker.new(:name => 'New tracker', :default_status_id => 1)
|
||
|
assert tracker.active?
|
||
|
end
|
||
|
def test_lock_tracker
|
||
|
tracker = Tracker.find(1)
|
||
|
assert tracker.active?
|
||
|
tracker.update!(active: false)
|
||
|
assert_not tracker.reload.active?
|
||
|
end
|
||
|
def test_unlock_tracker
|
||
|
tracker = Tracker.find(1)
|
||
|
tracker.update!(active: false)
|
||
|
tracker.update!(active: true)
|
||
|
assert tracker.reload.active?
|
||
|
end
|
||
|
end
|
||