Commit 0a8f611b authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'fj-add-report-permission-to-graphql-snippet-endpoint' into 'master'

Add reportSnippet permission to snippet GraphQL

See merge request gitlab-org/gitlab!21836
parents 264efb4d 57a87eeb
......@@ -10,6 +10,7 @@ module Types
permission_field :read_snippet, method: :can_read_snippet?
permission_field :update_snippet, method: :can_update_snippet?
permission_field :admin_snippet, method: :can_admin_snippet?
permission_field :report_snippet, method: :can_report_as_spam?
end
end
end
......@@ -23,6 +23,10 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
can_access_resource?("admin")
end
def can_report_as_spam?
snippet.submittable_as_spam_by?(current_user)
end
private
def can_access_resource?(ability_prefix)
......
---
title: Add reportSnippet permission to Snippet GraphQL
merge_request: 21836
author:
type: other
......@@ -5689,6 +5689,11 @@ type SnippetPermissions {
"""
readSnippet: Boolean!
"""
Whether or not a user can perform `report_snippet` on this resource
"""
reportSnippet: Boolean!
"""
Whether or not a user can perform `update_snippet` on this resource
"""
......
......@@ -6802,6 +6802,24 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "reportSnippet",
"description": "Whether or not a user can perform `report_snippet` on this resource",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updateSnippet",
"description": "Whether or not a user can perform `update_snippet` on this resource",
......
......@@ -842,6 +842,7 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph
| `readSnippet` | Boolean! | Whether or not a user can perform `read_snippet` on this resource |
| `updateSnippet` | Boolean! | Whether or not a user can perform `update_snippet` on this resource |
| `adminSnippet` | Boolean! | Whether or not a user can perform `admin_snippet` on this resource |
| `reportSnippet` | Boolean! | Whether or not a user can perform `report_snippet` on this resource |
### Submodule
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
describe Types::PermissionTypes::Snippet do
it 'returns the snippets permissions' do
expected_permissions = [
:create_note, :award_emoji, :read_snippet, :update_snippet, :admin_snippet
:create_note, :award_emoji, :read_snippet, :update_snippet, :admin_snippet, :report_snippet
]
expected_permissions.each do |permission|
......
......@@ -127,4 +127,20 @@ describe SnippetPresenter do
end
end
end
describe '#can_report_as_spam' do
let(:snippet) { personal_snippet }
subject { presenter.can_report_as_spam? }
it 'returns false if the user cannot submit the snippet as spam' do
expect(subject).to be_falsey
end
it 'returns true if the user can submit the snippet as spam' do
allow(snippet).to receive(:submittable_as_spam_by?).and_return(true)
expect(subject).to be_truthy
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