Skip to content
代码片段 群组 项目
未验证 提交 8637671d 编辑于 作者: Phil Hughes's avatar Phil Hughes
浏览文件

Update custom emoji to use the asset proxy

上级 f53f8dee
No related branches found
No related tags found
无相关合并请求
......@@ -21,7 +21,6 @@ class CustomEmojiType < BaseObject
field :url, GraphQL::Types::String,
null: false,
method: :file,
description: 'Link to file of the emoji.'
field :external, GraphQL::Types::Boolean,
......
......@@ -67,7 +67,7 @@ def url
return if TanukiEmoji.find_by_alpha_code(name)
Groups::CustomEmojiFinder.new(resource_parent, { include_ancestor_groups: true }).execute
.by_name(name)&.select(:url)&.first&.url
.by_name(name)&.select(:file)&.first&.url
end
def expire_cache
......
......@@ -45,8 +45,6 @@ class CustomEmoji < ApplicationRecord
.order(order)
end
alias_attribute :url, :file # this might need a change in https://gitlab.com/gitlab-org/gitlab/-/issues/230467
scope :for_resource, -> (resource) do
return none if resource.nil?
return none unless resource.is_a?(Group)
......@@ -54,6 +52,10 @@ class CustomEmoji < ApplicationRecord
resource.custom_emoji
end
def url
Gitlab::AssetProxy.proxy_url(file)
end
private
def valid_emoji_name
......
......@@ -6,7 +6,7 @@
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let(:args) { { group_path: group.full_path, name: 'tanuki', url: 'https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png' } }
let(:args) { { group_path: group.full_path, name: 'tanuki', file: 'https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png' } }
before do
group.add_developer(user)
......
......@@ -63,4 +63,20 @@
expect(doc.css('gl-emoji').size).to eq 1
end
context 'when asset proxy is configured' do
before do
stub_asset_proxy_setting(
enabled: true,
secret_key: 'shared-secret',
url: 'https://assets.example.com'
)
end
it 'uses the proxied url' do
doc = filter('<p>:tanuki:</p>')
expect(doc.css('gl-emoji').first.attributes['data-fallback-src'].value).to start_with('https://assets.example.com')
end
end
end
......@@ -81,4 +81,20 @@
it { expect(described_class.for_namespaces([subgroup.id, group.id])).to eq([subgroup_emoji]) }
end
end
describe '#url' do
before do
stub_asset_proxy_setting(
enabled: true,
secret_key: 'shared-secret',
url: 'https://assets.example.com'
)
end
it 'uses the asset proxy' do
emoji = build(:custom_emoji, name: 'gitlab', file: "http://example.com/test.png")
expect(emoji.url).to eq("https://assets.example.com/08df250eeeef1a8cf2c761475ac74c5065105612/687474703a2f2f6578616d706c652e636f6d2f746573742e706e67")
end
end
end
......@@ -7,7 +7,7 @@
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group, :private) }
let_it_be(:custom_emoji) { create(:custom_emoji, group: group) }
let_it_be(:custom_emoji) { create(:custom_emoji, group: group, file: 'http://example.com/test.png') }
before do
group.add_developer(current_user)
......@@ -32,6 +32,7 @@ def custom_emoji_query(group)
expect(response).to have_gitlab_http_status(:ok)
expect(graphql_data['group']['customEmoji']['nodes'].count).to eq(1)
expect(graphql_data['group']['customEmoji']['nodes'].first['name']).to eq(custom_emoji.name)
expect(graphql_data['group']['customEmoji']['nodes'].first['url']).to eq(custom_emoji.file)
end
it 'returns nil group when unauthorised' do
......@@ -40,5 +41,20 @@ def custom_emoji_query(group)
expect(graphql_data['group']).to be_nil
end
context 'when asset proxy is configured' do
before do
stub_asset_proxy_setting(
enabled: true,
secret_key: 'shared-secret',
url: 'https://assets.example.com'
)
end
it 'uses the proxied url' do
post_graphql(custom_emoji_query(group), current_user: current_user)
expect(graphql_data['group']['customEmoji']['nodes'].first['url']).to start_with('https://assets.example.com')
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册