summaryrefslogtreecommitdiff
path: root/app/serializers/build_action_entity.rb
blob: 95833c3528f0621299c7096c133e13fffe655bc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

class BuildActionEntity < Grape::Entity
  include RequestAwareEntity

  expose :name do |build|
    build.name
  end

  expose :path do |build|
    play_project_job_path(build.project, build)
  end

  expose :playable?, as: :playable
  expose :scheduled?, as: :scheduled
  expose :scheduled_at, if: -> (*) { scheduled? }

  expose :unschedule_path, if: -> (build) { build.scheduled? } do |build|
    unschedule_project_job_path(build.project, build)
  end

  private

  alias_method :build, :object

  def playable?
    build.playable? && can?(request.current_user, :update_build, build)
  end

  def scheduled?
    build.scheduled?
  end
end