debian-mirror-gitlab/lib/api/entities/release.rb

47 lines
1.8 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module API
module Entities
2022-06-21 17:19:12 +05:30
class Release < BasicReleaseDetails
2020-03-13 15:44:24 +05:30
include ::API::Helpers::Presentable
2021-06-08 01:23:25 +05:30
expose :description_html, if: -> (_, options) { options[:include_html_description] } do |entity|
2020-04-08 14:13:33 +05:30
MarkupHelper.markdown_field(entity, :description, current_user: options[:current_user])
2020-03-13 15:44:24 +05:30
end
expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? }
2023-01-13 00:05:48 +05:30
expose :commit, using: Entities::Commit, if: ->(_, _) { can_read_code? }
2021-03-08 18:12:59 +05:30
expose :milestones,
using: Entities::MilestoneWithStats,
if: -> (release, _) { release.milestones.present? && can_read_milestone? } do |release, _|
release.milestones.order_by_dates_and_title
end
2023-01-13 00:05:48 +05:30
expose :commit_path,
documentation: { type: 'string', example: '/root/app/commit/588440f66559714280628a4f9799f0c4eb880a4a' },
expose_nil: false
expose :tag_path, documentation: { type: 'string', example: '/root/app/-/tags/v1.0' }, expose_nil: false
2020-04-22 19:07:51 +05:30
2020-03-13 15:44:24 +05:30
expose :assets do
2023-01-13 00:05:48 +05:30
expose :assets_count, documentation: { type: 'integer', example: 2 }, as: :count
expose :sources, using: Entities::Releases::Source, if: ->(_, _) { can_read_code? }
2021-06-08 01:23:25 +05:30
expose :sorted_links, as: :links, using: Entities::Releases::Link
2020-03-13 15:44:24 +05:30
end
2023-01-13 00:05:48 +05:30
expose :evidences, using: Entities::Releases::Evidence, expose_nil: false, if: ->(_, _) { can_read_code? }
2020-03-13 15:44:24 +05:30
expose :_links do
expose :self_url, as: :self, expose_nil: false
expose :edit_url, expose_nil: false
end
private
2023-01-13 00:05:48 +05:30
def can_read_code?
Ability.allowed?(options[:current_user], :read_code, object.project)
2020-03-13 15:44:24 +05:30
end
def can_read_milestone?
Ability.allowed?(options[:current_user], :read_milestone, object.project)
end
end
end
end