From c3e923c496b7d1c344a5fa68cef4a80ce23c90d0 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 25 May 2016 18:52:10 -0700 Subject: Ensure we don't show TODOS for projects pending delete By joining the Todos on the project table. --- app/finders/todos_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 4bd46a76087..f638b5bf91f 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -23,7 +23,7 @@ class TodosFinder end def execute - items = current_user.todos + items = current_user.todos.joins(:project).where(projects: { pending_delete: false }) items = by_action_id(items) items = by_author(items) items = by_project(items) -- cgit v1.2.3 From 4ecc10fade61a1b45cd45ea4189e95a2acbea353 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 25 May 2016 21:31:36 -0700 Subject: Reduce the filters on the todos joins project query by being explicit about the join --- app/finders/todos_finder.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index f638b5bf91f..3243d62fc95 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -23,7 +23,13 @@ class TodosFinder end def execute - items = current_user.todos.joins(:project).where(projects: { pending_delete: false }) + items = current_user.todos + + # Filter out todos linked to project pending deletion + items = items.joins( + 'INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false' + ) + items = by_action_id(items) items = by_author(items) items = by_project(items) -- cgit v1.2.3 From 4280575fc0888632196cf4483dcd777618c13390 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Mon, 30 May 2016 10:59:14 -0700 Subject: Move filtering todos by projects not pending deletion into a scope on the todo model --- app/finders/todos_finder.rb | 8 +------- app/models/todo.rb | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 3243d62fc95..5d7d55180e1 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -23,13 +23,7 @@ class TodosFinder end def execute - items = current_user.todos - - # Filter out todos linked to project pending deletion - items = items.joins( - 'INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false' - ) - + items = current_user.todos.not_pending_delete items = by_action_id(items) items = by_author(items) items = by_project(items) diff --git a/app/models/todo.rb b/app/models/todo.rb index 3a091373329..f66755436ea 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -19,6 +19,7 @@ class Todo < ActiveRecord::Base scope :pending, -> { with_state(:pending) } scope :done, -> { with_state(:done) } + scope :not_pending_delete, -> { joins('INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false') } state_machine :state, initial: :pending do event :done do -- cgit v1.2.3 From b173ea2bd4bbc65529b827f9afa5999f6f04579e Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 1 Jun 2016 16:44:35 -0700 Subject: Use the project finder in the todos finder to limit todos to just ones within projects you have access to. --- app/finders/todos_finder.rb | 14 +++++++++++++- app/models/todo.rb | 1 - 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 5d7d55180e1..6fbe68a720d 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -23,7 +23,7 @@ class TodosFinder end def execute - items = current_user.todos.not_pending_delete + items = current_user.todos items = by_action_id(items) items = by_author(items) items = by_project(items) @@ -78,6 +78,16 @@ class TodosFinder @project end + def projects + return @projects if defined?(@projects) + + if project? + @projects = project + else + @projects = ProjectsFinder.new.execute(current_user).reorder(nil) + end + end + def type? type.present? && ['Issue', 'MergeRequest'].include?(type) end @@ -105,6 +115,8 @@ class TodosFinder def by_project(items) if project? items = items.where(project: project) + elsif projects + items = items.merge(projects).joins(:project) end items diff --git a/app/models/todo.rb b/app/models/todo.rb index f66755436ea..3a091373329 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -19,7 +19,6 @@ class Todo < ActiveRecord::Base scope :pending, -> { with_state(:pending) } scope :done, -> { with_state(:done) } - scope :not_pending_delete, -> { joins('INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false') } state_machine :state, initial: :pending do event :done do -- cgit v1.2.3 From f0ca487cd513d50c807e4226a1ee459586f16b08 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Thu, 2 Jun 2016 14:17:46 -0700 Subject: Reorder the todos because the use of the project finder attempts to order them differently --- app/finders/todos_finder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 6fbe68a720d..1d88116d7d2 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -30,7 +30,7 @@ class TodosFinder items = by_state(items) items = by_type(items) - items + items.reorder(id: :desc) end private @@ -84,7 +84,7 @@ class TodosFinder if project? @projects = project else - @projects = ProjectsFinder.new.execute(current_user).reorder(nil) + @projects = ProjectsFinder.new.execute(current_user) end end -- cgit v1.2.3