debian-mirror-gitlab/spec/features/projects/features_visibility_spec.rb

291 lines
9.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe 'Edit Project Settings' do
2016-09-29 09:46:39 +05:30
let(:member) { create(:user) }
2017-09-10 17:25:29 +05:30
let!(:project) { create(:project, :public, :repository) }
2016-11-03 12:29:30 +05:30
let!(:issue) { create(:issue, project: project) }
2016-09-29 09:46:39 +05:30
let(:non_member) { create(:user) }
2018-03-17 18:26:18 +05:30
describe 'project features visibility selectors', :js do
2016-09-29 09:46:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(member)
2017-09-10 17:25:29 +05:30
sign_in(member)
2016-09-29 09:46:39 +05:30
end
tools = { builds: "pipelines", issues: "issues", wiki: "wiki", snippets: "snippets", merge_requests: "merge_requests" }
tools.each do |tool_name, shortcut_name|
describe "feature #{tool_name}" do
it 'toggles visibility' do
2017-09-10 17:25:29 +05:30
visit edit_project_path(project)
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
# disable by clicking toggle
toggle_feature_off("project[project_feature_attributes][#{tool_name}_access_level]")
2017-09-10 17:25:29 +05:30
page.within('.sharing-permissions') do
2018-03-17 18:26:18 +05:30
find('input[value="Save changes"]').click
2017-09-10 17:25:29 +05:30
end
wait_for_requests
2016-09-29 09:46:39 +05:30
expect(page).not_to have_selector(".shortcuts-#{shortcut_name}")
2018-03-17 18:26:18 +05:30
# re-enable by clicking toggle again
toggle_feature_on("project[project_feature_attributes][#{tool_name}_access_level]")
2017-09-10 17:25:29 +05:30
page.within('.sharing-permissions') do
2018-03-17 18:26:18 +05:30
find('input[value="Save changes"]').click
2017-09-10 17:25:29 +05:30
end
wait_for_requests
2016-09-29 09:46:39 +05:30
expect(page).to have_selector(".shortcuts-#{shortcut_name}")
end
end
end
2016-11-24 13:41:30 +05:30
2017-09-10 17:25:29 +05:30
context 'When external issue tracker is enabled and issues enabled on project settings' do
2020-01-01 13:55:28 +05:30
it 'does not hide issues tab and hides labels tab' do
2019-12-26 22:10:19 +05:30
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new)
end
2017-09-10 17:25:29 +05:30
visit project_path(project)
expect(page).to have_selector('.shortcuts-issues')
2020-01-01 13:55:28 +05:30
expect(page).not_to have_selector('.shortcuts-labels')
2017-09-10 17:25:29 +05:30
end
end
context 'When external issue tracker is enabled and issues disabled on project settings' do
2020-01-01 13:55:28 +05:30
it 'hides issues tab and show labels tab' do
2017-09-10 17:25:29 +05:30
project.issues_enabled = false
project.save!
2019-12-26 22:10:19 +05:30
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new)
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
visit project_path(project)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).not_to have_selector('.shortcuts-issues')
2020-01-01 13:55:28 +05:30
expect(page).to have_selector('.shortcuts-labels')
2017-08-17 22:00:37 +05:30
end
end
2016-11-24 13:41:30 +05:30
context "pipelines subtabs" do
it "shows builds when enabled" do
2017-09-10 17:25:29 +05:30
visit project_pipelines_path(project)
2016-11-24 13:41:30 +05:30
expect(page).to have_selector(".shortcuts-builds")
end
it "hides builds when disabled" do
2019-09-04 21:01:54 +05:30
allow(Ability).to receive(:allowed?).and_return(true)
allow(Ability).to receive(:allowed?).with(member, :read_build, project).and_return(false)
2016-11-24 13:41:30 +05:30
2017-09-10 17:25:29 +05:30
visit project_pipelines_path(project)
2016-11-24 13:41:30 +05:30
expect(page).not_to have_selector(".shortcuts-builds")
end
end
2016-09-29 09:46:39 +05:30
end
describe 'project features visibility pages' do
2017-09-10 17:25:29 +05:30
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:job) { create(:ci_build, pipeline: pipeline) }
2017-08-17 22:00:37 +05:30
let(:tools) do
{
2017-09-10 17:25:29 +05:30
builds: project_job_path(project, job),
issues: project_issues_path(project),
wiki: project_wiki_path(project, :home),
snippets: project_snippets_path(project),
merge_requests: project_merge_requests_path(project)
2017-08-17 22:00:37 +05:30
}
2016-09-29 09:46:39 +05:30
end
context 'normal user' do
2017-08-17 22:00:37 +05:30
before do
2017-09-10 17:25:29 +05:30
sign_in(member)
2017-08-17 22:00:37 +05:30
end
2016-09-29 09:46:39 +05:30
it 'renders 200 if tool is enabled' do
2017-08-17 22:00:37 +05:30
tools.each do |method_name, url|
2016-09-29 09:46:39 +05:30
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::ENABLED)
visit url
expect(page.status_code).to eq(200)
end
end
it 'renders 404 if feature is disabled' do
2017-08-17 22:00:37 +05:30
tools.each do |method_name, url|
2016-09-29 09:46:39 +05:30
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::DISABLED)
visit url
expect(page.status_code).to eq(404)
end
end
it 'renders 404 if feature is enabled only for team members' do
project.team.truncate
2017-08-17 22:00:37 +05:30
tools.each do |method_name, url|
2016-09-29 09:46:39 +05:30
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
expect(page.status_code).to eq(404)
end
end
2017-08-17 22:00:37 +05:30
it 'renders 200 if user is member of group' do
2016-09-29 09:46:39 +05:30
group = create(:group)
project.group = group
project.save
group.add_owner(member)
2017-08-17 22:00:37 +05:30
tools.each do |method_name, url|
2016-09-29 09:46:39 +05:30
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
expect(page.status_code).to eq(200)
end
end
end
context 'admin user' do
before do
non_member.update_attribute(:admin, true)
2017-09-10 17:25:29 +05:30
sign_in(non_member)
2016-09-29 09:46:39 +05:30
end
it 'renders 404 if feature is disabled' do
2017-08-17 22:00:37 +05:30
tools.each do |method_name, url|
2016-09-29 09:46:39 +05:30
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::DISABLED)
visit url
expect(page.status_code).to eq(404)
end
end
it 'renders 200 if feature is enabled only for team members' do
project.team.truncate
2017-08-17 22:00:37 +05:30
tools.each do |method_name, url|
2016-09-29 09:46:39 +05:30
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
expect(page.status_code).to eq(200)
end
end
end
end
2016-11-03 12:29:30 +05:30
2018-03-17 18:26:18 +05:30
describe 'repository visibility', :js do
2016-11-03 12:29:30 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(member)
2017-09-10 17:25:29 +05:30
sign_in(member)
visit edit_project_path(project)
2016-11-03 12:29:30 +05:30
end
it "disables repository related features" do
2018-03-17 18:26:18 +05:30
toggle_feature_off('project[project_feature_attributes][repository_access_level]')
2016-11-03 12:29:30 +05:30
2017-09-10 17:25:29 +05:30
page.within('.sharing-permissions') do
click_button "Save changes"
end
2020-03-13 15:44:24 +05:30
expect(find(".sharing-permissions")).to have_selector(".project-feature-toggle.is-disabled", count: 3)
2016-11-03 12:29:30 +05:30
end
it "shows empty features project homepage" do
2018-03-17 18:26:18 +05:30
toggle_feature_off('project[project_feature_attributes][repository_access_level]')
toggle_feature_off('project[project_feature_attributes][issues_access_level]')
toggle_feature_off('project[project_feature_attributes][wiki_access_level]')
2016-11-03 12:29:30 +05:30
2017-09-10 17:25:29 +05:30
page.within('.sharing-permissions') do
click_button "Save changes"
end
wait_for_requests
2016-11-03 12:29:30 +05:30
2017-09-10 17:25:29 +05:30
visit project_path(project)
2016-11-03 12:29:30 +05:30
expect(page).to have_content "Customize your workflow!"
end
2017-08-17 22:00:37 +05:30
it "hides project activity tabs" do
2018-03-17 18:26:18 +05:30
toggle_feature_off('project[project_feature_attributes][repository_access_level]')
toggle_feature_off('project[project_feature_attributes][issues_access_level]')
toggle_feature_off('project[project_feature_attributes][wiki_access_level]')
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
page.within('.sharing-permissions') do
click_button "Save changes"
end
wait_for_requests
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
visit activity_project_path(project)
2017-08-17 22:00:37 +05:30
page.within(".event-filter") do
2019-12-21 20:55:43 +05:30
expect(page).to have_content("All")
2017-08-17 22:00:37 +05:30
expect(page).not_to have_content("Push events")
expect(page).not_to have_content("Merge events")
expect(page).not_to have_content("Comments")
end
end
2019-12-04 20:38:33 +05:30
# Regression spec for https://gitlab.com/gitlab-org/gitlab-foss/issues/25272
2017-08-17 22:00:37 +05:30
it "hides comments activity tab only on disabled issues, merge requests and repository" do
2018-03-17 18:26:18 +05:30
toggle_feature_off('project[project_feature_attributes][issues_access_level]')
2017-08-17 22:00:37 +05:30
save_changes_and_check_activity_tab do
expect(page).to have_content("Comments")
end
2017-09-10 17:25:29 +05:30
visit edit_project_path(project)
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
toggle_feature_off('project[project_feature_attributes][merge_requests_access_level]')
2017-08-17 22:00:37 +05:30
save_changes_and_check_activity_tab do
expect(page).to have_content("Comments")
end
2017-09-10 17:25:29 +05:30
visit edit_project_path(project)
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
toggle_feature_off('project[project_feature_attributes][repository_access_level]')
2017-08-17 22:00:37 +05:30
save_changes_and_check_activity_tab do
expect(page).not_to have_content("Comments")
end
2017-09-10 17:25:29 +05:30
visit edit_project_path(project)
2017-08-17 22:00:37 +05:30
end
def save_changes_and_check_activity_tab
2017-09-10 17:25:29 +05:30
page.within('.sharing-permissions') do
click_button "Save changes"
end
wait_for_requests
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
visit activity_project_path(project)
2017-08-17 22:00:37 +05:30
page.within(".event-filter") do
yield
end
end
end
2019-12-04 20:38:33 +05:30
# Regression spec for https://gitlab.com/gitlab-org/gitlab-foss/issues/24056
2017-08-17 22:00:37 +05:30
describe 'project statistic visibility' do
let!(:project) { create(:project, :private) }
before do
2018-03-17 18:26:18 +05:30
project.add_guest(member)
2017-09-10 17:25:29 +05:30
sign_in(member)
visit project_path(project)
2017-08-17 22:00:37 +05:30
end
it "does not show project statistic for guest" do
expect(page).not_to have_selector('.project-stats')
end
2016-11-03 12:29:30 +05:30
end
2018-03-17 18:26:18 +05:30
def toggle_feature_off(feature_name)
find(".project-feature-controls[data-for=\"#{feature_name}\"] .project-feature-toggle.is-checked").click
end
def toggle_feature_on(feature_name)
find(".project-feature-controls[data-for=\"#{feature_name}\"] .project-feature-toggle:not(.is-checked)").click
end
2016-09-29 09:46:39 +05:30
end