Skip to content
Snippets Groups Projects
Commit 1a1fdf8e authored by Thong Kuah's avatar Thong Kuah :speech_balloon:
Browse files

Resolve controller sharing concern

Use ClustersController as base while having Projects::ClustersController
to inform what `clusterable` is. Thanks @ayufan for the great suggestion
!

- View changes to work with new approach

- Fix javascript for new approach

- Fix feature specs for new approach

- Fix QA
parent 28dabc67
No related branches found
No related tags found
No related merge requests found
Showing
with 93 additions and 65 deletions
import initDismissableCallout from '~/dismissable_callout';
import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
document.addEventListener('DOMContentLoaded', () => {
initDismissableCallout('.gcp-signup-offer');
initGkeDropdowns();
});
import initDismissableCallout from '~/dismissable_callout';
import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
document.addEventListener('DOMContentLoaded', () => {
initDismissableCallout('.gcp-signup-offer');
initGkeDropdowns();
});
import initDismissableCallout from '~/dismissable_callout';
import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
document.addEventListener('DOMContentLoaded', () => {
initDismissableCallout('.gcp-signup-offer');
initGkeDropdowns();
});
import initDismissableCallout from '~/dismissable_callout';
import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
import Project from './project';
import ShortcutsNavigation from '../../behaviors/shortcuts/shortcuts_navigation';
 
document.addEventListener('DOMContentLoaded', () => {
const { page } = document.body.dataset;
const newClusterViews = [
'projects:clusters:new',
'projects:clusters:create_gcp',
'projects:clusters:create_user',
];
if (newClusterViews.indexOf(page) > -1) {
initDismissableCallout('.gcp-signup-offer');
initGkeDropdowns();
}
new Project(); // eslint-disable-line no-new
new ShortcutsNavigation(); // eslint-disable-line no-new
});
Loading
Loading
@@ -2,31 +2,25 @@
 
class Clusters::BaseController < ApplicationController
include RoutableActions
include ProjectUnauthorized
 
skip_before_action :authenticate_user!
before_action :require_project_id
before_action :project, if: :project_type?
before_action :repository, if: :project_type?
before_action :authorize_read_cluster!
 
layout :determine_layout
helper_method :clusterable
 
private
 
# We can extend to `#group_type?` in the future
def require_project_id
not_found unless project_type?
def cluster
@cluster ||= clusterable.clusters.find(params[:id])
.present(current_user: current_user)
end
 
def project
@project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id]), not_found_or_authorized_proc: project_unauthorized_proc)
def authorize_update_cluster!
access_denied! unless can?(current_user, :update_cluster, cluster)
end
 
def repository
@repository ||= project.repository
def authorize_admin_cluster!
access_denied! unless can?(current_user, :admin_cluster, cluster)
end
 
def authorize_read_cluster!
Loading
Loading
@@ -37,17 +31,7 @@ class Clusters::BaseController < ApplicationController
access_denied! unless can?(current_user, :create_cluster, clusterable)
end
 
def determine_layout
if project_type?
'project'
end
end
def clusterable
@clusterable ||= ClusterablePresenter.fabricate(project, current_user: current_user)
end
def project_type?
params[:project_id].present?
raise NotImplementedError
end
end
# frozen_string_literal: true
 
class ClustersController < Clusters::BaseController
class Clusters::ClustersController < Clusters::BaseController
include RoutableActions
before_action :cluster, except: [:index, :new, :create_gcp, :create_user]
before_action :generate_gcp_authorize_url, only: [:new]
before_action :validate_gcp_token, only: [:new]
Loading
Loading
@@ -9,7 +11,7 @@ class ClustersController < Clusters::BaseController
before_action :authorize_create_cluster!, only: [:new]
before_action :authorize_update_cluster!, only: [:update]
before_action :authorize_admin_cluster!, only: [:destroy]
before_action :update_applications_status, only: [:status]
before_action :update_applications_status, only: [:cluster_status]
 
helper_method :token_in_session
 
Loading
Loading
@@ -23,7 +25,8 @@ class ClustersController < Clusters::BaseController
def new
end
 
def status
# Overridding ActionController::Metal#status is NOT a good idea
def cluster_status
respond_to do |format|
format.json do
Gitlab::PollingInterval.set_header(response, interval: STATUS_POLLING_INTERVAL)
Loading
Loading
@@ -107,11 +110,6 @@ class ClustersController < Clusters::BaseController
 
private
 
def cluster
@cluster ||= clusterable.clusters.find(params[:id])
.present(current_user: current_user)
end
def update_params
if cluster.managed?
params.require(:cluster).permit(
Loading
Loading
@@ -214,14 +212,6 @@ class ClustersController < Clusters::BaseController
end
end
 
def authorize_update_cluster!
access_denied! unless can?(current_user, :update_cluster, cluster)
end
def authorize_admin_cluster!
access_denied! unless can?(current_user, :admin_cluster, cluster)
end
def update_applications_status
@cluster.applications.each(&:schedule_status_update)
end
Loading
Loading
# frozen_string_literal: true
class Projects::Clusters::ApplicationsController < Clusters::ApplicationsController
include ProjectUnauthorized
prepend_before_action :project
private
def clusterable
@clusterable ||= ClusterablePresenter.fabricate(project, current_user: current_user)
end
def project
@project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id]), not_found_or_authorized_proc: project_unauthorized_proc)
end
end
# frozen_string_literal: true
class Projects::ClustersController < Clusters::ClustersController
include ProjectUnauthorized
prepend_before_action :project
before_action :repository
layout 'project'
private
def clusterable
@clusterable ||= ClusterablePresenter.fabricate(project, current_user: current_user)
end
def project
@project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id]), not_found_or_authorized_proc: project_unauthorized_proc)
end
def repository
@repository ||= project.repository
end
end
Loading
Loading
@@ -11,7 +11,7 @@ module ClustersHelper
return unless show_gcp_signup_offer?
 
content_tag :section, class: 'no-animate expanded' do
render 'clusters/gcp_signup_offer_banner'
render 'clusters/clusters/gcp_signup_offer_banner'
end
end
 
Loading
Loading
Loading
Loading
@@ -9,6 +9,26 @@ class ProjectClusterablePresenter < ClusterablePresenter
new_project_cluster_path(clusterable)
end
 
def create_user_clusters_path
create_user_project_clusters_path(clusterable)
end
def create_gcp_clusters_path
create_gcp_project_clusters_path(clusterable)
end
def cluster_status_cluster_path(cluster, params = {})
cluster_status_project_cluster_path(clusterable, cluster, params)
end
def install_applications_cluster_path(cluster, application)
install_applications_project_cluster_path(clusterable, cluster, application)
end
def cluster_path(cluster, params = {})
project_cluster_path(clusterable, cluster, params)
end
def clusterable_params
{ project_id: clusterable.to_param, namespace_id: clusterable.namespace.to_param }
end
Loading
Loading
Loading
Loading
@@ -12,4 +12,4 @@
= s_('ClusterIntegration|Remove Kubernetes cluster integration')
%p
= s_("ClusterIntegration|Remove this Kubernetes cluster's configuration from this project. This will not delete your actual Kubernetes cluster.")
= link_to(s_('ClusterIntegration|Remove integration'), cluster_path(@cluster, clusterable.clusterable_params), method: :delete, class: 'btn btn-danger', data: { confirm: s_("ClusterIntegration|Are you sure you want to remove this Kubernetes cluster's integration? This will not delete your actual Kubernetes cluster.")})
= link_to(s_('ClusterIntegration|Remove integration'), clusterable.cluster_path(@cluster), method: :delete, class: 'btn btn-danger', data: { confirm: s_("ClusterIntegration|Are you sure you want to remove this Kubernetes cluster's integration? This will not delete your actual Kubernetes cluster.")})
Loading
Loading
@@ -16,7 +16,7 @@
class: "#{'is-checked' if cluster.enabled?} #{'is-disabled' if !cluster.can_toggle_cluster?}",
"aria-label": s_("ClusterIntegration|Toggle Kubernetes Cluster"),
disabled: !cluster.can_toggle_cluster?,
data: { endpoint: cluster_path(cluster, clusterable.clusterable_params.merge(format: :json)) } }
data: { endpoint: clusterable.cluster_path(cluster, format: :json) } }
%input.js-project-feature-toggle-input{ type: "hidden", value: cluster.enabled? }
= icon("spinner spin", class: "loading-icon")
%span.toggle-icon
Loading
Loading
= form_for @cluster, url: cluster_path(@cluster), as: :cluster do |field|
= form_for @cluster, url: clusterable.cluster_path(@cluster), as: :cluster do |field|
= form_errors(@cluster)
= hidden_clusterable_fields
.form-group
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment