Commit 27b068d7 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Ensure snippets enabled in GraphQL resolver

When resolving snippets for a project, there is no need
to look up Snippets if the project snippets
feature is disabled
parent 796cd50d
......@@ -10,6 +10,11 @@ module Resolvers
def resolve(**args)
return Snippet.none if project.nil?
unless project.feature_available?(:snippets, current_user)
raise Gitlab::Graphql::Errors::ResourceNotAvailable,
'Snippets are not enabled for this Project'
end
super
end
......
---
title: Project Snippets GraphQL resolver checks feature status
merge_request: 26158
author:
type: performance
......@@ -75,6 +75,16 @@ describe Resolvers::Projects::SnippetsResolver do
expect(resolve_snippets(context: { current_user: other_user }, args: { ids: project_snippet.to_global_id })).to be_empty
end
end
context 'when project snippets are disabled' do
it 'raises an error' do
disabled_snippet_project = create(:project, :snippets_disabled)
disabled_snippet_project.add_developer(current_user)
expect(SnippetsFinder).not_to receive(:new)
expect { resolve_snippets(obj: disabled_snippet_project) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
def resolve_snippets(args: {}, context: { current_user: current_user }, obj: project)
......
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