summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-09-26 09:54:32 +0200
committerAlexis Reigel <mail@koffeinfrei.org>2018-06-05 16:20:18 +0200
commitce6172e863f982c73fedc9f4a73877543c30cb1c (patch)
treec35bc83d94504d1aa55086d62ff2234d12fe62d4
parentc8a4d202c99c772822a2b9b09fa6da2c90b2ae81 (diff)
downloadgitlab-ce-ce6172e863f982c73fedc9f4a73877543c30cb1c.tar.gz
allow uploading favicon in appearance settings
-rw-r--r--app/controllers/admin/appearances_controller.rb9
-rw-r--r--app/controllers/concerns/uploads_actions.rb2
-rw-r--r--app/models/appearance.rb1
-rw-r--r--app/views/admin/appearances/_form.html.haml17
-rw-r--r--config/routes/admin.rb1
-rw-r--r--config/routes/uploads.rb2
-rw-r--r--db/migrate/20170925184228_add_favicon_to_appearances.rb7
-rw-r--r--db/schema.rb1
8 files changed, 38 insertions, 2 deletions
diff --git a/app/controllers/admin/appearances_controller.rb b/app/controllers/admin/appearances_controller.rb
index ea302f17d16..9aaec905734 100644
--- a/app/controllers/admin/appearances_controller.rb
+++ b/app/controllers/admin/appearances_controller.rb
@@ -41,6 +41,13 @@ class Admin::AppearancesController < Admin::ApplicationController
redirect_to admin_appearances_path, notice: 'Header logo was succesfully removed.'
end
+ def favicon
+ @appearance.remove_favicon!
+ @appearance.save
+
+ redirect_to admin_appearances_path, notice: 'Favicon was succesfully removed.'
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
@@ -61,6 +68,8 @@ class Admin::AppearancesController < Admin::ApplicationController
logo_cache
header_logo
header_logo_cache
+ favicon
+ favicon_cache
new_project_guidelines
updated_by
]
diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb
index b9b9b6e4e88..80049044124 100644
--- a/app/controllers/concerns/uploads_actions.rb
+++ b/app/controllers/concerns/uploads_actions.rb
@@ -2,7 +2,7 @@ module UploadsActions
include Gitlab::Utils::StrongMemoize
include SendFileUpload
- UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo).freeze
+ UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo favicon).freeze
def create
link_to_file = UploadService.new(model, params[:file], uploader_class).execute
diff --git a/app/models/appearance.rb b/app/models/appearance.rb
index 67cc84a9140..b770aadef0e 100644
--- a/app/models/appearance.rb
+++ b/app/models/appearance.rb
@@ -14,6 +14,7 @@ class Appearance < ActiveRecord::Base
mount_uploader :logo, AttachmentUploader
mount_uploader :header_logo, AttachmentUploader
+ mount_uploader :favicon, FaviconUploader
# Overrides CacheableAttributes.current_without_cache
def self.current_without_cache
diff --git a/app/views/admin/appearances/_form.html.haml b/app/views/admin/appearances/_form.html.haml
index 5e08837255f..163ce55eb53 100644
--- a/app/views/admin/appearances/_form.html.haml
+++ b/app/views/admin/appearances/_form.html.haml
@@ -55,6 +55,23 @@
.hint
Guidelines parsed with #{link_to "GitLab Flavored Markdown", help_page_path('user/markdown'), target: '_blank'}.
+ %fieldset.app_logo
+ %legend
+ Favicon:
+ .form-group
+ = f.label :favicon, 'Favicon', class: 'control-label'
+ .col-sm-10
+ - if @appearance.favicon?
+ = image_tag @appearance.favicon.default_without_format_conversion.url, class: 'appearance-light-logo-preview'
+ - if @appearance.persisted?
+ %br
+ = link_to 'Remove favicon', favicon_admin_appearances_path, data: { confirm: "Favicon will be removed. Are you sure?"}, method: :delete, class: "btn btn-remove btn-sm remove-logo"
+ %hr
+ = f.hidden_field :favicon_cache
+ = f.file_field :favicon, class: ''
+ .hint
+ Maximum file size is 1MB. The resulting favicons will be cropped to be square and scaled down to a size of 32x32 px.
+
.form-actions
= f.submit 'Save', class: 'btn btn-save append-right-10'
- if @appearance.persisted?
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index 3cca1210e39..ff27ceb50dc 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -102,6 +102,7 @@ namespace :admin do
get :preview_sign_in
delete :logo
delete :header_logos
+ delete :favicon
end
end
diff --git a/config/routes/uploads.rb b/config/routes/uploads.rb
index 6370645bcb9..6becadd57ae 100644
--- a/config/routes/uploads.rb
+++ b/config/routes/uploads.rb
@@ -17,7 +17,7 @@ scope path: :uploads do
# Appearance
get "-/system/:model/:mounted_as/:id/:filename",
to: "uploads#show",
- constraints: { model: /appearance/, mounted_as: /logo|header_logo/, filename: /.+/ }
+ constraints: { model: /appearance/, mounted_as: /logo|header_logo|favicon/, filename: /.+/ }
# Project markdown uploads
get ":namespace_id/:project_id/:secret/:filename",
diff --git a/db/migrate/20170925184228_add_favicon_to_appearances.rb b/db/migrate/20170925184228_add_favicon_to_appearances.rb
new file mode 100644
index 00000000000..65083733afb
--- /dev/null
+++ b/db/migrate/20170925184228_add_favicon_to_appearances.rb
@@ -0,0 +1,7 @@
+class AddFaviconToAppearances < ActiveRecord::Migration
+ DOWNTIME = false
+
+ def change
+ add_column :appearances, :favicon, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a6b0706b02a..89c8acba3e6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -38,6 +38,7 @@ ActiveRecord::Schema.define(version: 20180529152628) do
t.integer "cached_markdown_version"
t.text "new_project_guidelines"
t.text "new_project_guidelines_html"
+ t.string "favicon"
end
create_table "application_setting_terms", force: :cascade do |t|