summaryrefslogtreecommitdiff
path: root/app/services/environments/update_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/environments/update_service.rb')
-rw-r--r--app/services/environments/update_service.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/services/environments/update_service.rb b/app/services/environments/update_service.rb
new file mode 100644
index 00000000000..e02b2398426
--- /dev/null
+++ b/app/services/environments/update_service.rb
@@ -0,0 +1,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