Class: Snippets::DestroyService
- Inherits:
-
Object
- Object
- Snippets::DestroyService
- Includes:
- Gitlab::Allowable
- Defined in:
- app/services/snippets/destroy_service.rb
Constant Summary collapse
- DestroyError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#snippet ⇒ Object
readonly
Returns the value of attribute snippet.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(user, snippet) ⇒ DestroyService
constructor
A new instance of DestroyService.
Methods included from Gitlab::Allowable
Constructor Details
#initialize(user, snippet) ⇒ DestroyService
Returns a new instance of DestroyService.
11 12 13 14 |
# File 'app/services/snippets/destroy_service.rb', line 11 def initialize(user, snippet) @current_user = user @snippet = snippet end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
7 8 9 |
# File 'app/services/snippets/destroy_service.rb', line 7 def current_user @current_user end |
#snippet ⇒ Object (readonly)
Returns the value of attribute snippet.
7 8 9 |
# File 'app/services/snippets/destroy_service.rb', line 7 def snippet @snippet end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/snippets/destroy_service.rb', line 16 def execute if snippet.nil? return service_response_error('No snippet found.', 404) end unless user_can_delete_snippet? return service_response_error( "You don't have access to delete this snippet.", 403 ) end attempt_destroy! ServiceResponse.success(message: 'Snippet was deleted.') rescue DestroyError service_response_error('Failed to remove snippet repository.', 400) rescue StandardError service_response_error('Failed to remove snippet.', 400) end |