diff options
-rw-r--r-- | app/controllers/projects/application_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/projects/git_http_client_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/projects/uploads_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 1 | ||||
-rw-r--r-- | app/helpers/environments_helper.rb | 6 | ||||
-rw-r--r-- | app/views/layouts/nav/sidebar/_project.html.haml | 4 | ||||
-rw-r--r-- | config/routes/project.rb | 1 | ||||
-rw-r--r-- | spec/controllers/projects/environments_controller_spec.rb | 18 | ||||
-rw-r--r-- | spec/helpers/environments_helper_spec.rb | 19 |
10 files changed, 35 insertions, 35 deletions
diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index 5475e333db9..5ab6d103c89 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -5,7 +5,6 @@ class Projects::ApplicationController < ApplicationController skip_before_action :authenticate_user! before_action :project before_action :repository - before_action :available_environment layout 'project' helper_method :repository, :can_collaborate_with_project?, :user_access @@ -33,10 +32,6 @@ class Projects::ApplicationController < ApplicationController @repository ||= project.repository end - def available_environment - @available_environment ||= project.environments.with_state(:available).first - end - def authorize_action!(action) unless can?(current_user, action, project) return access_denied! diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index decef19a0a2..53da384dc74 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -124,6 +124,19 @@ class Projects::EnvironmentsController < Projects::ApplicationController render :empty end + def metrics_redirect + environment = project.environments.with_state(:available).first + + path = + if environment + environment_metrics_path(environment) + else + empty_project_environments_path(project) + end + + redirect_to path + end + def metrics # Currently, this acts as a hint to load the metrics details into the cache # if they aren't there already diff --git a/app/controllers/projects/git_http_client_controller.rb b/app/controllers/projects/git_http_client_controller.rb index 199a8a4c4c5..07249fe3182 100644 --- a/app/controllers/projects/git_http_client_controller.rb +++ b/app/controllers/projects/git_http_client_controller.rb @@ -15,7 +15,6 @@ class Projects::GitHttpClientController < Projects::ApplicationController # Git clients will not know what authenticity token to send along skip_before_action :verify_authenticity_token skip_before_action :repository - skip_before_action :available_environment before_action :authenticate_user private diff --git a/app/controllers/projects/uploads_controller.rb b/app/controllers/projects/uploads_controller.rb index 14e84f6a65f..f5cf089ad98 100644 --- a/app/controllers/projects/uploads_controller.rb +++ b/app/controllers/projects/uploads_controller.rb @@ -2,7 +2,7 @@ class Projects::UploadsController < Projects::ApplicationController include UploadsActions # These will kick you out if you don't have access. - skip_before_action :project, :repository, :available_environment, + skip_before_action :project, :repository, if: -> { action_name == 'show' && image_or_video? } before_action :authorize_upload_file!, only: [:create] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5a6ccd629d1..c2492a137fb 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -8,7 +8,6 @@ class ProjectsController < Projects::ApplicationController before_action :redirect_git_extension, only: [:show] before_action :project, except: [:index, :new, :create] before_action :repository, except: [:index, :new, :create] - before_action :available_environment, except: [:index, :new, :create] before_action :assign_ref_vars, only: [:show], if: :repo_exists? before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?] before_action :lfs_blob_ids, only: [:show], if: [:repo_exists?, :project_view_files?] diff --git a/app/helpers/environments_helper.rb b/app/helpers/environments_helper.rb index 9276d9b6ac5..4ce89f89fa9 100644 --- a/app/helpers/environments_helper.rb +++ b/app/helpers/environments_helper.rb @@ -4,10 +4,4 @@ module EnvironmentsHelper endpoint: project_environments_path(@project, format: :json) } end - - def operations_metrics_path(project, environment) - return environment_metrics_path(environment) if environment - - empty_project_environments_path(project) - end end diff --git a/app/views/layouts/nav/sidebar/_project.html.haml b/app/views/layouts/nav/sidebar/_project.html.haml index 7ff4bcebe27..a1763393d25 100644 --- a/app/views/layouts/nav/sidebar/_project.html.haml +++ b/app/views/layouts/nav/sidebar/_project.html.haml @@ -204,14 +204,14 @@ %ul.sidebar-sub-level-items = nav_link(controller: [:environments, :clusters, :user, :gcp], html_options: { class: "fly-out-top-item" } ) do - = link_to operations_metrics_path(@project, @available_environment) do + = link_to metrics_project_environments_path(@project) do %strong.fly-out-top-item-name = _('Operations') %li.divider.fly-out-top-item - if project_nav_tab? :environments = nav_link(controller: :environments, action: [:metrics, :empty]) do - = link_to operations_metrics_path(@project, @available_environment), title: 'Metrics', class: 'shortcuts-metrics' do + = link_to metrics_project_environments_path(@project), title: 'Metrics', class: 'shortcuts-metrics' do %span = _('Metrics') diff --git a/config/routes/project.rb b/config/routes/project.rb index 702141749e8..18685d3acfd 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -235,6 +235,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do end collection do + get :metrics, action: :metrics_redirect get :empty get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ } end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 36ebbc8a016..f6ce4c20d5b 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -287,6 +287,24 @@ describe Projects::EnvironmentsController do end end + describe 'GET #metrics_redirect' do + let(:project) { create(:project) } + + it 'redirects to environment if it exists' do + environment = create(:environment, name: 'production', project: project) + + get :metrics_redirect, environment_params + + expect(response).to redirect_to(environment_metrics_path(environment)) + end + + it 'redirects to empty page if no environment exists' do + get :metrics_redirect, environment_params + + expect(response).to redirect_to(empty_project_environments_path(project)) + end + end + describe 'GET #metrics' do before do allow(controller).to receive(:environment).and_return(environment) diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb deleted file mode 100644 index c6810f9003d..00000000000 --- a/spec/helpers/environments_helper_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe EnvironmentsHelper do - include ApplicationHelper - - describe 'operations_metrics_path' do - let(:project) { create(:project) } - - it 'returns empty metrics path when environment is nil' do - expect(helper.operations_metrics_path(project, nil)).to eq(empty_project_environments_path(project)) - end - - it 'returns environment metrics path when environment is passed' do - environment = create(:environment, project: project) - - expect(helper.operations_metrics_path(project, environment)).to eq(environment_metrics_path(environment)) - end - end -end |