summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDJ Mountney <david@twkie.net>2016-06-01 16:44:35 -0700
committerDJ Mountney <david@twkie.net>2016-06-02 12:20:27 -0700
commitb173ea2bd4bbc65529b827f9afa5999f6f04579e (patch)
treebdebc63c33170f59d5f3e669cbf5d01584b02dd1
parent4280575fc0888632196cf4483dcd777618c13390 (diff)
downloadgitlab-ce-b173ea2bd4bbc65529b827f9afa5999f6f04579e.tar.gz
Use the project finder in the todos finder to limit todos to just ones within projects you have access to.
-rw-r--r--app/finders/todos_finder.rb14
-rw-r--r--app/models/todo.rb1
-rw-r--r--spec/features/todos/todos_spec.rb2
3 files changed, 14 insertions, 3 deletions
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
diff --git a/spec/features/todos/todos_spec.rb b/spec/features/todos/todos_spec.rb
index c8c86a3ff47..c0a1cd64f32 100644
--- a/spec/features/todos/todos_spec.rb
+++ b/spec/features/todos/todos_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe 'Dashboard Todos', feature: true do
let(:user) { create(:user) }
let(:author) { create(:user) }
- let(:project) { create(:project) }
+ let(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
let(:issue) { create(:issue) }
describe 'GET /dashboard/todos' do