2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-22 14:49:16 -05:00
|
|
|
class Appearance < ActiveRecord::Base
|
2018-05-04 13:23:50 -04:00
|
|
|
include CacheableAttributes
|
2016-10-06 17:17:11 -04:00
|
|
|
include CacheMarkdownField
|
2018-02-21 11:43:21 -05:00
|
|
|
include ObjectStorage::BackgroundMove
|
2018-05-07 09:49:32 -04:00
|
|
|
include WithUploads
|
2016-10-06 17:17:11 -04:00
|
|
|
|
|
|
|
cache_markdown_field :description
|
2017-11-22 08:48:38 -05:00
|
|
|
cache_markdown_field :new_project_guidelines
|
2018-04-02 10:26:59 -04:00
|
|
|
cache_markdown_field :header_message, pipeline: :broadcast_message
|
|
|
|
cache_markdown_field :footer_message, pipeline: :broadcast_message
|
2016-10-06 17:17:11 -04:00
|
|
|
|
2016-02-22 14:49:16 -05:00
|
|
|
validates :logo, file_size: { maximum: 1.megabyte }
|
|
|
|
validates :header_logo, file_size: { maximum: 1.megabyte }
|
2018-04-02 10:26:59 -04:00
|
|
|
validates :message_background_color, allow_blank: true, color: true
|
|
|
|
validates :message_font_color, allow_blank: true, color: true
|
2016-02-22 14:49:16 -05:00
|
|
|
|
2017-08-09 10:41:51 -04:00
|
|
|
validate :single_appearance_row, on: :create
|
|
|
|
|
2018-04-02 10:26:59 -04:00
|
|
|
default_value_for :message_background_color, '#E75E40'
|
|
|
|
default_value_for :message_font_color, '#FFFFFF'
|
2019-02-20 10:18:15 -05:00
|
|
|
default_value_for :email_header_and_footer_enabled, false
|
2018-04-02 10:26:59 -04:00
|
|
|
|
2016-02-22 14:49:16 -05:00
|
|
|
mount_uploader :logo, AttachmentUploader
|
|
|
|
mount_uploader :header_logo, AttachmentUploader
|
2017-09-26 03:54:32 -04:00
|
|
|
mount_uploader :favicon, FaviconUploader
|
2018-02-02 08:59:43 -05:00
|
|
|
|
2018-05-04 13:23:50 -04:00
|
|
|
# Overrides CacheableAttributes.current_without_cache
|
|
|
|
def self.current_without_cache
|
|
|
|
first
|
2017-08-09 10:41:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def single_appearance_row
|
|
|
|
if self.class.any?
|
|
|
|
errors.add(:single_appearance_row, 'Only 1 appearances row can exist')
|
|
|
|
end
|
|
|
|
end
|
2018-12-25 03:24:00 -05:00
|
|
|
|
|
|
|
def logo_path
|
|
|
|
logo_system_path(logo, 'logo')
|
|
|
|
end
|
|
|
|
|
|
|
|
def header_logo_path
|
|
|
|
logo_system_path(header_logo, 'header_logo')
|
|
|
|
end
|
|
|
|
|
|
|
|
def favicon_path
|
|
|
|
logo_system_path(favicon, 'favicon')
|
|
|
|
end
|
|
|
|
|
2018-04-02 10:26:59 -04:00
|
|
|
def show_header?
|
|
|
|
header_message.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_footer?
|
|
|
|
footer_message.present?
|
|
|
|
end
|
|
|
|
|
2018-12-25 03:24:00 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def logo_system_path(logo, mount_type)
|
2019-01-23 13:28:26 -05:00
|
|
|
# Legacy attachments may not have have an associated Upload record,
|
|
|
|
# so fallback to the AttachmentUploader#url if this is the
|
|
|
|
# case. AttachmentUploader#path doesn't work because for a local
|
|
|
|
# file, this is an absolute path to the file.
|
|
|
|
return logo&.url unless logo&.upload
|
2018-12-25 03:24:00 -05:00
|
|
|
|
|
|
|
# If we're using a CDN, we need to use the full URL
|
|
|
|
asset_host = ActionController::Base.asset_host
|
|
|
|
local_path = Gitlab::Routing.url_helpers.appearance_upload_path(
|
|
|
|
filename: logo.filename,
|
|
|
|
id: logo.upload.model_id,
|
|
|
|
model: 'appearance',
|
|
|
|
mounted_as: mount_type)
|
|
|
|
|
|
|
|
Gitlab::Utils.append_path(asset_host, local_path)
|
|
|
|
end
|
2016-02-22 14:49:16 -05:00
|
|
|
end
|