Commit 95c7aa62 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-todos' into 'master'

Destroy related todos when an Issue/MR is deleted

Closes #14550 

Closes #14598

See merge request !3376
parents 220b5126 f1d1dc00
......@@ -15,6 +15,10 @@ v 8.7.0 (unreleased)
- Gracefully handle notes on deleted commits in merge requests (Stan Hu)
- Fall back to `In-Reply-To` and `References` headers when sub-addressing is not available (David Padilla)
v 8.6.3 (unreleased)
- Destroy related todos when an Issue/MR is deleted. !3376
- Fix error 500 when target is nil on todo list. !3376
v 8.6.2
- Fix dropdown alignment. !3298
- Fix issuable sidebar overlaps on tablet. !3299
......
......@@ -19,6 +19,7 @@ module Issuable
has_many :notes, as: :noteable, dependent: :destroy
has_many :label_links, as: :target, dependent: :destroy
has_many :labels, through: :label_links
has_many :todos, as: :target, dependent: :destroy
validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 }
......
......@@ -10,7 +10,10 @@
(removed)
%span.todo-label
= todo_action_name(todo)
= todo_target_link(todo)
- if todo.target
= todo_target_link(todo)
- else
(removed)
· #{time_ago_with_tooltip(todo.created_at)}
......
class RemoveTodosForDeletedIssues < ActiveRecord::Migration
def up
execute <<-SQL
DELETE FROM todos
WHERE todos.target_type = 'Issue'
AND NOT EXISTS (
SELECT *
FROM issues
WHERE issues.id = todos.target_id
AND issues.deleted_at IS NULL
)
SQL
end
def down
end
end
class RemoveTodosForDeletedMergeRequests < ActiveRecord::Migration
def up
execute <<-SQL
DELETE FROM todos
WHERE todos.target_type = 'MergeRequest'
AND NOT EXISTS (
SELECT *
FROM merge_requests
WHERE merge_requests.id = todos.target_id
AND merge_requests.deleted_at IS NULL
)
SQL
end
def down
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160320204112) do
ActiveRecord::Schema.define(version: 20160331133914) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
......@@ -9,6 +9,7 @@ describe Issue, "Issuable" do
it { is_expected.to belong_to(:author) }
it { is_expected.to belong_to(:assignee) }
it { is_expected.to have_many(:notes).dependent(:destroy) }
it { is_expected.to have_many(:todos).dependent(:destroy) }
end
describe "Validation" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment