Commit b173ea2b authored by DJ Mountney's avatar DJ Mountney

Use the project finder in the todos finder to limit todos to just ones within...

Use the project finder in the todos finder to limit todos to just ones within projects you have access to.
parent 4280575f
...@@ -23,7 +23,7 @@ class TodosFinder ...@@ -23,7 +23,7 @@ class TodosFinder
end end
def execute def execute
items = current_user.todos.not_pending_delete items = current_user.todos
items = by_action_id(items) items = by_action_id(items)
items = by_author(items) items = by_author(items)
items = by_project(items) items = by_project(items)
...@@ -78,6 +78,16 @@ class TodosFinder ...@@ -78,6 +78,16 @@ class TodosFinder
@project @project
end 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? def type?
type.present? && ['Issue', 'MergeRequest'].include?(type) type.present? && ['Issue', 'MergeRequest'].include?(type)
end end
...@@ -105,6 +115,8 @@ class TodosFinder ...@@ -105,6 +115,8 @@ class TodosFinder
def by_project(items) def by_project(items)
if project? if project?
items = items.where(project: project) items = items.where(project: project)
elsif projects
items = items.merge(projects).joins(:project)
end end
items items
......
...@@ -19,7 +19,6 @@ class Todo < ActiveRecord::Base ...@@ -19,7 +19,6 @@ class Todo < ActiveRecord::Base
scope :pending, -> { with_state(:pending) } scope :pending, -> { with_state(:pending) }
scope :done, -> { with_state(:done) } 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 state_machine :state, initial: :pending do
event :done do event :done do
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe 'Dashboard Todos', feature: true do describe 'Dashboard Todos', feature: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:author) { create(:user) } let(:author) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
describe 'GET /dashboard/todos' do describe 'GET /dashboard/todos' 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