summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG2
-rw-r--r--app/controllers/admin/application_settings_controller.rb2
-rw-r--r--app/helpers/visibility_level_helper.rb24
-rw-r--r--app/models/application_setting.rb6
-rw-r--r--app/views/admin/application_settings/_form.html.haml8
-rw-r--r--app/views/projects/_visibility_level.html.haml27
-rw-r--r--app/views/projects/edit.html.haml2
-rw-r--r--app/views/projects/new.html.haml2
-rw-r--r--app/views/projects/snippets/edit.html.haml2
-rw-r--r--app/views/projects/snippets/new.html.haml2
-rw-r--r--app/views/shared/_visibility_level.html.haml14
-rw-r--r--app/views/shared/_visibility_radios.html.haml14
-rw-r--r--app/views/shared/snippets/_form.html.haml2
-rw-r--r--app/views/shared/snippets/_visibility_level.html.haml27
-rw-r--r--app/views/snippets/edit.html.haml2
-rw-r--r--app/views/snippets/new.html.haml2
-rw-r--r--config/gitlab.yml.example1
-rw-r--r--db/migrate/20150423033240_add_default_project_visibililty_to_application_settings.rb7
-rw-r--r--db/migrate/20150425173433_add_default_snippet_visibility_to_app_settings.rb7
-rw-r--r--db/schema.rb6
-rw-r--r--spec/helpers/visibility_level_helper_spec.rb75
21 files changed, 167 insertions, 67 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 92ae6767ea2..5ba56afd0d4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index e9757676908..8f6a766635a 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -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
diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb
index 0d573e72a80..66a1383d61b 100644
--- a/app/helpers/visibility_level_helper.rb
+++ b/app/helpers/visibility_level_helper.rb
@@ -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
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 0d8365c4ff2..9406fb91939 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -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
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
index 4f3565c67eb..98d3e00153d 100644
--- a/app/views/admin/application_settings/_form.html.haml
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -43,6 +43,14 @@
.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
- data_attrs = { toggle: 'buttons' }
diff --git a/app/views/projects/_visibility_level.html.haml b/app/views/projects/_visibility_level.html.haml
deleted file mode 100644
index 42c8e685224..00000000000
--- a/app/views/projects/_visibility_level.html.haml
+++ /dev/null
@@ -1,27 +0,0 @@
-.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)
diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml
index fbf04847e48..c09d794ef7f 100644
--- a/app/views/projects/edit.html.haml
+++ b/app/views/projects/edit.html.haml
@@ -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'
diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml
index a06c85b4251..47c69f89a97 100644
--- a/app/views/projects/new.html.haml
+++ b/app/views/projects/new.html.haml
@@ -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
diff --git a/app/views/projects/snippets/edit.html.haml b/app/views/projects/snippets/edit.html.haml
index 2d4d5d030ab..7baddebde45 100644
--- a/app/views/projects/snippets/edit.html.haml
+++ b/app/views/projects/snippets/edit.html.haml
@@ -1,4 +1,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
diff --git a/app/views/projects/snippets/new.html.haml b/app/views/projects/snippets/new.html.haml
index bb659dba0cf..5efe662665e 100644
--- a/app/views/projects/snippets/new.html.haml
+++ b/app/views/projects/snippets/new.html.haml
@@ -1,4 +1,4 @@
%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
diff --git a/app/views/shared/_visibility_level.html.haml b/app/views/shared/_visibility_level.html.haml
new file mode 100644
index 00000000000..1c6ec198d3d
--- /dev/null
+++ b/app/views/shared/_visibility_level.html.haml
@@ -0,0 +1,14 @@
+.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
+ = 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, form_model)
diff --git a/app/views/shared/_visibility_radios.html.haml b/app/views/shared/_visibility_radios.html.haml
new file mode 100644
index 00000000000..b07c4d20f12
--- /dev/null
+++ b/app/views/shared/_visibility_radios.html.haml
@@ -0,0 +1,14 @@
+- 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.
diff --git a/app/views/shared/snippets/_form.html.haml b/app/views/shared/snippets/_form.html.haml
index 4e0663ea208..6783587bda9 100644
--- a/app/views/shared/snippets/_form.html.haml
+++ b/app/views/shared/snippets/_form.html.haml
@@ -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
diff --git a/app/views/shared/snippets/_visibility_level.html.haml b/app/views/shared/snippets/_visibility_level.html.haml
deleted file mode 100644
index 9acff18e450..00000000000
--- a/app/views/shared/snippets/_visibility_level.html.haml
+++ /dev/null
@@ -1,27 +0,0 @@
-.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)
- = 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.
- - else
- .col-sm-10
- %span.info
- = visibility_level_icon(visibility_level)
- %strong
- = visibility_level_label(visibility_level)
- .light= visibility_level_description(visibility_level)
diff --git a/app/views/snippets/edit.html.haml b/app/views/snippets/edit.html.haml
index 7042d07d5e8..30aa174edfb 100644
--- a/app/views/snippets/edit.html.haml
+++ b/app/views/snippets/edit.html.haml
@@ -1,4 +1,4 @@
%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
diff --git a/app/views/snippets/new.html.haml b/app/views/snippets/new.html.haml
index 694d7058317..77cfd9af335 100644
--- a/app/views/snippets/new.html.haml
+++ b/app/views/snippets/new.html.haml
@@ -1,4 +1,4 @@
%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
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index ba40671b162..93a01c0723f 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -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)
diff --git a/db/migrate/20150423033240_add_default_project_visibililty_to_application_settings.rb b/db/migrate/20150423033240_add_default_project_visibililty_to_application_settings.rb
new file mode 100644
index 00000000000..9b0f13f3fa7
--- /dev/null
+++ b/db/migrate/20150423033240_add_default_project_visibililty_to_application_settings.rb
@@ -0,0 +1,7 @@
+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
diff --git a/db/migrate/20150425173433_add_default_snippet_visibility_to_app_settings.rb b/db/migrate/20150425173433_add_default_snippet_visibility_to_app_settings.rb
new file mode 100644
index 00000000000..51237354d9f
--- /dev/null
+++ b/db/migrate/20150425173433_add_default_snippet_visibility_to_app_settings.rb
@@ -0,0 +1,7 @@
+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
diff --git a/db/schema.rb b/db/schema.rb
index 6db7e386c86..8683c0446fe 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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"
diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb
new file mode 100644
index 00000000000..3840e64981f
--- /dev/null
+++ b/spec/helpers/visibility_level_helper_spec.rb
@@ -0,0 +1,75 @@
+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