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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
798 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
class RunnerEntity < Grape::Entity
include RequestAwareEntity
2021-04-29 21:17:54 +05:30
expose :id, :description, :short_sha
2017-09-10 17:25:29 +05:30
2018-12-05 23:21:45 +05:30
expose :edit_path, if: -> (*) { can_edit_runner? } do |runner|
2017-09-10 17:25:29 +05:30
edit_project_runner_path(project, runner)
end
2023-07-09 08:55:56 +05:30
expose :admin_path, if: -> (*) { can_admin_runner? } do |runner|
Gitlab::Routing.url_helpers.admin_runner_url(runner)
end
2017-09-10 17:25:29 +05:30
private
alias_method :runner, :object
def project
request.project
end
2018-12-05 23:21:45 +05:30
2023-07-09 08:55:56 +05:30
def current_user
request.current_user
end
2018-12-05 23:21:45 +05:30
def can_edit_runner?
2023-07-09 08:55:56 +05:30
can?(current_user, :update_runner, runner) && runner.project_type?
end
# can_admin_all_resources? is used here because the
# path exposed is only available to admins
def can_admin_runner?
current_user&.can_admin_all_resources?
2018-12-05 23:21:45 +05:30
end
2017-09-10 17:25:29 +05:30
end