diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 15:08:52 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 15:08:52 +0000 |
commit | 0ab47b994caa80c5587f33dc818626b66cfdafe2 (patch) | |
tree | 5ef3976d2f84e3368903a67ba2dbd87a74b9a43c /lib/api/entities/release.rb | |
parent | 1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (diff) | |
download | gitlab-ce-0ab47b994caa80c5587f33dc818626b66cfdafe2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/entities/release.rb')
-rw-r--r-- | lib/api/entities/release.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/api/entities/release.rb b/lib/api/entities/release.rb new file mode 100644 index 00000000000..dc4b91e594e --- /dev/null +++ b/lib/api/entities/release.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +module API + module Entities + class Release < Grape::Entity + include ::API::Helpers::Presentable + + expose :name do |release, _| + can_download_code? ? release.name : "Release-#{release.id}" + end + expose :tag, as: :tag_name, if: ->(_, _) { can_download_code? } + expose :description + expose :description_html do |entity| + MarkupHelper.markdown_field(entity, :description) + end + expose :created_at + expose :released_at + expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? } + expose :commit, using: Entities::Commit, if: ->(_, _) { can_download_code? } + expose :upcoming_release?, as: :upcoming_release + expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? && can_read_milestone? } + expose :commit_path, expose_nil: false + expose :tag_path, expose_nil: false + expose :evidence_sha, expose_nil: false, if: ->(_, _) { can_download_code? } + expose :assets do + expose :assets_count, as: :count do |release, _| + assets_to_exclude = can_download_code? ? [] : [:sources] + release.assets_count(except: assets_to_exclude) + end + expose :sources, using: Entities::Releases::Source, if: ->(_, _) { can_download_code? } + expose :links, using: Entities::Releases::Link do |release, options| + release.links.sorted + end + expose :evidence_file_path, expose_nil: false, if: ->(_, _) { can_download_code? } + end + expose :_links do + expose :self_url, as: :self, expose_nil: false + expose :merge_requests_url, expose_nil: false + expose :issues_url, expose_nil: false + expose :edit_url, expose_nil: false + end + + private + + def can_download_code? + Ability.allowed?(options[:current_user], :download_code, object.project) + end + + def can_read_milestone? + Ability.allowed?(options[:current_user], :read_milestone, object.project) + end + end + end +end |