Skip to content

Commit

Permalink
added settings for plugin related to deleting parent issue, some
Browse files Browse the repository at this point in the history
cosmetic in plugin's description.
  • Loading branch information
hron committed Jun 8, 2009
1 parent 80d25d0 commit cec0917
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/controllers/issues_controller.rb
Expand Up @@ -109,7 +109,7 @@ def retrieve_query_with_subtasks

def find_issue_with_subtasks
find_issue_without_subtasks
@parent_issue = @issue.parent
@parent_issue = @issue.parent if @issue
rescue ActiveRecord::RecordNotFound
render_404
end
Expand Down
7 changes: 7 additions & 0 deletions app/views/settings/_subtasks_settings.rhtml
@@ -0,0 +1,7 @@
<p><label><%= l(:subtasks_field_settings_delete_children)%></label>
<%= select_tag( 'settings[delete_children]',
options_for_select( [ [ "Yes", "1" ],
[ "No", "0" ] ],
@settings[:delete_children])) %>
</p>

3 changes: 2 additions & 1 deletion config/locales/en.yml
@@ -1,9 +1,10 @@
en:
subtasks_label_view: "View options"
subtasks_field_parent: Subproject of
subtasks_field_parent_issue: Child of
subtasks_field_parent_title: Parent page
subtasks_field_settings_delete_children: Delete children when parent destroyed

subtasks_label_view: "View options"
subtasks_label_children: parent of
subtasks_label_parents: child of
subtasks_label_view_option_parents_do_not_show: Never
Expand Down
8 changes: 8 additions & 0 deletions init.rb
@@ -1,14 +1,22 @@
require 'redmine'
require 'redmine_subtasks/setting'
require 'redmine_subtasks/redmine_ext'
require 'redmine_subtasks/redmine_ext/issues_controller_hooks'

RAILS_DEFAULT_LOGGER.info 'Starting Subtasks plugin for RedMine'

Redmine::Plugin.register :redmine_subtasks do
name 'Subtasks plugin'
author 'Aleksei Gusev'
author_url 'mailto:Aleksei Gusev <aleksei.gusev@gmail.com>?subject=redmine_subtasks'
description 'This is plugin for Redmine for adding subtasks functionality.'
url 'http://github.com/hron/redmine_subtasks/tree/master'
version '0.0.1'
requires_redmine :version_or_higher => '0.8.0'

settings :default => { :delete_children => 1 },
:partial => 'settings/subtasks_settings'

# remapping permissions
Redmine::AccessControl.permissions.delete_if do |p|
p.name == :manage_issue_relations
Expand Down
1 change: 0 additions & 1 deletion lib/redmine_subtasks/redmine_ext.rb
Expand Up @@ -4,7 +4,6 @@
require_dependency 'redmine_subtasks/redmine_ext/issues_helper_patch'
require_dependency 'redmine_subtasks/redmine_ext/queries_helper_patch'
require_dependency 'redmine_subtasks/redmine_ext/versions_helper_patch'
require_dependency 'redmine_subtasks/redmine_ext/issues_controller_hooks'

class ViewOption
attr_accessor :name, :available_values
Expand Down
12 changes: 11 additions & 1 deletion lib/redmine_subtasks/redmine_ext/issue_patch.rb
Expand Up @@ -7,6 +7,15 @@ module IssuePatch

def self.included(base)
base.class_eval do

def move_children_to_root_before_destroy
unless RedmineSubtasks::Setting.delete_children?
children.each( &:move_to_root)
reload_nested_set
end
end
before_destroy :move_children_to_root_before_destroy

acts_as_nested_set

after_save :do_subtasks_hooks
Expand Down Expand Up @@ -94,6 +103,7 @@ def after_save
end
end


# Moves/copies an issue to a new project and tracker
# Returns the moved/copied issue on success, false on failure
def move_to(new_project, new_tracker = nil, options = {})
Expand All @@ -105,7 +115,7 @@ def move_to(new_project, new_tracker = nil, options = {})
end
transaction do
if new_project && issue.project_id != new_project.id
unless Setting.cross_project_issue_relations?
unless ::Setting.cross_project_issue_relations?
# delete issue relations
issue.relations_from.clear
issue.relations_to.clear
Expand Down
7 changes: 7 additions & 0 deletions lib/redmine_subtasks/setting.rb
@@ -0,0 +1,7 @@
module RedmineSubtasks
class Setting
def self.delete_children?
::Setting[:plugin_redmine_subtasks][:delete_children].to_i > 0
end
end
end
4 changes: 3 additions & 1 deletion tasks/testing.rake
Expand Up @@ -4,6 +4,8 @@ namespace :test do
RedmineSubtasks::Testing.override_core_fixtures
end

Rake::Task["test:plugins"].prerequisites << "test:override_core_fixtures"
[ "test:plugins" ].each do |t|
Rake::Task[t].prerequisites << "test:override_core_fixtures"
end
end

16 changes: 8 additions & 8 deletions test/fixtures/issues.yml
Expand Up @@ -95,7 +95,7 @@ issues_007:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: Issue due today
id: 7
fixed_version_id:
Expand All @@ -112,7 +112,7 @@ issues_008:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: Closed issue
id: 8
fixed_version_id:
Expand All @@ -130,7 +130,7 @@ issues_root:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: root
id: 9
fixed_version_id:
Expand All @@ -151,7 +151,7 @@ issues_child001:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: child001
id: 10
fixed_version_id:
Expand All @@ -171,7 +171,7 @@ issues_child002:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: child002
id: 11
fixed_version_id:
Expand All @@ -191,7 +191,7 @@ issues_subchild001:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: subchild001
id: 12
fixed_version_id:
Expand All @@ -211,7 +211,7 @@ issues_subchild002:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: subchild002
id: 13
fixed_version_id:
Expand All @@ -231,7 +231,7 @@ issues_subchild003:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
updated_on: <%= 10.days.ago.to_date.to_s(:db) %>
priority_id: 3
priority_id: 4
subject: subchild003
id: 14
fixed_version_id:
Expand Down
33 changes: 30 additions & 3 deletions test/unit/issue_test.rb
Expand Up @@ -6,7 +6,10 @@ class IssueTest < Test::Unit::TestCase
:issue_statuses, :issue_categories,
:enumerations,
:issues,
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
:custom_fields,
:custom_fields_projects,
:custom_fields_trackers,
:custom_values,
:time_entries,
:versions)

Expand Down Expand Up @@ -120,7 +123,7 @@ def test_should_not_set_target_version_of_parent_if_child_on_another_project
def test_should_update_due_to_date_if_target_version_is_set_but_due_to_is_not
@issue = Issue.new( :project_id => 1, :tracker_id => 1,
:author_id => 1, :status_id => 1,
:priority => Enumeration.priorities.first,
:priority => IssuePriority.priorities.first,
:subject => 'issue for test hook which set due_to when sets target version.',
:description => 'issue for test hook which set due_to when sets target version.')

Expand All @@ -131,13 +134,37 @@ def test_should_update_due_to_date_if_target_version_is_set_but_due_to_is_not
assert @issue.reload.due_date == @issue.reload.fixed_version.due_date
end

def test_settings_delete_children_on
with_settings :plugin_redmine_subtasks => { :delete_children => "1" } do
@root = issues( :issues_root)
children_before_delete = @root.children.clone
assert @root.destroy, "failed to destroy parent issue"
assert_raise ActiveRecord::RecordNotFound do
children_before_delete.each( &:reload)
end
end
end

def test_settings_delete_children_off
with_settings :plugin_redmine_subtasks => { :delete_children => "0" } do
@root = issues( :issues_root)
children_before_delete = @root.children.clone
assert @root.destroy, "failed to destroy parent issue"
assert_nothing_raised do
children_before_delete.each( &:reload)
end
end
end

private

# TODO: rewrite all test used this method to using fixtures
# instead of creating families of issues.
def create_family_of_issues( subject)
# Create 3 issues
@issue1 = Issue.new( :project_id => 1, :tracker_id => 1,
:author_id => 1, :status_id => 1,
:priority => Enumeration.priorities.first,
:priority => IssuePriority.priorities.first,
:subject => subject,
:description => subject)
assert @issue1.save
Expand Down

0 comments on commit cec0917

Please sign in to comment.