debian-mirror-gitlab/app/serializers/job_entity.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
class JobEntity < Grape::Entity
2017-08-17 22:00:37 +05:30
include RequestAwareEntity
expose :id
expose :name
expose :build_path do |build|
2017-09-10 17:25:29 +05:30
build.target_url || path_to(:namespace_project_job, build)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
expose :retry_path, if: -> (*) { retryable? } do |build|
path_to(:retry_namespace_project_job, build)
end
expose :cancel_path, if: -> (*) { cancelable? } do |build|
path_to(:cancel_namespace_project_job, build)
2017-08-17 22:00:37 +05:30
end
expose :play_path, if: -> (*) { playable? } do |build|
2017-09-10 17:25:29 +05:30
path_to(:play_namespace_project_job, build)
2017-08-17 22:00:37 +05:30
end
expose :playable?, as: :playable
expose :created_at
expose :updated_at
expose :detailed_status, as: :status, with: StatusEntity
private
alias_method :build, :object
2017-09-10 17:25:29 +05:30
def cancelable?
build.cancelable? && can?(request.current_user, :update_build, build)
end
def retryable?
build.retryable? && can?(request.current_user, :update_build, build)
end
2017-08-17 22:00:37 +05:30
def playable?
build.playable? && can?(request.current_user, :update_build, build)
end
def detailed_status
build.detailed_status(request.current_user)
end
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build)
end
end