summaryrefslogtreecommitdiff
path: root/app/services/environments/update_service.rb
blob: e02b239842681852ded5d79d25449dd32a500dc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

module Environments
  class UpdateService < BaseService
    def execute(environment)
      unless can?(current_user, :update_environment, environment)
        return ServiceResponse.error(
          message: _('Unauthorized to update the environment'),
          payload: { environment: environment }
        )
      end

      if environment.update(**params)
        ServiceResponse.success(payload: { environment: environment })
      else
        ServiceResponse.error(
          message: environment.errors.full_messages,
          payload: { environment: environment }
        )
      end
    end
  end
end