Feature #16188 ยป 2021-09-25-133700-archive_issue_categories.patch
| app/controllers/issue_categories_controller.rb | ||
|---|---|---|
|
before_action :find_model_object, :except => [:index, :new, :create]
|
||
|
before_action :find_project_from_association, :except => [:index, :new, :create]
|
||
|
before_action :find_project_by_project_id, :only => [:index, :new, :create]
|
||
|
before_action :authorize
|
||
|
accept_api_auth :index, :show, :create, :update, :destroy
|
||
|
before_action :authorize, :except => [:archive, :unarchive]
|
||
|
accept_api_auth :index, :show, :create, :update, :destroy, :archive, :unarchive
|
||
|
def index
|
||
|
respond_to do |format|
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def archive
|
||
|
@category.archived = true
|
||
|
if @category.save
|
||
|
respond_to do |format|
|
||
|
format.html do
|
||
|
flash[:notice] = l(:notice_successful_update)
|
||
|
redirect_to_settings_in_projects
|
||
|
end
|
||
|
format.js
|
||
|
format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def unarchive
|
||
|
@category.archived = false
|
||
|
if @category.save
|
||
|
respond_to do |format|
|
||
|
format.html do
|
||
|
flash[:notice] = l(:notice_successful_update)
|
||
|
redirect_to_settings_in_projects
|
||
|
end
|
||
|
format.js
|
||
|
format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def destroy
|
||
|
@issue_count = @category.issues.size
|
||
| app/controllers/issues_controller.rb | ||
|---|---|---|
|
@assignables = target_projects.map(&:assignable_users).reduce(:&)
|
||
|
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
|
||
|
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
||
|
@active_categories = @categories.reject { |c| c.archived }
|
||
|
if @copy
|
||
|
@attachments_present = @issues.detect {|i| i.attachments.any?}.present?
|
||
|
@subtasks_present = @issues.detect {|i| !i.leaf?}.present?
|
||
| app/models/issue.rb | ||
|---|---|---|
|
users.uniq.sort
|
||
|
end
|
||
|
def assignable_issue_categories
|
||
|
return [] if project.nil?
|
||
|
categories = project.active_issue_categories
|
||
|
if category && category.archived
|
||
|
categories << category
|
||
|
end
|
||
|
categories.uniq.sort
|
||
|
end
|
||
|
|
||
|
# Versions that the issue can be assigned to
|
||
|
def assignable_versions
|
||
|
return @assignable_versions if @assignable_versions
|
||
| app/models/project.rb | ||
|---|---|---|
|
value.custom_field.visible_by?(project, user)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def active_issue_categories
|
||
|
issue_categories.reject { |c| c.archived }
|
||
|
end
|
||
|
private
|
||
| app/views/context_menus/issues.html.erb | ||
|---|---|---|
|
</li>
|
||
|
<% end %>
|
||
|
<% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%>
|
||
|
<% if @safe_attributes.include?('category_id') && @project && @project.active_issue_categories.any? -%>
|
||
|
<li class="folder">
|
||
|
<a href="#" class="submenu"><%= l(:field_category) %></a>
|
||
|
<ul>
|
||
|
<% @project.issue_categories.each do |u| -%>
|
||
|
<% @project.active_issue_categories.each do |u| -%>
|
||
|
<li><%= context_menu_link u.name, _bulk_update_issues_path(@issue, :ids => @issue_ids, :issue => {'category_id' => u}, :back_url => @back), :method => :patch,
|
||
|
:selected => (@issue && u == @issue.category), :disabled => !@can[:edit] %></li>
|
||
|
<% end -%>
|
||
| app/views/issues/_attributes.html.erb | ||
|---|---|---|
|
</p>
|
||
|
<% end %>
|
||
|
<% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %>
|
||
|
<p><%= f.select :category_id, (@issue.project.issue_categories.collect {|c| [c.name, c.id]}),
|
||
|
<% if @issue.safe_attribute?('category_id') && @issue.assignable_issue_categories.any? %>
|
||
|
<p><%= f.select :category_id, (@issue.assignable_issue_categories.collect {|c| [c.name, c.id]}),
|
||
|
{:include_blank => true, :required => @issue.required_attribute?('category_id')},
|
||
|
:onchange => ("updateIssueFrom('#{escape_javascript(update_issue_form_path(@project, @issue))}', this)" if @issue.new_record?) %>
|
||
|
<%= link_to(l(:label_issue_category_new),
|
||
| app/views/issues/bulk_edit.html.erb | ||
|---|---|---|
|
<label for='issue_category_id'><%= l(:field_category) %></label>
|
||
|
<%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
|
||
|
content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:category_id] == 'none')) +
|
||
|
options_from_collection_for_select(@categories, :id, :name, @issue_params[:category_id])) %>
|
||
|
options_from_collection_for_select(@active_categories, :id, :name, @issue_params[:category_id])) %>
|
||
|
</p>
|
||
|
<% end %>
|
||
| app/views/projects/settings/_issue_categories.html.erb | ||
|---|---|---|
|
<td class="buttons">
|
||
|
<% if User.current.allowed_to?(:manage_categories, @project) %>
|
||
|
<%= link_to l(:button_edit), edit_issue_category_path(category), :class => 'icon icon-edit' %>
|
||
|
<%= link_to(l(:button_archive), archive_issue_category_path(category), :method => :post, :class => 'icon icon-lock') unless category.archived? %>
|
||
|
<%= link_to(l(:button_unarchive), unarchive_issue_category_path(category), :method => :post, :class => 'icon icon-lock') if category.archived? %>
|
||
|
<%= delete_link issue_category_path(category) %>
|
||
|
<% end %>
|
||
|
</td>
|
||
| config/routes.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
resources :issue_categories do
|
||
|
member do
|
||
|
post 'archive'
|
||
|
post 'unarchive'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| db/migrate/20210908145200_issue_categories_add_column.rb | ||
|---|---|---|
|
class IssueCategoriesAddColumn < ActiveRecord::Migration[6.1]
|
||
|
def self.up
|
||
|
add_column :issue_categories, :archived, :boolean, :default => false
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :issue_categories, :archived
|
||
|
end
|
||
|
end
|
||
| test/functional/issue_categories_controller_test.rb | ||
|---|---|---|
|
# check that the issue category was nullified
|
||
|
assert_nil issue.reload.category_id
|
||
|
end
|
||
|
|
||
|
def test_archive_unarchive
|
||
|
assert_no_difference 'IssueCategory.count' do
|
||
|
put(
|
||
|
:archive,
|
||
|
:params => {
|
||
|
:id => 2,
|
||
|
}
|
||
|
)
|
||
|
end
|
||
|
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||
|
assert_equal true, IssueCategory.find(2).archived
|
||
|
|
||
|
assert_no_difference 'IssueCategory.count' do
|
||
|
put(
|
||
|
:unarchive,
|
||
|
:params => {
|
||
|
:id => 2,
|
||
|
}
|
||
|
)
|
||
|
end
|
||
|
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||
|
assert_equal false, IssueCategory.find(2).archived
|
||
|
end
|
||
|
end
|
||
| test/unit/issue_test.rb | ||
|---|---|---|
|
assert_equal [5], issue2.filter_projects_scope('').ids.sort
|
||
|
end
|
||
|
|
||
|
def test_issue_categories_archived
|
||
|
issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'Default')
|
||
|
assert_save issue
|
||
|
|
||
|
project = issue.project
|
||
|
|
||
|
assert_nil issue.category_id
|
||
|
assert_nil issue.category
|
||
|
assert_equal 1, project.id
|
||
|
assert_equal 2, project.issue_categories.size
|
||
|
assert_equal 2, project.active_issue_categories.size
|
||
|
assert_equal 2, issue.assignable_issue_categories.size
|
||
|
|
||
|
category = project.issue_categories.first
|
||
|
category.archived = true
|
||
|
|
||
|
assert_equal 2, project.issue_categories.size
|
||
|
assert_equal 1, project.active_issue_categories.size
|
||
|
assert_equal 1, issue.assignable_issue_categories.size
|
||
|
assert_not_equal category, issue.assignable_issue_categories.first
|
||
|
|
||
|
issue.category = category
|
||
|
assert_equal 1, project.active_issue_categories.size
|
||
|
assert_equal 2, issue.assignable_issue_categories.size
|
||
|
|
||
|
category.archived = false
|
||
|
assert_equal 2, project.active_issue_categories.size
|
||
|
assert_equal 2, issue.assignable_issue_categories.size
|
||
|
end
|
||
|
end
|
||
| test/unit/project_test.rb | ||
|---|---|---|
|
assert_equal 'valuea', project.custom_field_value(cf1)
|
||
|
assert_nil project.custom_field_value(cf2)
|
||
|
end
|
||
|
|
||
|
def test_issue_categories_archived
|
||
|
project = Project.find(1)
|
||
|
assert_equal 2, project.issue_categories.size
|
||
|
assert_equal 2, project.active_issue_categories.size
|
||
|
|
||
|
project.issue_categories.each do |cat|
|
||
|
cat.archived = true
|
||
|
end
|
||
|
|
||
|
assert_equal 2, project.issue_categories.size
|
||
|
assert_equal 0, project.active_issue_categories.size
|
||
|
|
||
|
project.issue_categories.each do |cat|
|
||
|
cat.archived = false
|
||
|
end
|
||
|
|
||
|
assert_equal 2, project.issue_categories.size
|
||
|
assert_equal 2, project.active_issue_categories.size
|
||
|
end
|
||
|
end
|
||