Commit e5d0af56 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
parent 8b68b6f2
...@@ -2,6 +2,10 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,10 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.6.3 (unreleased) v 8.6.3 (unreleased)
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 v 8.6.2
- Fix dropdown alignment. !3298 - Fix dropdown alignment. !3298
- Fix issuable sidebar overlaps on tablet. !3299 - Fix issuable sidebar overlaps on tablet. !3299
......
...@@ -19,6 +19,7 @@ module Issuable ...@@ -19,6 +19,7 @@ module Issuable
has_many :notes, as: :noteable, dependent: :destroy has_many :notes, as: :noteable, dependent: :destroy
has_many :label_links, as: :target, dependent: :destroy has_many :label_links, as: :target, dependent: :destroy
has_many :labels, through: :label_links has_many :labels, through: :label_links
has_many :todos, as: :target, dependent: :destroy
validates :author, presence: true validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 } validates :title, presence: true, length: { within: 0..255 }
......
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
(removed) (removed)
%span.todo-label %span.todo-label
= todo_action_name(todo) = todo_action_name(todo)
= todo_target_link(todo) - if todo.target
= todo_target_link(todo)
- else
(removed)
· #{time_ago_with_tooltip(todo.created_at)} · #{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 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
......
...@@ -9,6 +9,7 @@ describe Issue, "Issuable" do ...@@ -9,6 +9,7 @@ describe Issue, "Issuable" do
it { is_expected.to belong_to(:author) } it { is_expected.to belong_to(:author) }
it { is_expected.to belong_to(:assignee) } it { is_expected.to belong_to(:assignee) }
it { is_expected.to have_many(:notes).dependent(:destroy) } it { is_expected.to have_many(:notes).dependent(:destroy) }
it { is_expected.to have_many(:todos).dependent(:destroy) }
end end
describe "Validation" do 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