Commit f54f9cb5 authored by Roger Meier's avatar Roger Meier

Add option to add custom profile image guidelines

parent 8b279be5
......@@ -73,6 +73,7 @@ class Admin::AppearancesController < Admin::ApplicationController
favicon
favicon_cache
new_project_guidelines
profile_image_guidelines
updated_by
header_message
footer_message
......
......@@ -25,6 +25,10 @@ module AppearancesHelper
markdown_field(current_appearance, :new_project_guidelines)
end
def brand_profile_image_guidelines
markdown_field(current_appearance, :profile_image_guidelines)
end
def current_appearance
strong_memoize(:current_appearance) do
Appearance.current
......
......@@ -8,6 +8,7 @@ class Appearance < ApplicationRecord
cache_markdown_field :description
cache_markdown_field :new_project_guidelines
cache_markdown_field :profile_image_guidelines
cache_markdown_field :header_message, pipeline: :broadcast_message
cache_markdown_field :footer_message, pipeline: :broadcast_message
......@@ -15,12 +16,14 @@ class Appearance < ApplicationRecord
validates :header_logo, file_size: { maximum: 1.megabyte }
validates :message_background_color, allow_blank: true, color: true
validates :message_font_color, allow_blank: true, color: true
validates :profile_image_guidelines, length: { maximum: 4096 }
validate :single_appearance_row, on: :create
default_value_for :title, ''
default_value_for :description, ''
default_value_for :new_project_guidelines, ''
default_value_for :profile_image_guidelines, ''
default_value_for :header_message, ''
default_value_for :footer_message, ''
default_value_for :message_background_color, '#E75E40'
......
- parsed_with_gfm = "Content parsed with #{link_to('GitLab Flavored Markdown', help_page_path('user/markdown'), target: '_blank')}.".html_safe
= form_for @appearance, url: admin_appearances_path, html: { class: 'prepend-top-default' } do |f|
= form_errors(@appearance)
......@@ -57,7 +59,7 @@
= f.label :description, class: 'col-form-label label-bold'
= f.text_area :description, class: "form-control", rows: 10
.hint
Description parsed with #{link_to "GitLab Flavored Markdown", help_page_path('user/markdown'), target: '_blank'}.
= parsed_with_gfm
.form-group
= f.label :logo, class: 'col-form-label label-bold pt-0'
%p
......@@ -83,10 +85,25 @@
%p
= f.text_area :new_project_guidelines, class: "form-control", rows: 10
.hint
Guidelines parsed with #{link_to "GitLab Flavored Markdown", help_page_path('user/markdown'), target: '_blank'}.
= parsed_with_gfm
%hr
.row
.col-lg-4.profile-settings-sidebar
%h4.prepend-top-0 Profile image guideline
.col-lg-8
.form-group
= f.label :profile_image_guidelines, class: 'col-form-label label-bold'
%p
= f.text_area :profile_image_guidelines, class: "form-control", rows: 10
.hint
= parsed_with_gfm
.prepend-top-default.append-bottom-default
= f.submit 'Update appearance settings', class: 'btn btn-success'
- if @appearance.persisted? || @appearance.updated_at
.mt-4
- if @appearance.persisted?
Preview last save:
= link_to 'Sign-in page', preview_sign_in_admin_appearances_path, class: 'btn', target: '_blank', rel: 'noopener noreferrer'
......
......@@ -20,6 +20,9 @@
= s_("Profiles|You can upload your avatar here or change it at %{gravatar_link}").html_safe % { gravatar_link: gravatar_link }
- else
= s_("Profiles|You can upload your avatar here")
- if current_appearance&.profile_image_guidelines?
.md
= brand_profile_image_guidelines
.col-lg-8
.clearfix.avatar-image.append-bottom-default
= link_to avatar_icon_for_user(@user, 400), target: '_blank', rel: 'noopener noreferrer' do
......
---
title: Add option to add custom profile image guidelines
merge_request: 29894
author: Roger Meier
type: added
# frozen_string_literal: true
class AddProfileImageGuidelinesToAppearances < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column :appearances, :profile_image_guidelines, :text, null: true
add_column :appearances, :profile_image_guidelines_html, :text, null: true # rubocop:disable Migration/AddLimitToTextColumns
add_text_limit :appearances, :profile_image_guidelines, 4096, constraint_name: 'appearances_profile_image_guidelines'
end
def down
remove_column :appearances, :profile_image_guidelines
remove_column :appearances, :profile_image_guidelines_html
end
end
......@@ -171,7 +171,10 @@ CREATE TABLE public.appearances (
message_background_color text,
message_font_color text,
favicon character varying,
email_header_and_footer_enabled boolean DEFAULT false NOT NULL
email_header_and_footer_enabled boolean DEFAULT false NOT NULL,
profile_image_guidelines text,
profile_image_guidelines_html text,
CONSTRAINT appearances_profile_image_guidelines CHECK ((char_length(profile_image_guidelines) <= 4096))
);
CREATE SEQUENCE public.appearances_id_seq
......@@ -13511,6 +13514,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200416120354
20200417044453
20200417145946
20200420092011
20200420104303
20200420104323
20200420162730
......
......@@ -27,6 +27,7 @@ Example response:
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png",
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png",
"new_project_guidelines": "Please read the FAQs for help.",
"profile_image_guidelines": "Custom profile image guidelines",
"header_message": "",
"footer_message": "",
"message_background_color": "#e75e40",
......@@ -51,6 +52,7 @@ PUT /application/appearance
| `header_logo` | mixed | no | Instance image used for the main navigation bar
| `favicon` | mixed | no | Instance favicon in .ico/.png format
| `new_project_guidelines` | string | no | Markdown text shown on the new project page
| `profile_image_guidelines` | string | no | Markdown text shown on the profile page below Public Avatar
| `header_message` | string | no | Message within the system header bar
| `footer_message` | string | no | Message within the system footer bar
| `message_background_color` | string | no | Background color for the system header / footer bar
......@@ -71,6 +73,7 @@ Example response:
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png",
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png",
"new_project_guidelines": "Please read the FAQs for help.",
"profile_image_guidelines": "Custom profile image guidelines",
"header_message": "test",
"footer_message": "",
"message_background_color": "#e75e40",
......
......@@ -27,7 +27,8 @@ module API
optional :logo, type: File, desc: 'Instance image used on the sign in / sign up page' # rubocop:disable Scalability/FileUploads
optional :header_logo, type: File, desc: 'Instance image used for the main navigation bar' # rubocop:disable Scalability/FileUploads
optional :favicon, type: File, desc: 'Instance favicon in .ico/.png format' # rubocop:disable Scalability/FileUploads
optional :new_project_guidelines, type: String, desc: 'Markmarkdown text shown on the new project page'
optional :new_project_guidelines, type: String, desc: 'Markdown text shown on the new project page'
optional :profile_image_guidelines, type: String, desc: 'Markdown text shown on the profile page below Public Avatar'
optional :header_message, type: String, desc: 'Message within the system header bar'
optional :footer_message, type: String, desc: 'Message within the system footer bar'
optional :message_background_color, type: String, desc: 'Background color for the system header / footer bar'
......
......@@ -19,6 +19,7 @@ module API
end
expose :new_project_guidelines
expose :profile_image_guidelines
expose :header_message
expose :footer_message
expose :message_background_color
......
......@@ -7,6 +7,7 @@ FactoryBot.define do
title { "GitLab Community Edition" }
description { "Open source software to collaborate on code" }
new_project_guidelines { "Custom project guidelines" }
profile_image_guidelines { "Custom profile image guidelines" }
end
trait :with_logo do
......
......@@ -12,6 +12,7 @@ describe 'Admin Appearance' do
fill_in 'appearance_title', with: 'MyCompany'
fill_in 'appearance_description', with: 'dev server'
fill_in 'appearance_new_project_guidelines', with: 'Custom project guidelines'
fill_in 'appearance_profile_image_guidelines', with: 'Custom profile image guidelines'
click_button 'Update appearance settings'
expect(current_path).to eq admin_appearances_path
......@@ -20,6 +21,7 @@ describe 'Admin Appearance' do
expect(page).to have_field('appearance_title', with: 'MyCompany')
expect(page).to have_field('appearance_description', with: 'dev server')
expect(page).to have_field('appearance_new_project_guidelines', with: 'Custom project guidelines')
expect(page).to have_field('appearance_profile_image_guidelines', with: 'Custom profile image guidelines')
expect(page).to have_content 'Last edit'
end
......@@ -86,6 +88,22 @@ describe 'Admin Appearance' do
expect_custom_new_project_appearance(appearance)
end
context 'Profile page with custom profile image guidelines' do
before do
sign_in(create(:admin))
visit admin_appearances_path
fill_in 'appearance_profile_image_guidelines', with: 'Custom profile image guidelines, please :smile:!'
click_button 'Update appearance settings'
end
it 'renders guidelines when set' do
sign_in create(:user)
visit profile_path
expect(page).to have_content 'Custom profile image guidelines, please 😄!'
end
end
it 'Appearance logo' do
sign_in(create(:admin))
visit admin_appearances_path
......
......@@ -31,6 +31,7 @@ describe API::Appearance, 'Appearance' do
expect(json_response['message_background_color']).to eq('#E75E40')
expect(json_response['message_font_color']).to eq('#FFFFFF')
expect(json_response['new_project_guidelines']).to eq('')
expect(json_response['profile_image_guidelines']).to eq('')
expect(json_response['title']).to eq('')
end
end
......@@ -51,7 +52,8 @@ describe API::Appearance, 'Appearance' do
put api("/application/appearance", admin), params: {
title: "GitLab Test Instance",
description: "gitlab-test.example.com",
new_project_guidelines: "Please read the FAQs for help."
new_project_guidelines: "Please read the FAQs for help.",
profile_image_guidelines: "Custom profile image guidelines"
}
expect(response).to have_gitlab_http_status(:ok)
......@@ -66,6 +68,7 @@ describe API::Appearance, 'Appearance' do
expect(json_response['message_background_color']).to eq('#E75E40')
expect(json_response['message_font_color']).to eq('#FFFFFF')
expect(json_response['new_project_guidelines']).to eq('Please read the FAQs for help.')
expect(json_response['profile_image_guidelines']).to eq('Custom profile image guidelines')
expect(json_response['title']).to eq('GitLab Test Instance')
end
end
......
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