2018-10-09 12:17:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class EnvironmentStatusEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :name
|
2018-10-29 07:34:41 -04:00
|
|
|
expose :status
|
2018-10-09 12:17:40 -04:00
|
|
|
|
|
|
|
expose :url do |es|
|
|
|
|
project_environment_path(es.project, es.environment)
|
|
|
|
end
|
|
|
|
|
2019-07-01 05:40:59 -04:00
|
|
|
expose :metrics_url, if: ->(*) { can_read_environment? && has_metrics? } do |es|
|
2018-10-09 12:17:40 -04:00
|
|
|
metrics_project_environment_deployment_path(es.project, es.environment, es.deployment)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :metrics_monitoring_url, if: ->(*) { can_read_environment? } do |es|
|
2022-04-08 05:08:18 -04:00
|
|
|
project_metrics_dashboard_path(es.project, environment: es.environment)
|
2018-10-09 12:17:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :stop_url, if: ->(*) { can_stop_environment? } do |es|
|
|
|
|
stop_project_environment_path(es.project, es.environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :external_url do |es|
|
|
|
|
es.environment.external_url
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :external_url_formatted do |es|
|
|
|
|
es.environment.formatted_external_url
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :deployed_at
|
|
|
|
|
|
|
|
expose :deployed_at_formatted do |es|
|
|
|
|
es.deployment.try(:formatted_deployment_time)
|
|
|
|
end
|
|
|
|
|
2019-11-29 04:06:31 -05:00
|
|
|
expose :deployment, as: :details do |es, options|
|
|
|
|
DeploymentEntity.represent(es.deployment, options.merge(project: es.project, only: [:playable_build]))
|
|
|
|
end
|
|
|
|
|
2018-11-12 11:33:59 -05:00
|
|
|
expose :changes
|
2018-10-18 10:17:24 -04:00
|
|
|
|
2018-10-09 12:17:40 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def environment
|
|
|
|
object.environment
|
|
|
|
end
|
|
|
|
|
2019-07-01 05:40:59 -04:00
|
|
|
def has_metrics?
|
|
|
|
object.has_metrics?
|
2018-11-14 06:11:27 -05:00
|
|
|
end
|
|
|
|
|
2018-10-09 12:17:40 -04:00
|
|
|
def project
|
|
|
|
object.environment.project
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_read_environment?
|
|
|
|
can?(current_user, :read_environment, environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_stop_environment?
|
|
|
|
can?(current_user, :stop_environment, environment)
|
|
|
|
end
|
|
|
|
end
|