Class: Environments::UpdateService
- Inherits:
-
BaseService
- Object
- BaseService
- Environments::UpdateService
- Defined in:
- app/services/environments/update_service.rb
Constant Summary collapse
- ALLOWED_ATTRIBUTES =
%i[description external_url tier cluster_agent kubernetes_namespace flux_resource_path auto_stop_setting].freeze
Constants inherited from BaseService
BaseService::UnauthorizedError
Instance Attribute Summary
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
Methods inherited from BaseService
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
This class inherits a constructor from BaseService
Instance Method Details
#execute(environment) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/environments/update_service.rb', line 8 def execute(environment) unless can?(current_user, :update_environment, environment) return ServiceResponse.error( message: _('Unauthorized to update the environment'), payload: { environment: environment } ) end if return ServiceResponse.error( message: _('Unauthorized to access the cluster agent in this project'), payload: { environment: environment }) end begin environment.update!(**params.slice(*ALLOWED_ATTRIBUTES)) ServiceResponse.success(payload: { environment: environment }) rescue ActiveRecord::RecordInvalid => err ServiceResponse.error(message: err.record.errors., payload: { environment: environment }) rescue ArgumentError => err ServiceResponse.error(message: [err.], payload: { environment: environment }) end end |