Commit 8f942a05 authored by Matija Čupić's avatar Matija Čupić

Use policies instead of role checks in ClustersHelper

parent ad38e120
...@@ -8,8 +8,7 @@ module CalloutsHelper ...@@ -8,8 +8,7 @@ module CalloutsHelper
def show_gke_cluster_integration_callout?(project) def show_gke_cluster_integration_callout?(project)
current_user && !user_dismissed?(GKE_CLUSTER_INTEGRATION) && current_user && !user_dismissed?(GKE_CLUSTER_INTEGRATION) &&
(project.team.master?(current_user) || can?(current_user, :create_cluster, project)
current_user == project.owner)
end end
private private
......
...@@ -17,30 +17,22 @@ describe CalloutsHelper do ...@@ -17,30 +17,22 @@ describe CalloutsHelper do
allow(helper).to receive(:user_dismissed?).and_return(false) allow(helper).to receive(:user_dismissed?).and_return(false)
end end
context 'when user is master' do context 'when user can create a cluster' do
before 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 end
it { is_expected.to be true } it { is_expected.to be true }
end end
context 'when user is not master' do context 'when user can not create a cluster' do
context 'when the user is owner' do before do
before do allow(helper).to receive(:can?).with(anything, :create_cluster, anything)
allow(project).to receive(:owner).and_return(user) .and_return(false)
end
it { is_expected.to be true }
end end
context 'when the user is not owner' do it { is_expected.to be false }
before do
allow(project).to receive_message_chain(:team, :master?).and_return(false)
end
it { is_expected.to be false }
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment