Skip to content
Snippets Groups Projects
Commit 1068483f authored by Paul Slaughter's avatar Paul Slaughter
Browse files

Merge branch...

Merge branch '50020-fe-allow-email-notifications-to-be-disabled-for-all-users-of-a-group' into 'master'

UI for disabling group/project email notifications

Closes #50020

See merge request gitlab-org/gitlab-ce!30961
parents 9eabc0d6 9be16e1f
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -27,4 +27,14 @@ describe "User toggles subscription", :js do
# Check we're unsubscribed.
expect(subscription_button).to have_css("button:not(.is-checked)")
end
context 'when project emails are disabled' do
let(:project) { create(:project_empty_repo, :public, emails_disabled: true) }
it 'is disabled' do
expect(page).to have_content('Notifications have been disabled by the project or group owner')
expect(page).to have_selector('.js-emails-disabled', visible: true)
expect(page).not_to have_selector('.js-issuable-subscribe-button')
end
end
end
Loading
Loading
@@ -20,4 +20,12 @@ describe 'User visits the notifications tab', :js do
 
expect(page).to have_selector('#notifications-button', text: 'On mention')
end
context 'when project emails are disabled' do
let(:project) { create(:project, emails_disabled: true) }
it 'notification button is disabled' do
expect(page).to have_selector('.notifications-btn.disabled', visible: true)
end
end
end
Loading
Loading
@@ -59,6 +59,12 @@ describe 'Projects > Settings > Visibility settings', :js do
end
end
end
context 'disable email notifications' do
it 'is visible' do
expect(page).to have_selector('.js-emails-disabled', visible: true)
end
end
end
 
context 'as maintainer' do
Loading
Loading
@@ -76,5 +82,11 @@ describe 'Projects > Settings > Visibility settings', :js do
expect(visibility_select_container).to have_selector 'select[name="project[visibility_level]"]:disabled'
expect(visibility_select_container).to have_content 'The project can be accessed by anyone, regardless of authentication.'
end
context 'disable email notifications' do
it 'is not available' do
expect(page).not_to have_selector('.js-emails-disabled', visible: true)
end
end
end
end
Loading
Loading
@@ -65,4 +65,12 @@ describe 'Projects > Show > User manages notifications', :js do
end
end
end
context 'when project emails are disabled' do
let(:project) { create(:project, :public, :repository, emails_disabled: true) }
it 'is disabled' do
expect(page).to have_selector('.notifications-btn.disabled', visible: true)
end
end
end
Loading
Loading
@@ -262,4 +262,44 @@ describe GroupsHelper do
expect(parent_group_options(group2)).to eq([{ id: group.id, text: group.human_name }].to_json)
end
end
describe '#can_disable_group_emails?' do
let(:current_user) { create(:user) }
let(:group) { create(:group, name: 'group') }
let(:subgroup) { create(:group, name: 'subgroup', parent: group) }
before do
allow(helper).to receive(:current_user) { current_user }
end
it 'returns true for the group owner' do
allow(helper).to receive(:can?).with(current_user, :set_emails_disabled, group) { true }
expect(helper.can_disable_group_emails?(group)).to be_truthy
end
it 'returns false for anyone else' do
allow(helper).to receive(:can?).with(current_user, :set_emails_disabled, group) { false }
expect(helper.can_disable_group_emails?(group)).to be_falsey
end
context 'when subgroups' do
before do
allow(helper).to receive(:can?).with(current_user, :set_emails_disabled, subgroup) { true }
end
it 'returns false if parent group is disabling emails' do
allow(group).to receive(:emails_disabled?).and_return(true)
expect(helper.can_disable_group_emails?(subgroup)).to be_falsey
end
it 'returns true if parent group is not disabling emails' do
allow(group).to receive(:emails_disabled?).and_return(false)
expect(helper.can_disable_group_emails?(subgroup)).to be_truthy
end
end
end
end
Loading
Loading
@@ -3,6 +3,7 @@ require 'spec_helper'
describe NotificationsHelper do
describe 'notification_icon' do
it { expect(notification_icon(:disabled)).to match('class="fa fa-microphone-slash fa-fw"') }
it { expect(notification_icon(:owner_disabled)).to match('class="fa fa-microphone-slash fa-fw"') }
it { expect(notification_icon(:participating)).to match('class="fa fa-volume-up fa-fw"') }
it { expect(notification_icon(:mention)).to match('class="fa fa-at fa-fw"') }
it { expect(notification_icon(:global)).to match('class="fa fa-globe fa-fw"') }
Loading
Loading
@@ -19,4 +20,14 @@ describe NotificationsHelper do
it { expect(notification_event_name(:success_pipeline)).to match('Successful pipeline') }
it { expect(notification_event_name(:failed_pipeline)).to match('Failed pipeline') }
end
describe '#notification_icon_level' do
let(:user) { create(:user) }
let(:global_setting) { user.global_notification_setting }
let(:notification_setting) { create(:notification_setting, level: :watch) }
it { expect(notification_icon_level(notification_setting, true)).to eq 'owner_disabled' }
it { expect(notification_icon_level(notification_setting)).to eq 'watch' }
it { expect(notification_icon_level(global_setting)).to eq 'participating' }
end
end
Loading
Loading
@@ -107,6 +107,30 @@ describe ProjectsHelper do
end
end
 
describe '#can_disable_emails?' do
let(:project) { create(:project) }
let(:user) { create(:project_member, :maintainer, user: create(:user), project: project).user }
it 'returns true for the project owner' do
allow(helper).to receive(:can?).with(project.owner, :set_emails_disabled, project) { true }
expect(helper.can_disable_emails?(project, project.owner)).to be_truthy
end
it 'returns false for anyone else' do
allow(helper).to receive(:can?).with(user, :set_emails_disabled, project) { false }
expect(helper.can_disable_emails?(project, user)).to be_falsey
end
it 'returns false if group emails disabled' do
project = create(:project, group: create(:group))
allow(project.group).to receive(:emails_disabled?).and_return(true)
expect(helper.can_disable_emails?(project, project.owner)).to be_falsey
end
end
describe "readme_cache_key" do
let(:project) { create(:project, :repository) }
 
Loading
Loading
@@ -477,6 +501,7 @@ describe ProjectsHelper do
 
it 'returns the command to push to create project over SSH' do
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enabled_git_access_protocol) { 'ssh' }
allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return('git@localhost:')
 
expect(helper.push_to_create_project_command(user)).to eq('git push --set-upstream git@localhost:john/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD)')
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment