summaryrefslogtreecommitdiff
path: root/lib/gitlab/favicon.rb
blob: e7fe0bff5b83b368a0e1dc4a559f6fa5ca67a844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Gitlab
  class Favicon
    class << self
      def default
        return custom_favicon_url(appearance_favicon.default.url) if appearance_favicon.exists?
        return 'favicon-yellow.ico' if Gitlab::Utils.to_boolean(ENV['CANARY'])
        return 'favicon-blue.ico' if Rails.env.development?

        'favicon.ico'
      end

      def status(status_name)
        if appearance_favicon.exists?
          custom_favicon_url(appearance_favicon.public_send("status_#{status_name}").url) # rubocop:disable GitlabSecurity/PublicSend
        else
          dir = 'ci_favicons'
          dir = File.join(dir, 'dev') if Rails.env.development?
          dir = File.join(dir, 'canary') if Gitlab::Utils.to_boolean(ENV['CANARY'])

          File.join(dir, "favicon_status_#{status_name}.ico")
        end
      end

      private

      def appearance
        Appearance.current || Appearance.new
      end

      def appearance_favicon
        appearance.favicon
      end

      # Without the '?' at the end of the favicon url the custom favicon (i.e.
      # the favicons that are served through `UploadController`) are not shown
      # in the browser.
      def custom_favicon_url(url)
        "#{url}?"
      end
    end
  end
end