Commit 56a54c62 authored by Robert Schilling's avatar Robert Schilling

Add confidential_only scop to issue model

parent 73e3a1cd
...@@ -73,17 +73,11 @@ class IssuesFinder < IssuableFinder ...@@ -73,17 +73,11 @@ class IssuesFinder < IssuableFinder
by_confidential(issues) by_confidential(issues)
end end
# rubocop: disable CodeReuse/ActiveRecord
def by_confidential(items) def by_confidential(items)
if params[:confidential] == 'yes' return items unless params[:confidential].present?
items.where('issues.confidential = TRUE')
elsif params[:confidential] == 'no' params[:confidential] == 'yes' ? items.confidential_only : items.public_only
items.where.not('issues.confidential = TRUE')
else
items
end
end end
# rubocop: enable CodeReuse/ActiveRecord
def by_due_date(items) def by_due_date(items)
if due_date? if due_date?
......
...@@ -66,6 +66,7 @@ class Issue < ActiveRecord::Base ...@@ -66,6 +66,7 @@ class Issue < ActiveRecord::Base
scope :preload_associations, -> { preload(:labels, project: :namespace) } scope :preload_associations, -> { preload(:labels, project: :namespace) }
scope :public_only, -> { where(confidential: false) } scope :public_only, -> { where(confidential: false) }
scope :confidential_only, -> { where(confidential: true) }
after_save :expire_etag_cache after_save :expire_etag_cache
after_save :ensure_metrics, unless: :imported? after_save :ensure_metrics, unless: :imported?
......
...@@ -765,6 +765,15 @@ describe Issue do ...@@ -765,6 +765,15 @@ describe Issue do
end end
end end
describe '.confidential_only' do
it 'only returns confidential_only issues' do
create(:issue)
confidential_issue = create(:issue, confidential: true)
expect(described_class.confidential_only).to eq([confidential_issue])
end
end
it_behaves_like 'throttled touch' do it_behaves_like 'throttled touch' do
subject { create(:issue, updated_at: 1.hour.ago) } subject { create(:issue, updated_at: 1.hour.ago) }
end end
......
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