Class: AlertManagement::MetricImages::UploadService
- Inherits:
-
BaseService
- Object
- BaseService
- AlertManagement::MetricImages::UploadService
- Defined in:
- app/services/alert_management/metric_images/upload_service.rb
Instance Attribute Summary collapse
-
#alert ⇒ Object
readonly
Returns the value of attribute alert.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#url_text ⇒ Object
readonly
Returns the value of attribute url_text.
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(alert, current_user, params = {}) ⇒ UploadService
constructor
A new instance of UploadService.
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(alert, current_user, params = {}) ⇒ UploadService
Returns a new instance of UploadService.
8 9 10 11 12 13 14 15 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 8 def initialize(alert, current_user, params = {}) super @alert = alert @file = params.fetch(:file) @url = params.fetch(:url, nil) @url_text = params.fetch(:url_text, nil) end |
Instance Attribute Details
#alert ⇒ Object (readonly)
Returns the value of attribute alert.
6 7 8 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 6 def alert @alert end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 6 def file @file end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
6 7 8 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 6 def metric @metric end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 6 def url @url end |
#url_text ⇒ Object (readonly)
Returns the value of attribute url_text.
6 7 8 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 6 def url_text @url_text end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/alert_management/metric_images/upload_service.rb', line 17 def execute unless can_upload_metrics? return ServiceResponse.error( message: _("You are not authorized to upload metric images"), http_status: :forbidden ) end metric = AlertManagement::MetricImage.new( alert: alert, file: file, url: url, url_text: url_text ) if metric.save ServiceResponse.success(payload: { metric: metric, alert: alert }) else ServiceResponse.error(message: metric.errors..join(', '), http_status: :bad_request) end end |