Commit 56f25c3e authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Stan Hu

Improve text indication visibility on snippets

parent e6668f8e
...@@ -24,6 +24,7 @@ v 8.3.0 (unreleased) ...@@ -24,6 +24,7 @@ v 8.3.0 (unreleased)
- Fix bug when simultaneously accepting multiple MRs results in MRs that are of "merged" status, but not merged to the target branch - Fix bug when simultaneously accepting multiple MRs results in MRs that are of "merged" status, but not merged to the target branch
- Add languages page to graphs - Add languages page to graphs
- Block LDAP user when they are no longer found in the LDAP server - Block LDAP user when they are no longer found in the LDAP server
- Improve wording on project visibility levels (Zeger-Jan van de Weg)
v 8.2.3 v 8.2.3
- Fix application settings cache not expiring after changes (Stan Hu) - Fix application settings cache not expiring after changes (Stan Hu)
......
...@@ -12,22 +12,22 @@ module VisibilityLevelHelper ...@@ -12,22 +12,22 @@ module VisibilityLevelHelper
# Return the description for the +level+ argument. # Return the description for the +level+ argument.
# #
# +level+ One of the Gitlab::VisibilityLevel constants # +level+ One of the Gitlab::VisibilityLevel constants
# +form_model+ Either a model object (Project, Snippet, etc.) or the name of # +form_model+ Either a model object (Project, Snippet, etc.) or the name of
# a Project or Snippet class. # a Project or Snippet class.
def visibility_level_description(level, form_model) def visibility_level_description(level, form_model)
case form_model.is_a?(String) ? form_model : form_model.class.name case form_model
when 'PersonalSnippet', 'ProjectSnippet', 'Snippet' when Project
snippet_visibility_level_description(level)
when 'Project'
project_visibility_level_description(level) project_visibility_level_description(level)
when Snippet
snippet_visibility_level_description(level, form_model)
end end
end end
def project_visibility_level_description(level) def project_visibility_level_description(level)
case level case level
when Gitlab::VisibilityLevel::PRIVATE when Gitlab::VisibilityLevel::PRIVATE
"Project access must be granted explicitly for each user." "Project access must be granted explicitly to each user."
when Gitlab::VisibilityLevel::INTERNAL when Gitlab::VisibilityLevel::INTERNAL
"The project can be cloned by any logged in user." "The project can be cloned by any logged in user."
when Gitlab::VisibilityLevel::PUBLIC when Gitlab::VisibilityLevel::PUBLIC
...@@ -35,12 +35,16 @@ module VisibilityLevelHelper ...@@ -35,12 +35,16 @@ module VisibilityLevelHelper
end end
end end
def snippet_visibility_level_description(level) def snippet_visibility_level_description(level, snippet = nil)
case level case level
when Gitlab::VisibilityLevel::PRIVATE when Gitlab::VisibilityLevel::PRIVATE
"The snippet is visible only for me." if snippet.is_a? ProjectSnippet
"The snippet is visible only to project members."
else
"The snippet is visible only to me."
end
when Gitlab::VisibilityLevel::INTERNAL when Gitlab::VisibilityLevel::INTERNAL
"The snippet is visible for any logged in user." "The snippet is visible to any logged in user."
when Gitlab::VisibilityLevel::PUBLIC when Gitlab::VisibilityLevel::PUBLIC
"The snippet can be accessed without any authentication." "The snippet can be accessed without any authentication."
end end
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
.form-group.project-visibility-level-holder .form-group.project-visibility-level-holder
= f.label :default_project_visibility, class: 'control-label col-sm-2' = f.label :default_project_visibility, class: 'control-label col-sm-2'
.col-sm-10 .col-sm-10
= render('shared/visibility_radios', model_method: :default_project_visibility, form: f, selected_level: @application_setting.default_project_visibility, form_model: 'Project') = render('shared/visibility_radios', model_method: :default_project_visibility, form: f, selected_level: @application_setting.default_project_visibility, form_model: Project)
.form-group.project-visibility-level-holder .form-group.project-visibility-level-holder
= f.label :default_snippet_visibility, class: 'control-label col-sm-2' = f.label :default_snippet_visibility, class: 'control-label col-sm-2'
.col-sm-10 .col-sm-10
= render('shared/visibility_radios', model_method: :default_snippet_visibility, form: f, selected_level: @application_setting.default_snippet_visibility, form_model: 'Snippet') = render('shared/visibility_radios', model_method: :default_snippet_visibility, form: f, selected_level: @application_setting.default_snippet_visibility, form_model: PersonalSnippet)
.form-group .form-group
= f.label :restricted_visibility_levels, class: 'control-label col-sm-2' = f.label :restricted_visibility_levels, class: 'control-label col-sm-2'
.col-sm-10 .col-sm-10
......
.issuable-details .issuable-details
.page-title .page-title
.snippet-box.has_tooltip{class: visibility_level_color(@snippet.visibility_level), title: snippet_visibility_level_description(@snippet.visibility_level), data: { container: 'body' }} .snippet-box.has_tooltip{class: visibility_level_color(@snippet.visibility_level), title: snippet_visibility_level_description(@snippet.visibility_level, @snippet), data: { container: 'body' }}
= visibility_level_icon(@snippet.visibility_level, fw: false) = visibility_level_icon(@snippet.visibility_level, fw: false)
= visibility_level_label(@snippet.visibility_level) = visibility_level_label(@snippet.visibility_level)
Snippet ##{@snippet.id} Snippet ##{@snippet.id}
......
...@@ -7,69 +7,52 @@ describe VisibilityLevelHelper do ...@@ -7,69 +7,52 @@ describe VisibilityLevelHelper do
init_haml_helpers init_haml_helpers
end end
let(:project) { create(:project) } let(:project) { build(:project) }
let(:personal_snippet) { build(:personal_snippet) }
let(:project_snippet) { build(:project_snippet) }
describe 'visibility_level_description' do describe 'visibility_level_description' do
shared_examples 'a visibility level description' do context 'used with a Project' do
let(:desc) do it 'delegates projects to #project_visibility_level_description' do
visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, expect(visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, project))
form_model) .to match /project/i
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
end end
context 'form_model argument is a String' do context 'called with a Snippet' do
context 'model object is a personal snippet' do it 'delegates snippets to #snippet_visibility_level_description' do
it_behaves_like 'a visibility level description' do expect(visibility_level_description(Gitlab::VisibilityLevel::INTERNAL, project_snippet))
let(:form_model) { 'PersonalSnippet' } .to match /snippet/i
end
end end
end
end
context 'model object is a project snippet' do describe "#project_visibility_level_description" do
it_behaves_like 'a visibility level description' do it "describes private projects" do
let(:form_model) { 'ProjectSnippet' } expect(project_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE))
end .to eq "Project access must be granted explicitly to each user."
end end
context 'model object is a project' do it "describes public projects" do
it_behaves_like 'a visibility level description' do expect(project_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC))
let(:form_model) { 'Project' } .to eq "The project can be cloned without any authentication."
end
end
end end
end
context 'form_model argument is a model object' do describe "#snippet_visibility_level_description" do
context 'model object is a personal snippet' do it 'describes visibility only for me' do
it_behaves_like 'a visibility level description' do expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, personal_snippet))
let(:form_model) { create(:personal_snippet) } .to eq "The snippet is visible only to me."
end end
end
context 'model object is a project snippet' do it 'describes visibility for project members' do
it_behaves_like 'a visibility level description' do expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, project_snippet))
let(:form_model) { create(:project_snippet, project: project) } .to eq "The snippet is visible only to project members."
end end
end
context 'model object is a project' do it 'defaults to personal snippet' do
it_behaves_like 'a visibility level description' do expect(snippet_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE))
let(:form_model) { project } .to eq "The snippet is visible only to me."
end
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