Commit 28cd940f authored by Stan Hu's avatar Stan Hu Committed by Robert Speicher

Merge branch 'fix-relative-root-emoji-support' into 'master'

Fix emoji paths in relative root configurations

## What does this MR do?

If a site specifies a relative URL root, emoji files would omit the path from the URL, leading to lots of 404s.

## Are there points in the code the reviewer needs to double check?

At first, I tried to use `ActionView::Helpers::AssetUrlHelper.asset_url` since this is what it's intended to do. But this helper function is extremely slow, and it took minutes to generate the URLs for the hundreds of links needed for each emoji.

## Why was this MR needed?

Because emojis were broken in relative URL installations

## What are the relevant issue numbers?

#15642

## Does this MR meet the acceptance criteria?

- [X] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [X] Added for this feature/bug
  - [x] All builds are passing
- [X] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [X] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [X] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !5027
(cherry picked from commit 88dbc4d1)
parent 6e886413
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.9.5 v 8.9.5
- Fix emoji paths in relative root configurations. !5027
- Fix issues importing events in Import/Export. !4987 - Fix issues importing events in Import/Export. !4987
- Fixed 'use shortcuts' button on docs. !4979 - Fixed 'use shortcuts' button on docs. !4979
- Admin should be able to turn shared runners into specific ones. !4961 - Admin should be able to turn shared runners into specific ones. !4961
......
...@@ -66,8 +66,17 @@ module Gitlab ...@@ -66,8 +66,17 @@ module Gitlab
def self.urls def self.urls
@urls ||= begin @urls ||= begin
path = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json') path = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')
# Construct the full asset path ourselves because
# ActionView::Helpers::AssetUrlHelper.asset_url is slow for hundreds
# of entries since it has to do a lot of extra work (e.g. regexps).
prefix = Gitlab::Application.config.assets.prefix prefix = Gitlab::Application.config.assets.prefix
digest = Gitlab::Application.config.assets.digest digest = Gitlab::Application.config.assets.digest
base =
if defined?(Gitlab::Application.config.relative_url_root) && Gitlab::Application.config.relative_url_root
Gitlab::Application.config.relative_url_root
else
''
end
JSON.parse(File.read(path)).map do |hash| JSON.parse(File.read(path)).map do |hash|
if digest if digest
...@@ -76,7 +85,7 @@ module Gitlab ...@@ -76,7 +85,7 @@ module Gitlab
fname = hash['unicode'] fname = hash['unicode']
end end
{ name: hash['name'], path: "#{prefix}/#{fname}.png" } { name: hash['name'], path: File.join(base, prefix, "#{fname}.png") }
end end
end end
end end
......
...@@ -2,6 +2,10 @@ require 'spec_helper' ...@@ -2,6 +2,10 @@ require 'spec_helper'
describe Gitlab::AwardEmoji do describe Gitlab::AwardEmoji do
describe '.urls' do describe '.urls' do
after do
Gitlab::AwardEmoji.instance_variable_set(:@urls, nil)
end
subject { Gitlab::AwardEmoji.urls } subject { Gitlab::AwardEmoji.urls }
it { is_expected.to be_an_instance_of(Array) } it { is_expected.to be_an_instance_of(Array) }
...@@ -15,6 +19,17 @@ describe Gitlab::AwardEmoji do ...@@ -15,6 +19,17 @@ describe Gitlab::AwardEmoji do
end end
end end
end end
context 'handles relative root' do
it 'includes the full path' do
allow(Gitlab::Application.config).to receive(:relative_url_root).and_return('/gitlab')
subject.each do |hash|
expect(hash[:name]).to be_an_instance_of(String)
expect(hash[:path]).to start_with('/gitlab')
end
end
end
end end
describe '.emoji_by_category' do describe '.emoji_by_category' do
......
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