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

Convert clusters to use a top-level controller

In preparation so that we can create both cluster attached to project
and cluster attached to group.

- Move ClustersController to top level

- Move Clusters::ApplicationsController to top-level too

- Creates a Clusters::BaseController to share common functions

- Do not rely on @Project ivar. Anything could set the ivar.

- Fix Vue page components due to new data-page value

Because of the controller change we have gone from
`projects:clusters:new` to `clusters:new`, so we need to update the file
location of the page components. There is somewhere a function that will
convert data-page to a file location.

On that note, projects/clusters/gcp/new/, translate to
Projects::Clusters::Gcp#new doesn't exist so replace that with
clusters/create_gcp/ and clusters/create_user/
parent 5a953741
No related branches found
No related tags found
No related merge requests found
Showing
with 72 additions and 21 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
});
# frozen_string_literal: true
 
class Projects::Clusters::ApplicationsController < Projects::ApplicationController
class Clusters::ApplicationsController < Clusters::BaseController
before_action :cluster
before_action :authorize_read_cluster!
before_action :authorize_create_cluster!, only: [:create]
 
def create
Loading
Loading
# frozen_string_literal: true
class Clusters::BaseController < ApplicationController
include RoutableActions
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!
private
# We can extend to `#group_type?` in the future
def require_project_id
not_found unless project_type?
end
def project
@project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id]))
end
def repository
@repository ||= project.repository
end
def authorize_read_cluster!
access_denied! unless can?(current_user, :read_cluster, clusterable)
end
def authorize_create_cluster!
access_denied! unless can?(current_user, :create_cluster, clusterable)
end
def clusterable
project if project_type?
end
def project_type?
params[:project_id].present?
end
end
# frozen_string_literal: true
 
class Projects::ClustersController < Projects::ApplicationController
class ClustersController < Clusters::BaseController
before_action :cluster, except: [:index, :new, :create_gcp, :create_user]
before_action :authorize_read_cluster!
before_action :generate_gcp_authorize_url, only: [:new]
before_action :validate_gcp_token, only: [:new]
before_action :gcp_cluster, only: [:new]
Loading
Loading
@@ -11,6 +10,9 @@ class Projects::ClustersController < Projects::ApplicationController
before_action :authorize_update_cluster!, only: [:update]
before_action :authorize_admin_cluster!, only: [:destroy]
before_action :update_applications_status, only: [:status]
layout :determine_layout
helper_method :token_in_session
 
STATUS_POLLING_INTERVAL = 10_000
Loading
Loading
@@ -29,7 +31,7 @@ class Projects::ClustersController < Projects::ApplicationController
Gitlab::PollingInterval.set_header(response, interval: STATUS_POLLING_INTERVAL)
 
render json: ClusterSerializer
.new(project: @project, current_user: @current_user)
.new(project: project, current_user: @current_user)
.represent_status(@cluster)
end
end
Loading
Loading
@@ -105,6 +107,12 @@ class Projects::ClustersController < Projects::ApplicationController
 
private
 
def determine_layout
if project_type?
'project'
end
end
def cluster
@cluster ||= project.clusters.find(params[:id])
.present(current_user: current_user)
Loading
Loading
@@ -169,7 +177,7 @@ class Projects::ClustersController < Projects::ApplicationController
end
 
def generate_gcp_authorize_url
state = generate_session_key_redirect(new_project_cluster_path(@project).to_s)
state = generate_session_key_redirect(new_project_cluster_path(project).to_s)
 
@authorize_url = GoogleApi::CloudPlatform::Client.new(
nil, callback_google_api_auth_url,
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ module ClustersHelper
return unless show_gcp_signup_offer?
 
content_tag :section, class: 'no-animate expanded' do
render 'projects/clusters/gcp_signup_offer_banner'
render 'clusters/gcp_signup_offer_banner'
end
end
end
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