Commit b2026f2c authored by Markus Koller's avatar Markus Koller Committed by Rémy Coutable

[EE] Add custom brand text on new project pages

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 091d1f97
...@@ -4,8 +4,8 @@ class Admin::AppearancesController < Admin::ApplicationController ...@@ -4,8 +4,8 @@ class Admin::AppearancesController < Admin::ApplicationController
def show def show
end end
def preview def preview_sign_in
render 'preview', layout: 'devise' render 'preview_sign_in', layout: 'devise'
end end
def create def create
...@@ -52,7 +52,7 @@ class Admin::AppearancesController < Admin::ApplicationController ...@@ -52,7 +52,7 @@ class Admin::AppearancesController < Admin::ApplicationController
def appearance_params def appearance_params
params.require(:appearance).permit( params.require(:appearance).permit(
:title, :description, :logo, :logo_cache, :header_logo, :header_logo_cache, :title, :description, :logo, :logo_cache, :header_logo, :header_logo_cache,
:updated_by :new_project_guidelines, :updated_by
) )
end end
end end
module AppearancesHelper module AppearancesHelper
def brand_title def brand_title
if brand_item && brand_item.title brand_item&.title.presence || 'GitLab Enterprise Edition'
brand_item.title
else
'GitLab Enterprise Edition'
end
end end
def brand_image def brand_image
if brand_item.logo? image_tag(brand_item.logo) if brand_item&.logo?
image_tag brand_item.logo
else
nil
end
end end
def brand_text def brand_text
markdown_field(brand_item, :description) markdown_field(brand_item, :description)
end end
def brand_new_project_guidelines
markdown_field(brand_item, :new_project_guidelines)
end
def brand_item def brand_item
@appearance ||= Appearance.current @appearance ||= Appearance.current
end end
def brand_header_logo def brand_header_logo
if brand_item && brand_item.header_logo? if brand_item&.header_logo?
image_tag brand_item.header_logo image_tag brand_item.header_logo
else else
render 'shared/logo.svg' render 'shared/logo.svg'
...@@ -33,7 +29,7 @@ module AppearancesHelper ...@@ -33,7 +29,7 @@ module AppearancesHelper
# Skip the 'GitLab' type logo when custom brand logo is set # Skip the 'GitLab' type logo when custom brand logo is set
def brand_header_logo_type def brand_header_logo_type
unless brand_item && brand_item.header_logo? unless brand_item&.header_logo?
render 'shared/logo_type.svg' render 'shared/logo_type.svg'
end end
end end
......
...@@ -2,9 +2,8 @@ class Appearance < ActiveRecord::Base ...@@ -2,9 +2,8 @@ class Appearance < ActiveRecord::Base
include CacheMarkdownField include CacheMarkdownField
cache_markdown_field :description cache_markdown_field :description
cache_markdown_field :new_project_guidelines
validates :title, presence: true
validates :description, presence: true
validates :logo, file_size: { maximum: 1.megabyte } validates :logo, file_size: { maximum: 1.megabyte }
validates :header_logo, file_size: { maximum: 1.megabyte } validates :header_logo, file_size: { maximum: 1.megabyte }
......
= form_for @appearance, url: admin_appearances_path, html: { class: 'form-horizontal'} do |f| = form_for @appearance, url: admin_appearances_path, html: { class: 'form-horizontal'} do |f|
= form_errors(@appearance) = form_errors(@appearance)
%fieldset.app_logo
%legend
Navigation bar:
.form-group
= f.label :header_logo, 'Header logo', class: 'control-label'
.col-sm-10
- if @appearance.header_logo?
= image_tag @appearance.header_logo_url, class: 'appearance-light-logo-preview'
- if @appearance.persisted?
%br
= link_to 'Remove header logo', header_logos_admin_appearances_path, data: { confirm: "Header logo will be removed. Are you sure?"}, method: :delete, class: "btn btn-remove btn-sm remove-logo"
%hr
= f.hidden_field :header_logo_cache
= f.file_field :header_logo, class: ""
.hint
Maximum file size is 1MB. Pages are optimized for a 28px tall header logo
%fieldset.sign-in %fieldset.sign-in
%legend %legend
Sign in/Sign up pages: Sign in/Sign up pages:
...@@ -28,27 +45,22 @@ ...@@ -28,27 +45,22 @@
.hint .hint
Maximum file size is 1MB. Pages are optimized for a 640x360 px logo. Maximum file size is 1MB. Pages are optimized for a 640x360 px logo.
%fieldset.app_logo %fieldset
%legend %legend
Navigation bar: New project pages:
.form-group .form-group
= f.label :header_logo, 'Header logo', class: 'control-label' = f.label :new_project_guidelines, class: 'control-label'
.col-sm-10 .col-sm-10
- if @appearance.header_logo? = f.text_area :new_project_guidelines, class: "form-control", rows: 10
= image_tag @appearance.header_logo_url, class: 'appearance-light-logo-preview'
- if @appearance.persisted?
%br
= link_to 'Remove header logo', header_logos_admin_appearances_path, data: { confirm: "Header logo will be removed. Are you sure?"}, method: :delete, class: "btn btn-remove btn-sm remove-logo"
%hr
= f.hidden_field :header_logo_cache
= f.file_field :header_logo, class: ""
.hint .hint
Maximum file size is 1MB. Pages are optimized for a 28px tall header logo Guidelines parsed with #{link_to "GitLab Flavored Markdown", help_page_path('user/markdown'), target: '_blank'}.
.form-actions .form-actions
= f.submit 'Save', class: 'btn btn-save append-right-10' = f.submit 'Save', class: 'btn btn-save append-right-10'
- if @appearance.persisted? - if @appearance.persisted?
= link_to 'Preview last save', preview_admin_appearances_path, class: 'btn', target: '_blank', rel: 'noopener noreferrer' Preview last save:
= link_to 'Sign-in page', preview_sign_in_admin_appearances_path, class: 'btn', target: '_blank', rel: 'noopener noreferrer'
= link_to 'New project page', new_project_path, class: 'btn', target: '_blank', rel: 'noopener noreferrer'
- if @appearance.updated_at - if @appearance.updated_at
%span.pull-right %span.pull-right
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
.col-sm-7.brand-holder.pull-left .col-sm-7.brand-holder.pull-left
%h1 %h1
= brand_title = brand_title
- if brand_item
= brand_image = brand_image
- if brand_item&.description?
= brand_text = brand_text
- else - else
%h3 Open source software to collaborate on code %h3 Open source software to collaborate on code
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
A project is where you house your files (repository), plan your work (issues), and publish your documentation (wiki), #{link_to 'among other things', help_page_path("user/project/index.md", anchor: "projects-features"), target: '_blank'}. A project is where you house your files (repository), plan your work (issues), and publish your documentation (wiki), #{link_to 'among other things', help_page_path("user/project/index.md", anchor: "projects-features"), target: '_blank'}.
%p %p
All features are enabled when you create a project, but you can disable the ones you don’t need in the project settings. All features are enabled when you create a project, but you can disable the ones you don’t need in the project settings.
= brand_new_project_guidelines
.col-lg-9.js-toggle-container .col-lg-9.js-toggle-container
%ul.nav-links.gitlab-tabs{ role: 'tablist' } %ul.nav-links.gitlab-tabs{ role: 'tablist' }
%li.active{ role: 'presentation' } %li.active{ role: 'presentation' }
......
---
title: Add custom brand text on new project pages
merge_request: 15541
author: Markus Koller
type: changed
...@@ -107,7 +107,7 @@ namespace :admin do ...@@ -107,7 +107,7 @@ namespace :admin do
resource :appearances, only: [:show, :create, :update], path: 'appearance' do resource :appearances, only: [:show, :create, :update], path: 'appearance' do
member do member do
get :preview get :preview_sign_in
delete :logo delete :logo
delete :header_logos delete :header_logos
end end
......
class AddNewProjectGuidelinesToAppearances < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
change_table :appearances do |t|
t.text :new_project_guidelines
t.text :new_project_guidelines_html
end
end
end
...@@ -37,6 +37,8 @@ ActiveRecord::Schema.define(version: 20171124165823) do ...@@ -37,6 +37,8 @@ ActiveRecord::Schema.define(version: 20171124165823) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.text "description_html" t.text "description_html"
t.integer "cached_markdown_version" t.integer "cached_markdown_version"
t.text "new_project_guidelines"
t.text "new_project_guidelines_html"
end end
create_table "application_settings", force: :cascade do |t| create_table "application_settings", force: :cascade do |t|
......
...@@ -221,6 +221,7 @@ have access to GitLab administration tools and settings. ...@@ -221,6 +221,7 @@ have access to GitLab administration tools and settings.
- [Issue closing pattern](administration/issue_closing_pattern.md): Customize how to close an issue from commit messages. - [Issue closing pattern](administration/issue_closing_pattern.md): Customize how to close an issue from commit messages.
- [Libravatar](customization/libravatar.md): Use Libravatar instead of Gravatar for user avatars. - [Libravatar](customization/libravatar.md): Use Libravatar instead of Gravatar for user avatars.
- [Welcome message](customization/welcome_message.md): Add a custom welcome message to the sign-in page. - [Welcome message](customization/welcome_message.md): Add a custom welcome message to the sign-in page.
- [New project page](customization/new_project_page.md): Customize the new project page.
### Admin tools ### Admin tools
......
# Customizing the new project page
It is possible to add a markdown-formatted message to your GitLab
new project page.
By default, the new project page shows a sidebar with general information:
![](new_project_page/default_new_project_page.png)
## Changing the appearance of the new project page
Navigate to the **Admin** area and go to the **Appearance** page.
Fill in your project guidelines:
![](new_project_page/appearance_settings.png)
After saving the page, your new project page will show the guidelines in the sidebar, below the general information:
![](new_project_page/custom_new_project_page.png)
...@@ -4,5 +4,6 @@ FactoryGirl.define do ...@@ -4,5 +4,6 @@ FactoryGirl.define do
factory :appearance do factory :appearance do
title "GitLab Enterprise Edition" title "GitLab Enterprise Edition"
description "Open source software to collaborate on code" description "Open source software to collaborate on code"
new_project_guidelines "Custom project guidelines"
end end
end end
...@@ -9,6 +9,7 @@ feature 'Admin Appearance' do ...@@ -9,6 +9,7 @@ feature 'Admin Appearance' do
fill_in 'appearance_title', with: 'MyCompany' fill_in 'appearance_title', with: 'MyCompany'
fill_in 'appearance_description', with: 'dev server' fill_in 'appearance_description', with: 'dev server'
fill_in 'appearance_new_project_guidelines', with: 'Custom project guidelines'
click_button 'Save' click_button 'Save'
expect(current_path).to eq admin_appearances_path expect(current_path).to eq admin_appearances_path
...@@ -16,21 +17,39 @@ feature 'Admin Appearance' do ...@@ -16,21 +17,39 @@ feature 'Admin Appearance' do
expect(page).to have_field('appearance_title', with: 'MyCompany') 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_description', with: 'dev server')
expect(page).to have_field('appearance_new_project_guidelines', with: 'Custom project guidelines')
expect(page).to have_content 'Last edit' expect(page).to have_content 'Last edit'
end end
scenario 'Preview appearance' do scenario 'Preview sign-in page appearance' do
sign_in(create(:admin)) sign_in(create(:admin))
visit admin_appearances_path visit admin_appearances_path
click_link "Preview" click_link "Sign-in page"
expect_page_has_custom_appearance(appearance) expect_custom_sign_in_appearance(appearance)
end
scenario 'Preview new project page appearance' do
sign_in(create(:admin))
visit admin_appearances_path
click_link "New project page"
expect_custom_new_project_appearance(appearance)
end end
scenario 'Custom sign-in page' do scenario 'Custom sign-in page' do
visit new_user_session_path visit new_user_session_path
expect_page_has_custom_appearance(appearance)
expect_custom_sign_in_appearance(appearance)
end
scenario 'Custom new project page' do
sign_in create(:user)
visit new_project_path
expect_custom_new_project_appearance(appearance)
end end
scenario 'Appearance logo' do scenario 'Appearance logo' do
...@@ -57,11 +76,15 @@ feature 'Admin Appearance' do ...@@ -57,11 +76,15 @@ feature 'Admin Appearance' do
expect(page).not_to have_css(header_logo_selector) expect(page).not_to have_css(header_logo_selector)
end end
def expect_page_has_custom_appearance(appearance) def expect_custom_sign_in_appearance(appearance)
expect(page).to have_content appearance.title expect(page).to have_content appearance.title
expect(page).to have_content appearance.description expect(page).to have_content appearance.description
end end
def expect_custom_new_project_appearance(appearance)
expect(page).to have_content appearance.new_project_guidelines
end
def logo_selector def logo_selector
'//img[data-src^="/uploads/-/system/appearance/logo"]' '//img[data-src^="/uploads/-/system/appearance/logo"]'
end end
......
...@@ -5,9 +5,6 @@ describe Appearance do ...@@ -5,9 +5,6 @@ describe Appearance do
it { is_expected.to be_valid } it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to have_many(:uploads).dependent(:destroy) } it { is_expected.to have_many(:uploads).dependent(:destroy) }
describe '.current', :use_clean_rails_memory_store_caching do describe '.current', :use_clean_rails_memory_store_caching do
......
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