From 8f942a0534384f73cfa8686a0c67ec6451c5c39b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 2 Feb 2018 03:39:07 +0100 Subject: Use policies instead of role checks in ClustersHelper --- app/helpers/callouts_helper.rb | 3 +-- spec/helpers/callouts_helper_spec.rb | 24 ++++++++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/helpers/callouts_helper.rb b/app/helpers/callouts_helper.rb index 3841d288f52..168b731ae89 100644 --- a/app/helpers/callouts_helper.rb +++ b/app/helpers/callouts_helper.rb @@ -8,8 +8,7 @@ module CalloutsHelper def show_gke_cluster_integration_callout?(project) current_user && !user_dismissed?(GKE_CLUSTER_INTEGRATION) && - (project.team.master?(current_user) || - current_user == project.owner) + can?(current_user, :create_cluster, project) end private diff --git a/spec/helpers/callouts_helper_spec.rb b/spec/helpers/callouts_helper_spec.rb index 7ec8ca8eb0c..d0a5addc231 100644 --- a/spec/helpers/callouts_helper_spec.rb +++ b/spec/helpers/callouts_helper_spec.rb @@ -17,30 +17,22 @@ describe CalloutsHelper do allow(helper).to receive(:user_dismissed?).and_return(false) end - context 'when user is master' do + context 'when user can create a cluster' do before do - allow(project).to receive_message_chain(:team, :master?).and_return(true) + allow(helper).to receive(:can?).with(anything, :create_cluster, anything) + .and_return(true) end it { is_expected.to be true } end - context 'when user is not master' do - context 'when the user is owner' do - before do - allow(project).to receive(:owner).and_return(user) - end - - it { is_expected.to be true } + context 'when user can not create a cluster' do + before do + allow(helper).to receive(:can?).with(anything, :create_cluster, anything) + .and_return(false) end - context 'when the user is not owner' do - before do - allow(project).to receive_message_chain(:team, :master?).and_return(false) - end - - it { is_expected.to be false } - end + it { is_expected.to be false } end end -- cgit v1.2.1