2018-07-25 09:30:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 13:17:42 +00:00
|
|
|
class Appearance < ApplicationRecord
|
2018-05-04 17:23:50 +00:00
|
|
|
include CacheableAttributes
|
2016-10-06 21:17:11 +00:00
|
|
|
include CacheMarkdownField
|
2018-02-21 16:43:21 +00:00
|
|
|
include ObjectStorage::BackgroundMove
|
2018-05-07 13:49:32 +00:00
|
|
|
include WithUploads
|
2016-10-06 21:17:11 +00:00
|
|
|
|
|
|
|
cache_markdown_field :description
|
2017-11-22 13:48:38 +00:00
|
|
|
cache_markdown_field :new_project_guidelines
|
2018-04-02 14:26:59 +00:00
|
|
|
cache_markdown_field :header_message, pipeline: :broadcast_message
|
|
|
|
cache_markdown_field :footer_message, pipeline: :broadcast_message
|
2016-10-06 21:17:11 +00:00
|
|
|
|
2016-02-22 19:49:16 +00:00
|
|
|
validates :logo, file_size: { maximum: 1.megabyte }
|
|
|
|
validates :header_logo, file_size: { maximum: 1.megabyte }
|
2018-04-02 14:26:59 +00:00
|
|
|
validates :message_background_color, allow_blank: true, color: true
|
|
|
|
validates :message_font_color, allow_blank: true, color: true
|
2016-02-22 19:49:16 +00:00
|
|
|
|
2017-08-09 14:41:51 +00:00
|
|
|
validate :single_appearance_row, on: :create
|
|
|
|
|
2020-01-09 06:07:57 +00:00
|
|
|
default_value_for :title, ''
|
|
|
|
default_value_for :description, ''
|
|
|
|
default_value_for :new_project_guidelines, ''
|
|
|
|
default_value_for :header_message, ''
|
|
|
|
default_value_for :footer_message, ''
|
2018-04-02 14:26:59 +00:00
|
|
|
default_value_for :message_background_color, '#E75E40'
|
|
|
|
default_value_for :message_font_color, '#FFFFFF'
|
2019-02-20 15:18:15 +00:00
|
|
|
default_value_for :email_header_and_footer_enabled, false
|
2018-04-02 14:26:59 +00:00
|
|
|
|
2016-02-22 19:49:16 +00:00
|
|
|
mount_uploader :logo, AttachmentUploader
|
|
|
|
mount_uploader :header_logo, AttachmentUploader
|
2017-09-26 07:54:32 +00:00
|
|
|
mount_uploader :favicon, FaviconUploader
|
2018-02-02 13:59:43 +00:00
|
|
|
|
2018-05-04 17:23:50 +00:00
|
|
|
# Overrides CacheableAttributes.current_without_cache
|
|
|
|
def self.current_without_cache
|
|
|
|
first
|
2017-08-09 14:41:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def single_appearance_row
|
|
|
|
if self.class.any?
|
2020-03-03 09:07:54 +00:00
|
|
|
errors.add(:base, _('Only 1 appearances row can exist'))
|
2017-08-09 14:41:51 +00:00
|
|
|
end
|
|
|
|
end
|
2018-12-25 08:24:00 +00: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 14:26:59 +00:00
|
|
|
def show_header?
|
|
|
|
header_message.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_footer?
|
|
|
|
footer_message.present?
|
|
|
|
end
|
|
|
|
|
2018-12-25 08:24:00 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def logo_system_path(logo, mount_type)
|
2019-01-23 18:28:26 +00: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 08:24:00 +00: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 19:49:16 +00:00
|
|
|
end
|