Class: Uploads::DestroyService
- Inherits:
-
BaseService
- Object
- BaseService
- Uploads::DestroyService
- Defined in:
- app/services/uploads/destroy_service.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#model ⇒ Object
Returns the value of attribute model.
Attributes inherited from BaseService
Instance Method Summary collapse
- #execute(secret, filename) ⇒ Object
-
#initialize(model, user = nil) ⇒ DestroyService
constructor
A new instance of DestroyService.
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
#initialize(model, user = nil) ⇒ DestroyService
Returns a new instance of DestroyService.
7 8 9 10 |
# File 'app/services/uploads/destroy_service.rb', line 7 def initialize(model, user = nil) @model = model @current_user = user end |
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
5 6 7 |
# File 'app/services/uploads/destroy_service.rb', line 5 def current_user @current_user end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'app/services/uploads/destroy_service.rb', line 5 def model @model end |
Instance Method Details
#execute(secret, filename) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/uploads/destroy_service.rb', line 12 def execute(secret, filename) upload = find_upload(secret, filename) unless current_user && upload && current_user.can?(:destroy_upload, upload) return error(_("The resource that you are attempting to access does not "\ "exist or you don't have permission to perform this action.")) end if upload.destroy success(upload: upload) else error(_('Upload could not be deleted.')) end end |