diff options
author | Fatih Acet <acetfatih@gmail.com> | 2016-09-07 20:41:33 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-09-07 20:41:33 +0000 |
commit | 5dab043f2d5907958985482ef562420db0ddea5f (patch) | |
tree | 3401690ba06ac332f183d15e7d109828fb109225 | |
parent | 13a91b560e74b457eab20fe2c48e0af5afcf41b3 (diff) | |
parent | dfa286c1818eea9f05d3a76f99b6b2dd7b66e1d7 (diff) | |
download | gitlab-ce-5dab043f2d5907958985482ef562420db0ddea5f.tar.gz |
Merge branch 'issue_21821' into 'master'
Fix project settings field
fixes #21821
See merge request !6185
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 24 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 44 |
3 files changed, 58 insertions, 11 deletions
diff --git a/CHANGELOG b/CHANGELOG index 93bcecbb86e..e7db71b0849 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ v 8.12.0 (unreleased) - Rename behaviour to behavior in bug issue template for consistency (ClemMakesApps) - Remove suggested colors hover underline (ClemMakesApps) - Shorten task status phrase (ClemMakesApps) + - Fix project visibility level fields on settings - Add hover color to emoji icon (ClemMakesApps) - Add textarea autoresize after comment (ClemMakesApps) - Fix branches page dropdown sort alignment (ClemMakesApps) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 4c685b97c03..16a8e52a4ca 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -129,6 +129,19 @@ module ProjectsHelper current_user.recent_push(project_ids) end + def project_feature_access_select(field) + # Don't show option "everyone with access" if project is private + options = project_feature_options + + if @project.private? + options.delete('Everyone with access') + highest_available_option = options.values.max if @project.project_feature.send(field) == ProjectFeature::ENABLED + end + + options = options_for_select(options, selected: highest_available_option || @project.project_feature.public_send(field)) + content_tag(:select, options, name: "project[project_feature_attributes][#{field.to_s}]", id: "project_project_feature_attributes_#{field.to_s}", class: "pull-right form-control", data: { field: field }).html_safe + end + private def get_project_nav_tabs(project, current_user) @@ -422,15 +435,4 @@ module ProjectsHelper 'Everyone with access' => ProjectFeature::ENABLED } end - - def project_feature_access_select(field) - # Don't show option "everyone with access" if project is private - options = project_feature_options - level = @project.project_feature.public_send(field) - - options.delete('Everyone with access') if @project.private? && level != ProjectFeature::ENABLED - - options = options_for_select(options, selected: @project.project_feature.public_send(field) || ProjectFeature::ENABLED) - content_tag(:select, options, name: "project[project_feature_attributes][#{field.to_s}]", id: "project_project_feature_attributes_#{field.to_s}", class: "pull-right form-control", data: { field: field }).html_safe - end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 284b58d8d5c..70032e7df94 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -174,4 +174,48 @@ describe ProjectsHelper do end end end + + describe "#project_feature_access_select" do + let(:project) { create(:empty_project, :public) } + let(:user) { create(:user) } + + context "when project is internal or public" do + it "shows all options" do + helper.instance_variable_set(:@project, project) + result = helper.project_feature_access_select(:issues_access_level) + expect(result).to include("Disabled") + expect(result).to include("Only team members") + expect(result).to include("Everyone with access") + end + end + + context "when project is private" do + before { project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE) } + + it "shows only allowed options" do + helper.instance_variable_set(:@project, project) + result = helper.project_feature_access_select(:issues_access_level) + expect(result).to include("Disabled") + expect(result).to include("Only team members") + expect(result).not_to include("Everyone with access") + end + end + + context "when project moves from public to private" do + before do + project.project_feature.update_attributes(issues_access_level: ProjectFeature::ENABLED) + project.update_attributes(visibility_level: Gitlab::VisibilityLevel::PRIVATE) + end + + it "shows the highest allowed level selected" do + helper.instance_variable_set(:@project, project) + result = helper.project_feature_access_select(:issues_access_level) + + expect(result).to include("Disabled") + expect(result).to include("Only team members") + expect(result).not_to include("Everyone with access") + expect(result).to have_selector('option[selected]', text: "Only team members") + end + end + end end |