2016-10-28 08:32:07 -04:00
|
|
|
class EnvironmentEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :name
|
2016-11-03 07:54:10 -04:00
|
|
|
expose :state
|
|
|
|
expose :external_url
|
|
|
|
expose :environment_type
|
|
|
|
expose :last_deployment, using: DeploymentEntity
|
2018-07-12 06:22:11 -04:00
|
|
|
expose :stop_action_available?, as: :has_stop_action
|
2016-10-28 08:32:07 -04:00
|
|
|
|
2017-03-31 05:20:11 -04:00
|
|
|
expose :metrics_path, if: -> (environment, _) { environment.has_metrics? } do |environment|
|
2017-06-29 13:06:35 -04:00
|
|
|
metrics_project_environment_path(environment.project, environment)
|
2017-03-31 05:20:11 -04:00
|
|
|
end
|
|
|
|
|
2016-11-17 10:08:05 -05:00
|
|
|
expose :environment_path do |environment|
|
2017-06-29 13:06:35 -04:00
|
|
|
project_environment_path(environment.project, environment)
|
2016-11-02 09:36:21 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 16:31:53 -05:00
|
|
|
expose :stop_path do |environment|
|
2017-06-29 13:06:35 -04:00
|
|
|
stop_project_environment_path(environment.project, environment)
|
2016-11-18 16:31:53 -05:00
|
|
|
end
|
|
|
|
|
2016-11-22 14:55:56 -05:00
|
|
|
expose :terminal_path, if: ->(environment, _) { environment.has_terminals? } do |environment|
|
2017-05-09 00:15:34 -04:00
|
|
|
can?(request.current_user, :admin_environment, environment.project) &&
|
2017-06-29 13:06:35 -04:00
|
|
|
terminal_project_environment_path(environment.project, environment)
|
2016-11-22 14:55:56 -05:00
|
|
|
end
|
|
|
|
|
2017-08-21 11:46:45 -04:00
|
|
|
expose :folder_path do |environment|
|
|
|
|
folder_project_environments_path(environment.project, environment.folder_name)
|
|
|
|
end
|
|
|
|
|
2016-11-03 07:54:10 -04:00
|
|
|
expose :created_at, :updated_at
|
2018-07-10 04:11:04 -04:00
|
|
|
|
|
|
|
expose :can_stop do |environment|
|
|
|
|
environment.available? && can?(current_user, :stop_environment, environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
2016-10-28 08:32:07 -04:00
|
|
|
end
|