Commit 74b97377 authored by Ryan Cobb's avatar Ryan Cobb

Cleanup metric dashboard and specs

parent 79d6696c
...@@ -34,26 +34,23 @@ module MetricsDashboard ...@@ -34,26 +34,23 @@ module MetricsDashboard
def all_dashboards def all_dashboards
dashboards = dashboard_finder.find_all_paths(project_for_dashboard) dashboards = dashboard_finder.find_all_paths(project_for_dashboard)
dashboards.map do |dashboard| dashboards.each do |dashboard|
dashboard[:can_edit] = can_edit?(dashboard) dashboard[:can_edit] = false
dashboard[:project_blob_path] = project_blob_path(dashboard) dashboard[:project_blob_path] = nil
dashboard
if project_for_dashboard && !dashboard[:system_dashboard]
dashboard[:can_edit] = can_edit?(dashboard)
dashboard[:project_blob_path] = dashboard_project_blob_path(dashboard)
end
end end
end end
def can_edit?(dashboard) def dashboard_project_blob_path(dashboard)
return false unless project_for_dashboard project_blob_path(project_for_dashboard, File.join(project_for_dashboard.default_branch, dashboard[:path]))
return false if dashboard[:system_dashboard]
return false unless can_collaborate_with_project?(project_for_dashboard, ref: project_for_dashboard.default_branch)
true
end end
def project_blob_path(dashboard) def can_edit?(dashboard)
return unless project_for_dashboard can_collaborate_with_project?(project_for_dashboard, ref: project_for_dashboard.default_branch)
return if dashboard[:system_dashboard]
Gitlab::Routing.url_helpers.project_blob_path(project_for_dashboard, File.join(project_for_dashboard.default_branch, dashboard[:path]))
end end
# Override in class to provide arguments to the finder. # Override in class to provide arguments to the finder.
......
...@@ -67,29 +67,31 @@ describe MetricsDashboard do ...@@ -67,29 +67,31 @@ describe MetricsDashboard do
end end
context 'in all_dashboard list' do context 'in all_dashboard list' do
let(:system_dashboard) { json_response['all_dashboards'][0] } let(:system_dashboard) { json_response['all_dashboards'].find { |dashboard| dashboard["system_dashboard"] == true } }
let(:project_dashboard) { json_response['all_dashboards'][1] } let(:project_dashboard) { json_response['all_dashboards'].find { |dashboard| dashboard["system_dashboard"] == false } }
it 'includes project_blob_path only for project dashboards' do it 'includes project_blob_path only for project dashboards' do
expect(system_dashboard['project_blob_path']).to be_nil expect(system_dashboard['project_blob_path']).to be_nil
expect(project_dashboard['project_blob_path']).to eq("/#{project.namespace.path}/#{project.name}/blob/master/.gitlab/dashboards/test.yml") expect(project_dashboard['project_blob_path']).to eq("/#{project.namespace.path}/#{project.name}/blob/master/.gitlab/dashboards/test.yml")
end end
context 'when a user can collaborate on project' do describe 'project permissions' do
it 'sets can_edit to true for project dashboards' do using RSpec::Parameterized::TableSyntax
expect(system_dashboard['can_edit']).to eq(false)
expect(project_dashboard['can_edit']).to eq(true)
end
end
context 'when user does not have permissions to edit project dashboard' do where(:can_collaborate, :system_can_edit, :project_can_edit) do
before do false | false | false
allow(controller).to receive(:can_collaborate_with_project?).and_return(false) true | false | true
end end
it 'sets can_edit to false for project dashboards' do with_them do
expect(system_dashboard['can_edit']).to eq(false) before do
expect(project_dashboard['can_edit']).to eq(false) allow(controller).to receive(:can_collaborate_with_project?).and_return(can_collaborate)
end
it "sets can_edit appropriately" do
expect(system_dashboard["can_edit"]).to eq(system_can_edit)
expect(project_dashboard["can_edit"]).to eq(project_can_edit)
end
end 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