Commit 817d93e8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'snippet-default-visibility' into 'master'

Add new admin settings

Add new settings to the admin web UI for default project and snippet visibility levels.  See #2027.

### New settings:

![default_visibility_settings](https://dev.gitlab.org/gitlab/gitlabhq/uploads/bd6d296e39ea3c90ca6a5254b8eb1fef/default_visibility_settings.png)

See merge request !1795
parents 439b9f50 bd557e4b
......@@ -16,7 +16,7 @@ v 7.11.0 (unreleased)
- Don't crash when an MR from a fork has a cross-reference comment from the target project on of its commits.
- Include commit comments in MR from a forked project.
-
-
- Add default project and snippet visibility settings to the admin web UI.
- Fix bug where Slack service channel was not saved in admin template settings. (Stan Hu)
- Move snippets UI to fluid layout
- Improve UI for sidebar. Increase separation between navigation and content
......
......@@ -39,6 +39,8 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:sign_in_text,
:home_page_url,
:max_attachment_size,
:default_project_visibility,
:default_snippet_visibility,
restricted_visibility_levels: []
)
end
......
......@@ -10,7 +10,21 @@ module VisibilityLevelHelper
end
end
def visibility_level_description(level)
# Return the description for the +level+ argument.
#
# +level+ One of the Gitlab::VisibilityLevel constants
# +form_model+ Either a model object (Project, Snippet, etc.) or the name of
# a Project or Snippet class.
def visibility_level_description(level, form_model)
case form_model.is_a?(String) ? form_model : form_model.class.name
when 'PersonalSnippet', 'ProjectSnippet', 'Snippet'
snippet_visibility_level_description(level)
when 'Project'
project_visibility_level_description(level)
end
end
def project_visibility_level_description(level)
capture_haml do
haml_tag :span do
case level
......@@ -64,4 +78,12 @@ module VisibilityLevelHelper
return [] if current_user.is_admin? && !show_all
current_application_settings.restricted_visibility_levels || []
end
def default_project_visibility
current_application_settings.default_project_visibility
end
def default_snippet_visibility
current_application_settings.default_snippet_visibility
end
end
......@@ -17,6 +17,8 @@
# twitter_sharing_enabled :boolean default(TRUE)
# restricted_visibility_levels :text
# max_attachment_size :integer default(10)
# default_project_visibility :integer
# default_snippet_visibility :integer
#
class ApplicationSetting < ActiveRecord::Base
......@@ -51,7 +53,9 @@ class ApplicationSetting < ActiveRecord::Base
gravatar_enabled: Settings.gravatar['enabled'],
sign_in_text: Settings.extra['sign_in_text'],
restricted_visibility_levels: Settings.gitlab['restricted_visibility_levels'],
max_attachment_size: Settings.gitlab['max_attachment_size']
max_attachment_size: Settings.gitlab['max_attachment_size'],
default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'],
default_snippet_visibility: Settings.gitlab.default_projects_features['visibility_level']
)
end
......
......@@ -42,6 +42,14 @@
= f.label :default_branch_protection, class: 'control-label col-sm-2'
.col-sm-10
= f.select :default_branch_protection, options_for_select(Gitlab::Access.protection_options, @application_setting.default_branch_protection), {}, class: 'form-control'
.form-group
= f.label :default_project_visibility, class: 'control-label col-sm-2'
.col-sm-10
= render('shared/visibility_radios', model_method: :default_project_visibility, form: f, selected_level: @application_setting.default_project_visibility, form_model: 'Project')
.form-group
= f.label :default_snippet_visibility, class: 'control-label col-sm-2'
.col-sm-10
= render('shared/visibility_radios', model_method: :default_snippet_visibility, form: f, selected_level: @application_setting.default_snippet_visibility, form_model: 'Snippet')
.form-group
= f.label :restricted_visibility_levels, class: 'control-label col-sm-2'
.col-sm-10
......
.form-group.project-visibility-level-holder
= f.label :visibility_level, class: 'control-label' do
Visibility Level
= link_to "(?)", help_page_path("public_access", "public_access")
.col-sm-10
- if can_change_visibility_level
- Gitlab::VisibilityLevel.values.each do |level|
.radio
- restricted = restricted_visibility_levels.include?(level)
= label :project_visibility_level, level do
= f.radio_button :visibility_level, level, checked: (visibility_level == level), disabled: restricted
= visibility_level_icon(level)
.option-title
= visibility_level_label(level)
.option-descr
= visibility_level_description(level)
- unless restricted_visibility_levels.empty?
.col-sm-10
%span.info
Some visibility level settings have been restricted by the administrator.
- else
.col-sm-10
%span.info
= visibility_level_icon(visibility_level)
%strong
= visibility_level_label(visibility_level)
.light= visibility_level_description(visibility_level)
......@@ -29,7 +29,7 @@
.col-sm-10= f.select(:default_branch, @repository.branch_names, {}, {class: 'select2 select-wide'})
= render "visibility_level", f: f, visibility_level: @project.visibility_level, can_change_visibility_level: can?(current_user, :change_visibility_level, @project)
= render 'shared/visibility_level', f: f, visibility_level: @project.visibility_level, can_change_visibility_level: can?(current_user, :change_visibility_level, @project), form_model: @project
.form-group
= f.label :tag_list, "Tags", class: 'control-label'
......
......@@ -93,7 +93,7 @@
%span.light (optional)
.col-sm-10
= f.text_area :description, placeholder: "Awesome project", class: "form-control", rows: 3, maxlength: 250, tabindex: 3
= render "visibility_level", f: f, visibility_level: gitlab_config.default_projects_features.visibility_level, can_change_visibility_level: true
= render 'shared/visibility_level', f: f, visibility_level: default_project_visibility, can_change_visibility_level: true, form_model: @project
.form-actions
= f.submit 'Create project', class: "btn btn-create project-submit", tabindex: 4
......
%h3.page-title
Edit snippet
%hr
= render "shared/snippets/form", url: namespace_project_snippet_path(@project.namespace, @project, @snippet)
= render "shared/snippets/form", url: namespace_project_snippet_path(@project.namespace, @project, @snippet), visibility_level: @snippet.visibility_level
%h3.page-title
New snippet
%hr
= render "shared/snippets/form", url: namespace_project_snippets_path(@project.namespace, @project, @snippet)
= render "shared/snippets/form", url: namespace_project_snippets_path(@project.namespace, @project, @snippet), visibility_level: default_snippet_visibility
......@@ -4,24 +4,11 @@
= link_to "(?)", help_page_path("public_access", "public_access")
.col-sm-10
- if can_change_visibility_level
- Gitlab::VisibilityLevel.values.each do |level|
.radio
- restricted = restricted_visibility_levels.include?(level)
= f.radio_button :visibility_level, level, disabled: restricted
= label "#{dom_class(@snippet)}_visibility_level", level do
= visibility_level_icon(level)
.option-title
= visibility_level_label(level)
.option-descr
= snippet_visibility_level_description(level)
- unless restricted_visibility_levels.empty?
.col-sm-10
%span.info
Some visibility level settings have been restricted by the administrator.
= render('shared/visibility_radios', model_method: :visibility_level, form: f, selected_level: visibility_level, form_model: form_model)
- else
.col-sm-10
%span.info
= visibility_level_icon(visibility_level)
%strong
= visibility_level_label(visibility_level)
.light= visibility_level_description(visibility_level)
.light= visibility_level_description(visibility_level, form_model)
- Gitlab::VisibilityLevel.values.each do |level|
.radio
- restricted = restricted_visibility_levels.include?(level)
= label model_method, level do
= form.radio_button model_method, level, checked: (selected_level == level), disabled: restricted
= visibility_level_icon(level)
.option-title
= visibility_level_label(level)
.option-descr
= visibility_level_description(level, form_model)
- unless restricted_visibility_levels.empty?
.col-sm-10
%span.info
Some visibility level settings have been restricted by the administrator.
......@@ -10,7 +10,7 @@
= f.label :title, class: 'control-label'
.col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true
= render "shared/snippets/visibility_level", f: f, visibility_level: gitlab_config.default_projects_features.visibility_level, can_change_visibility_level: true
= render 'shared/visibility_level', f: f, visibility_level: visibility_level, can_change_visibility_level: true, form_model: @snippet
.form-group
.file-editor
......
%h3.page-title
Edit snippet
%hr
= render "shared/snippets/form", url: snippet_path(@snippet)
= render 'shared/snippets/form', url: snippet_path(@snippet), visibility_level: @snippet.visibility_level
%h3.page-title
New snippet
%hr
= render "shared/snippets/form", url: snippets_path(@snippet)
= render "shared/snippets/form", url: snippets_path(@snippet), visibility_level: default_snippet_visibility
......@@ -76,7 +76,6 @@ production: &base
merge_requests: true
wiki: true
snippets: false
visibility_level: "private" # can be "private" | "internal" | "public"
## Webhook settings
# Number of seconds to wait for HTTP response after sending webhook HTTP POST request (default: 10)
......
class AddDefaultProjectVisibililtyToApplicationSettings < ActiveRecord::Migration
def change
add_column :application_settings, :default_project_visibility, :integer
visibility = Settings.gitlab.default_projects_features['visibility_level']
execute("update application_settings set default_project_visibility = #{visibility}")
end
end
class AddDefaultSnippetVisibilityToAppSettings < ActiveRecord::Migration
def change
add_column :application_settings, :default_snippet_visibility, :integer
visibility = Settings.gitlab.default_projects_features['visibility_level']
execute("update application_settings set default_snippet_visibility = #{visibility}")
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150421120000) do
ActiveRecord::Schema.define(version: 20150425173433) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -29,6 +29,8 @@ ActiveRecord::Schema.define(version: 20150421120000) do
t.boolean "twitter_sharing_enabled", default: true
t.text "restricted_visibility_levels"
t.integer "max_attachment_size", default: 10, null: false
t.integer "default_project_visibility"
t.integer "default_snippet_visibility"
end
create_table "broadcast_messages", force: true do |t|
......@@ -470,6 +472,7 @@ ActiveRecord::Schema.define(version: 20150421120000) do
t.integer "notification_level", default: 1, null: false
t.datetime "password_expires_at"
t.integer "created_by_id"
t.datetime "last_credential_check_at"
t.string "avatar"
t.string "confirmation_token"
t.datetime "confirmed_at"
......@@ -477,7 +480,6 @@ ActiveRecord::Schema.define(version: 20150421120000) do
t.string "unconfirmed_email"
t.boolean "hide_no_ssh_key", default: false
t.string "website_url", default: "", null: false
t.datetime "last_credential_check_at"
t.string "github_access_token"
t.string "gitlab_access_token"
t.string "notification_email"
......
require 'spec_helper'
describe VisibilityLevelHelper do
include Haml::Helpers
before :all do
init_haml_helpers
end
let(:project) { create(:project) }
describe 'visibility_level_description' do
shared_examples 'a visibility level description' do
let(:desc) do
visibility_level_description(Gitlab::VisibilityLevel::PRIVATE,
form_model)
end
let(:expected_class) do
class_name = case form_model.class.name
when 'String'
form_model
else
form_model.class.name
end
class_name.match(/(project|snippet)$/i)[0]
end
it 'should refer to the correct class' do
expect(desc).to match(/#{expected_class}/i)
end
end
context 'form_model argument is a String' do
context 'model object is a personal snippet' do
it_behaves_like 'a visibility level description' do
let(:form_model) { 'PersonalSnippet' }
end
end
context 'model object is a project snippet' do
it_behaves_like 'a visibility level description' do
let(:form_model) { 'ProjectSnippet' }
end
end
context 'model object is a project' do
it_behaves_like 'a visibility level description' do
let(:form_model) { 'Project' }
end
end
end
context 'form_model argument is a model object' do
context 'model object is a personal snippet' do
it_behaves_like 'a visibility level description' do
let(:form_model) { create(:personal_snippet) }
end
end
context 'model object is a project snippet' do
it_behaves_like 'a visibility level description' do
let(:form_model) { create(:project_snippet, project: project) }
end
end
context 'model object is a project' do
it_behaves_like 'a visibility level description' do
let(:form_model) { project }
end
end
end
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