From 17f457cb587a6bdaa2f01af066f997f3abfc6bf6 Mon Sep 17 00:00:00 2001 From: Romit Choudhary Date: Mon, 17 May 2021 15:09:58 +0000 Subject: [PATCH] Fixes #3546 - Dont display profile link if user has no user_preferences.* permissions at all --- .../app/controllers/profile.coffee | 2 +- spec/system/profile_spec.rb | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 spec/system/profile_spec.rb diff --git a/app/assets/javascripts/app/controllers/profile.coffee b/app/assets/javascripts/app/controllers/profile.coffee index 0358f12ce..4e39dcdeb 100644 --- a/app/assets/javascripts/app/controllers/profile.coffee +++ b/app/assets/javascripts/app/controllers/profile.coffee @@ -23,4 +23,4 @@ App.Config.set('profile', ProfileRouter, 'Routes') App.Config.set('profile/:target', ProfileRouter, 'Routes') App.Config.set('Profile', { prio: 1000, name: 'Profile', target: '#profile' }, 'NavBarProfile') -App.Config.set('Profile', { prio: 1700, parent: '#current_user', name: 'Profile', target: '#profile', translate: true }, 'NavBarRight') +App.Config.set('Profile', { prio: 1700, parent: '#current_user', name: 'Profile', target: '#profile', permission: ['user_preferences.*'], translate: true }, 'NavBarRight') diff --git a/spec/system/profile_spec.rb b/spec/system/profile_spec.rb new file mode 100644 index 000000000..929b74bdc --- /dev/null +++ b/spec/system/profile_spec.rb @@ -0,0 +1,23 @@ +require 'rails_helper' + +RSpec.describe 'Profile', type: :system do + + it 'shows profile link in navigation' do + visit 'dashboard' + + find('a[href="#current_user"]').click + expect(page).to have_css('.dropdown-menu > li > a[href="#profile"]') + end + + context 'when user is an agent with no user_preferences permission', authenticated_as: :new_user do + let(:role) { create(:role, permissions: [Permission.find_by(name: 'ticket.agent')]) } + let(:new_user) { create(:user, roles: [role] ) } + + it 'does not show profile link in navigation' do + visit 'dashboard' + + find('a[href="#current_user"]').click + expect(page).to have_no_css('.dropdown-menu > li > a[href="#profile"]') + end + end +end