environment_entity.rb 1.29 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's avatar
Kamil Trzcinski committed
10
  expose :stop_action?
11

Kamil Trzcinski's avatar
Kamil Trzcinski committed
12
  expose :rollout_status, if: -> (*) { can_read_deploy_board? }, using: RolloutStatusEntity
13

Kamil Trzcinski's avatar
Kamil Trzcinski committed
14
  expose :metrics_path, if: -> (*) { environment.has_metrics? } do |environment|
15
    metrics_project_environment_path(environment.project, environment)
16 17
  end

18
  expose :environment_path do |environment|
19
    project_environment_path(environment.project, environment)
20 21
  end

22
  expose :stop_path do |environment|
23
    stop_project_environment_path(environment.project, environment)
24 25
  end

26
  expose :terminal_path, if: ->(*) { environment.has_terminals? } do |environment|
27
    can?(request.current_user, :admin_environment, environment.project) &&
28
      terminal_project_environment_path(environment.project, environment)
29 30
  end

31 32
  expose :folder_path do |environment|
    folder_project_environments_path(environment.project, environment.folder_name)
33 34
  end

35
  expose :created_at, :updated_at
Kamil Trzcinski's avatar
Kamil Trzcinski committed
36 37 38 39 40 41 42 43 44 45 46 47

  private

  alias_method :environment, :object

  def current_user
    request.current_user
  end

  def can_read_deploy_board?
    can?(current_user, :read_deploy_board, environment.project)
  end
48
end