Commit 7f5e6c88 authored by Mark Chao's avatar Mark Chao

Only display current group's epics, because frontend does not yet

support otherwise.

Add spec
parent 9727255a
...@@ -25,7 +25,14 @@ module Groups ...@@ -25,7 +25,14 @@ module Groups
end end
def epics def epics
EpicsFinder.new(current_user, group_id: group.id).execute # TODO: change to EpicsFinder once frontend supports epics from descendant groups
DeclarativePolicy.user_scope do
if Ability.allowed?(current_user, :read_epic, group)
group.epics
else
[]
end
end
end end
end end
end end
...@@ -4,7 +4,7 @@ describe Groups::AutocompleteService do ...@@ -4,7 +4,7 @@ describe Groups::AutocompleteService do
let!(:group) { create(:group, :nested, avatar: fixture_file_upload('spec/fixtures/dk.png')) } let!(:group) { create(:group, :nested, avatar: fixture_file_upload('spec/fixtures/dk.png')) }
let!(:sub_group) { create(:group, parent: group) } let!(:sub_group) { create(:group, parent: group) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:epic) { create(:epic, group: group, author: user) } let!(:epic) { create(:epic, group: group, author: user) }
before do before do
create(:group_member, group: group, user: user) create(:group_member, group: group, user: user)
...@@ -53,4 +53,20 @@ describe Groups::AutocompleteService do ...@@ -53,4 +53,20 @@ describe Groups::AutocompleteService do
end end
end end
end end
describe '#epics' do
it 'returns nothing if not allowed' do
allow(Ability).to receive(:allowed?).with(user, :read_epic, group).and_return(false)
service = described_class.new(group, user)
expect(service.epics).to eq([])
end
it 'returns epics from group' do
allow(Ability).to receive(:allowed?).with(user, :read_epic, group).and_return(true)
service = described_class.new(group, user)
expect(service.epics).to contain_exactly(epic)
end
end
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