diff --git a/CHANGELOG b/CHANGELOG index 10984ebd1907d95bdda508c0c9eb7a762bcd5476..75ea12320b30de95ecee6f17e2a386c9068e2f3d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,10 @@ v 8.6.0 (unreleased) - Add main language of a project in the list of projects (Tiago Botelho) - Add ability to show archived projects on dashboard, explore and group pages +v 8.5.5 + - Ensure removing a project removes associated Todo entries. + - Prevent a 500 error in Todos when author was removed. + v 8.5.4 - Do not cache requests for badges (including builds badge) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f0aa2b57121763d0a12b67d5eb1e3e779c8fc51c..368969c647215fbae0170328af52078882140fe5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -72,7 +72,7 @@ module ApplicationHelper if user_or_email.is_a?(User) user = user_or_email else - user = User.find_by(email: user_or_email.downcase) + user = User.find_by(email: user_or_email.try(:downcase)) end if user diff --git a/app/models/project.rb b/app/models/project.rb index 3235a1cee5051c7055a7b7f7b3661232a2487484..426464dee81c21db054dae019845b28cf8cffb68 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -151,6 +151,7 @@ class Project < ActiveRecord::Base has_many :releases, dependent: :destroy has_many :lfs_objects_projects, dependent: :destroy has_many :lfs_objects, through: :lfs_objects_projects + has_many :todos, dependent: :destroy has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" diff --git a/app/views/dashboard/todos/_todo.html.haml b/app/views/dashboard/todos/_todo.html.haml index f878d36e7394008d913e1d7e467bd38a36049d93..45cfe3da188f5eda4b055958dea63895182423bd 100644 --- a/app/views/dashboard/todos/_todo.html.haml +++ b/app/views/dashboard/todos/_todo.html.haml @@ -4,7 +4,10 @@ .todo-title %span.author-name - = link_to_author todo + - if todo.author + = link_to_author(todo) + - else + (removed) %span.todo-label = todo_action_name(todo) = todo_target_link(todo) diff --git a/db/migrate/20160309140734_fix_todos.rb b/db/migrate/20160309140734_fix_todos.rb new file mode 100644 index 0000000000000000000000000000000000000000..ebe0fc82305d87de35e0cc7bfabc1ba74f9695db --- /dev/null +++ b/db/migrate/20160309140734_fix_todos.rb @@ -0,0 +1,16 @@ +class FixTodos < ActiveRecord::Migration + def up + execute <<-SQL + DELETE FROM todos + WHERE todos.target_type IN ('Commit', 'ProjectSnippet') + OR NOT EXISTS ( + SELECT * + FROM projects + WHERE projects.id = todos.project_id + ) + SQL + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f56f3970db3a10a0100809d32e7f32e37d8a254..a74b86d8e2fd75f1b0652dd4eb7e854843668bad 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160305220806) do +ActiveRecord::Schema.define(version: 20160309140734) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index c458d9c9b1bea89fccb31c3f3a98dad524f62e9c..2fa38a5d3d384158f982b2697fd296b9c0f81546 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -68,6 +68,7 @@ describe Project, models: true do it { is_expected.to have_many(:runners) } it { is_expected.to have_many(:variables) } it { is_expected.to have_many(:triggers) } + it { is_expected.to have_many(:todos).dependent(:destroy) } end describe 'modules' do