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 ...@@ -10,6 +10,7 @@ module Types
permission_field :read_snippet, method: :can_read_snippet? permission_field :read_snippet, method: :can_read_snippet?
permission_field :update_snippet, method: :can_update_snippet? permission_field :update_snippet, method: :can_update_snippet?
permission_field :admin_snippet, method: :can_admin_snippet? permission_field :admin_snippet, method: :can_admin_snippet?
permission_field :report_snippet, method: :can_report_as_spam?
end end
end end
end end
...@@ -23,6 +23,10 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated ...@@ -23,6 +23,10 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
can_access_resource?("admin") can_access_resource?("admin")
end end
def can_report_as_spam?
snippet.submittable_as_spam_by?(current_user)
end
private private
def can_access_resource?(ability_prefix) 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 { ...@@ -5689,6 +5689,11 @@ type SnippetPermissions {
""" """
readSnippet: Boolean! 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 Whether or not a user can perform `update_snippet` on this resource
""" """
......
...@@ -6802,6 +6802,24 @@ ...@@ -6802,6 +6802,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "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", "name": "updateSnippet",
"description": "Whether or not a user can perform `update_snippet` on this resource", "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 ...@@ -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 | | `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 | | `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 | | `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 ### Submodule
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe Types::PermissionTypes::Snippet do describe Types::PermissionTypes::Snippet do
it 'returns the snippets permissions' do it 'returns the snippets permissions' do
expected_permissions = [ 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| expected_permissions.each do |permission|
......
...@@ -127,4 +127,20 @@ describe SnippetPresenter do ...@@ -127,4 +127,20 @@ describe SnippetPresenter do
end end
end 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 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