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