Commit 1ea55ffc authored by Toon Claes's avatar Toon Claes

API: Expose URL of award emoji image

For custom emoji there is source image URL. This change exposes that
through the award emoji API when it is available.
parent f31ba9e7
...@@ -60,6 +60,10 @@ class AwardEmoji < ApplicationRecord ...@@ -60,6 +60,10 @@ class AwardEmoji < ApplicationRecord
self.name == UPVOTE_NAME self.name == UPVOTE_NAME
end end
def url
awardable.try(:namespace)&.custom_emoji&.by_name(name)&.first&.url
end
def expire_cache def expire_cache
awardable.try(:bump_updated_at) awardable.try(:bump_updated_at)
awardable.try(:expire_etag_cache) awardable.try(:expire_etag_cache)
......
...@@ -8,6 +8,7 @@ module API ...@@ -8,6 +8,7 @@ module API
expose :user, using: Entities::UserBasic expose :user, using: Entities::UserBasic
expose :created_at, :updated_at expose :created_at, :updated_at
expose :awardable_id, :awardable_type expose :awardable_id, :awardable_type
expose :url
end end
end end
end end
...@@ -26,6 +26,23 @@ RSpec.describe API::AwardEmoji do ...@@ -26,6 +26,23 @@ RSpec.describe API::AwardEmoji do
expect(json_response.first['name']).to eq(award_emoji.name) expect(json_response.first['name']).to eq(award_emoji.name)
end end
it "includes custom emoji attributes" do
group = create(:group)
group.add_maintainer(user)
project = create(:project, namespace: group)
custom_emoji = create(:custom_emoji, name: 'partyparrot', namespace: group)
issue = create(:issue, project: project)
create(:award_emoji, awardable: issue, user: user, name: custom_emoji.name)
get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(custom_emoji.name)
expect(json_response.first['url']).to eq(custom_emoji.file)
end
it "returns a 404 error when issue id not found" do it "returns a 404 error when issue id not found" do
get api("/projects/#{project.id}/issues/#{non_existing_record_iid}/award_emoji", user) get api("/projects/#{project.id}/issues/#{non_existing_record_iid}/award_emoji", user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment