Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add latest changes from gitlab-org/gitlab@master
- Loading branch information
GitLab Bot
committed
Oct 4, 2019
1 parent
535d167
commit 1f1bdf5
Showing
9 changed files
with
177 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
# Provides an action which fetches a metrics dashboard according | ||
# to the parameters specified by the controller. | ||
module MetricsDashboard | ||
extend ActiveSupport::Concern | ||
|
||
def metrics_dashboard | ||
result = dashboard_finder.find( | ||
project_for_dashboard, | ||
current_user, | ||
metrics_dashboard_params | ||
) | ||
|
||
if include_all_dashboards? | ||
result[:all_dashboards] = dashboard_finder.find_all_paths(project_for_dashboard) | ||
end | ||
|
||
respond_to do |format| | ||
if result[:status] == :success | ||
format.json { render dashboard_success_response(result) } | ||
else | ||
format.json { render dashboard_error_response(result) } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
# Override in class to provide arguments to the finder. | ||
def metrics_dashboard_params | ||
{} | ||
end | ||
|
||
# Override in class if response requires complete list of | ||
# dashboards in addition to requested dashboard body. | ||
def include_all_dashboards? | ||
false | ||
end | ||
|
||
def dashboard_finder | ||
::Gitlab::Metrics::Dashboard::Finder | ||
end | ||
|
||
# Project is not defined for group and admin level clusters. | ||
def project_for_dashboard | ||
defined?(project) ? project : nil | ||
end | ||
|
||
def dashboard_success_response(result) | ||
{ | ||
status: :ok, | ||
json: result.slice(:all_dashboards, :dashboard, :status) | ||
} | ||
end | ||
|
||
def dashboard_error_response(result) | ||
{ | ||
status: result[:http_status], | ||
json: result.slice(:all_dashboards, :message, :status) | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
.../unreleased/31030-when-viewing-comments-occasionally-the-users-profile-picture-will-b.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Fix broken notes avatar rendering in Chrome 77 | ||
merge_request: 18110 | ||
author: | ||
type: fixed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe MetricsDashboard do | ||
describe 'GET #metrics_dashboard' do | ||
let_it_be(:user) { create(:user) } | ||
let_it_be(:project) { create(:project, :repository) } | ||
let_it_be(:environment) { create(:environment, project: project) } | ||
|
||
before do | ||
sign_in(user) | ||
project.add_maintainer(user) | ||
end | ||
|
||
controller(::ApplicationController) do | ||
include MetricsDashboard # rubocop:disable RSpec/DescribedClass | ||
end | ||
|
||
let(:json_response) do | ||
routes.draw { get "metrics_dashboard" => "anonymous#metrics_dashboard" } | ||
response = get :metrics_dashboard, format: :json | ||
|
||
JSON.parse(response.parsed_body) | ||
end | ||
|
||
context 'when no parameters are provided' do | ||
it 'returns an error json_response' do | ||
expect(json_response['status']).to eq('error') | ||
end | ||
end | ||
|
||
context 'when params are provided' do | ||
before do | ||
allow(controller).to receive(:project).and_return(project) | ||
allow(controller) | ||
.to receive(:metrics_dashboard_params) | ||
.and_return(environment: environment) | ||
end | ||
|
||
it 'returns the specified dashboard' do | ||
expect(json_response['dashboard']['dashboard']).to eq('Environment metrics') | ||
expect(json_response).not_to have_key('all_dashboards') | ||
end | ||
|
||
context 'when parameters are provided and the list of all dashboards is required' do | ||
before do | ||
allow(controller).to receive(:include_all_dashboards?).and_return(true) | ||
end | ||
|
||
it 'returns a dashboard in addition to the list of dashboards' do | ||
expect(json_response['dashboard']['dashboard']).to eq('Environment metrics') | ||
expect(json_response).to have_key('all_dashboards') | ||
end | ||
end | ||
end | ||
end | ||
end |