BigW Consortium Gitlab

environment_entity.rb 1.15 KB
Newer Older
1 2 3 4 5
class EnvironmentEntity < Grape::Entity
  include RequestAwareEntity

  expose :id
  expose :name
6 7 8 9
  expose :state
  expose :external_url
  expose :environment_type
  expose :last_deployment, using: DeploymentEntity
Kamil Trzcinski committed
10
  expose :stop_action?
11

12 13 14 15 16 17 18
  expose :metrics_path, if: -> (environment, _) { environment.has_metrics? } do |environment|
    metrics_namespace_project_environment_path(
      environment.project.namespace,
      environment.project,
      environment)
  end

19 20
  expose :environment_path do |environment|
    namespace_project_environment_path(
21 22
      environment.project.namespace,
      environment.project,
23
      environment)
24 25
  end

26 27 28 29 30 31 32
  expose :stop_path do |environment|
    stop_namespace_project_environment_path(
      environment.project.namespace,
      environment.project,
      environment)
  end

33
  expose :terminal_path, if: ->(environment, _) { environment.has_terminals? } do |environment|
34
    can?(request.current_user, :admin_environment, environment.project) &&
35 36 37 38
      terminal_namespace_project_environment_path(
        environment.project.namespace,
        environment.project,
        environment)
39 40
  end

41
  expose :created_at, :updated_at
42
end