Commit 593c8370 authored by Gabriel Mazetto's avatar Gabriel Mazetto Committed by Douglas Barbosa Alexandre

Geo: Refactor Admin controllers to use Geo specific namespace

parent 03fe66c4
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
.sidebar-context-title .sidebar-context-title
= _('Admin Area') = _('Admin Area')
%ul.sidebar-top-level-items %ul.sidebar-top-level-items
= nav_link(controller: %w(dashboard admin projects users groups jobs runners gitaly_servers), html_options: {class: 'home'}) do = nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers), html_options: {class: 'home'}) do
= link_to admin_root_path, class: 'shortcuts-tree' do = link_to admin_root_path, class: 'shortcuts-tree' do
.nav-icon-container .nav-icon-container
= sprite_icon('overview') = sprite_icon('overview')
%span.nav-item-name %span.nav-item-name
= _('Overview') = _('Overview')
%ul.sidebar-sub-level-items %ul.sidebar-sub-level-items
= nav_link(controller: %w(dashboard admin projects users groups jobs runners gitaly_servers), html_options: { class: "fly-out-top-item" } ) do = nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers), html_options: { class: "fly-out-top-item" } ) do
= link_to admin_root_path do = link_to admin_root_path do
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
= _('Overview') = _('Overview')
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
= link_to admin_root_path, title: _('Overview') do = link_to admin_root_path, title: _('Overview') do
%span %span
= _('Dashboard') = _('Dashboard')
= nav_link(controller: [:admin, :projects]) do = nav_link(controller: [:admin, 'admin/projects']) do
= link_to admin_projects_path, title: _('Projects') do = link_to admin_projects_path, title: _('Projects') do
%span %span
= _('Projects') = _('Projects')
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
#{ _('Push Rules') } #{ _('Push Rules') }
= nav_link(controller: [:geo_nodes, :geo_projects]) do = nav_link(controller: %w(admin/geo/nodes admin/geo/projects)) do
= link_to admin_geo_nodes_path do = link_to admin_geo_nodes_path do
.nav-icon-container .nav-icon-container
= sprite_icon('location-dot') = sprite_icon('location-dot')
...@@ -178,16 +178,16 @@ ...@@ -178,16 +178,16 @@
#{ _('Geo Nodes') } #{ _('Geo Nodes') }
- if Gitlab::Geo.secondary? - if Gitlab::Geo.secondary?
%ul.sidebar-sub-level-items %ul.sidebar-sub-level-items
= nav_link(controller: :geo_nodes, html_options: { class: "fly-out-top-item" } ) do = nav_link(controller: 'admin/geo/nodes', html_options: { class: "fly-out-top-item" } ) do
= link_to admin_geo_nodes_path do = link_to admin_geo_nodes_path do
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
#{ _('Geo Nodes') } #{ _('Geo Nodes') }
%li.divider.fly-out-top-item %li.divider.fly-out-top-item
= nav_link(path: 'geo_nodes#index') do = nav_link(path: 'admin/geo/nodes#index') do
= link_to admin_geo_nodes_path, title: 'Nodes' do = link_to admin_geo_nodes_path, title: 'Nodes' do
%span %span
#{ _('Nodes') } #{ _('Nodes') }
= nav_link(path: 'geo_projects#index') do = nav_link(path: 'admin/geo/projects#index') do
= link_to admin_geo_projects_path, title: 'Projects' do = link_to admin_geo_projects_path, title: 'Projects' do
%span %span
#{ _('Projects') } #{ _('Projects') }
......
...@@ -132,15 +132,17 @@ namespace :admin do ...@@ -132,15 +132,17 @@ namespace :admin do
get :download, on: :member get :download, on: :member
end end
resources :geo_nodes, only: [:index, :create, :new, :edit, :update] namespace :geo do
resources :nodes, only: [:index, :create, :new, :edit, :update]
resources :geo_projects, only: [:index] do resources :projects, only: :index do
member do member do
post :recheck post :recheck
post :resync post :resync
post :force_redownload post :force_redownload
end end
end end
end
get '/dashboard/stats', to: 'dashboard#stats' get '/dashboard/stats', to: 'dashboard#stats'
## EE-specific ## EE-specific
......
class Admin::GeoNodesController < Admin::ApplicationController # frozen_string_literal: true
class Admin::Geo::NodesController < Admin::ApplicationController
before_action :check_license, except: :index before_action :check_license, except: :index
before_action :load_node, only: [:edit, :update] before_action :load_node, only: [:edit, :update]
......
# frozen_string_literal: true # frozen_string_literal: true
class Admin::GeoProjectsController < Admin::ApplicationController class Admin::Geo::ProjectsController < Admin::ApplicationController
before_action :check_license before_action :check_license
before_action :load_registry, except: [:index] before_action :load_registry, except: [:index]
......
- page_title 'Geo nodes' - page_title 'Geo Nodes'
- @content_class = "geo-admin-container" - @content_class = "geo-admin-container"
%h2.page-title.clearfix %h2.page-title.clearfix
......
- page_title 'Projects' - page_title 'Geo Projects'
- @no_container = true - @no_container = true
- @content_class = "geo-admin-container geo-admin-projects" - @content_class = "geo-admin-container geo-admin-projects"
- params[:sync_status] ||= [] - params[:sync_status] ||= []
......
...@@ -6,11 +6,11 @@ module EE ...@@ -6,11 +6,11 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
WHITELISTED_GEO_ROUTES = { WHITELISTED_GEO_ROUTES = {
'admin/geo_nodes' => %w{update} 'admin/geo/nodes' => %w{update}
}.freeze }.freeze
WHITELISTED_GEO_ROUTES_TRACKING_DB = { WHITELISTED_GEO_ROUTES_TRACKING_DB = {
'admin/geo_projects' => %w{resync recheck force_redownload} 'admin/geo/projects' => %w{resync recheck force_redownload}
}.freeze }.freeze
private private
...@@ -22,7 +22,7 @@ module EE ...@@ -22,7 +22,7 @@ module EE
def geo_node_update_route def geo_node_update_route
# Calling route_hash may be expensive. Only do it if we think there's a possible match # Calling route_hash may be expensive. Only do it if we think there's a possible match
return false unless request.path =~ %r{/admin/geo_} return false unless request.path.start_with?('/admin/geo/')
controller = route_hash[:controller] controller = route_hash[:controller]
action = route_hash[:action] action = route_hash[:action]
...@@ -36,8 +36,8 @@ module EE ...@@ -36,8 +36,8 @@ module EE
def geo_proxy_git_push_ssh_route def geo_proxy_git_push_ssh_route
routes = ::Gitlab::Middleware::ReadOnly::API_VERSIONS.map do |version| routes = ::Gitlab::Middleware::ReadOnly::API_VERSIONS.map do |version|
["/api/v#{version}/geo/proxy_git_push_ssh/info_refs", %W(/api/v#{version}/geo/proxy_git_push_ssh/info_refs
"/api/v#{version}/geo/proxy_git_push_ssh/push"] /api/v#{version}/geo/proxy_git_push_ssh/push)
end end
routes.flatten.include?(request.path) routes.flatten.include?(request.path)
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Admin::GeoNodesController, :postgresql do describe Admin::Geo::NodesController, :postgresql do
shared_examples 'unlicensed geo action' do shared_examples 'unlicensed geo action' do
it 'redirects to the license page' do it 'redirects to the license page' do
expect(response).to redirect_to(admin_license_path) expect(response).to redirect_to(admin_license_path)
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Admin::GeoProjectsController, :geo do describe Admin::Geo::ProjectsController, :geo do
set(:admin) { create(:admin) } set(:admin) { create(:admin) }
let(:synced_registry) { create(:geo_project_registry, :synced) } let(:synced_registry) { create(:geo_project_registry, :synced) }
......
...@@ -3,7 +3,7 @@ export const PRIMARY_VERSION = { ...@@ -3,7 +3,7 @@ export const PRIMARY_VERSION = {
revision: 'b93c51849b', revision: 'b93c51849b',
}; };
export const NODE_DETAILS_PATH = '/admin/geo_nodes'; export const NODE_DETAILS_PATH = '/admin/geo/nodes';
export const mockNodes = [ export const mockNodes = [
{ {
...@@ -19,7 +19,7 @@ export const mockNodes = [ ...@@ -19,7 +19,7 @@ export const mockNodes = [
self: 'http://127.0.0.1:3001/api/v4/geo_nodes/1', self: 'http://127.0.0.1:3001/api/v4/geo_nodes/1',
repair: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/repair', repair: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/repair',
status: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/status', status: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/status',
web_edit: 'http://127.0.0.1:3001/admin/geo_nodes/1/edit', web_edit: 'http://127.0.0.1:3001/admin/geo/nodes/1/edit',
}, },
}, },
{ {
...@@ -35,7 +35,7 @@ export const mockNodes = [ ...@@ -35,7 +35,7 @@ export const mockNodes = [
self: 'http://127.0.0.1:3001/api/v4/geo_nodes/2', self: 'http://127.0.0.1:3001/api/v4/geo_nodes/2',
repair: 'http://127.0.0.1:3001/api/v4/geo_nodes/2/repair', repair: 'http://127.0.0.1:3001/api/v4/geo_nodes/2/repair',
status: 'http://127.0.0.1:3001/api/v4/geo_nodes/2/status', status: 'http://127.0.0.1:3001/api/v4/geo_nodes/2/status',
web_edit: 'http://127.0.0.1:3001/admin/geo_nodes/2/edit', web_edit: 'http://127.0.0.1:3001/admin/geo/nodes/2/edit',
}, },
}, },
]; ];
...@@ -50,7 +50,7 @@ export const mockNode = { ...@@ -50,7 +50,7 @@ export const mockNode = {
basePath: 'http://127.0.0.1:3001/api/v4/geo_nodes/1', basePath: 'http://127.0.0.1:3001/api/v4/geo_nodes/1',
repairPath: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/repair', repairPath: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/repair',
statusPath: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/status', statusPath: 'http://127.0.0.1:3001/api/v4/geo_nodes/1/status',
editPath: 'http://127.0.0.1:3001/admin/geo_nodes/1/edit', editPath: 'http://127.0.0.1:3001/admin/geo/nodes/1/edit',
}; };
export const rawMockNodeDetails = { export const rawMockNodeDetails = {
......
...@@ -44,7 +44,7 @@ describe Gitlab::Middleware::ReadOnly do ...@@ -44,7 +44,7 @@ describe Gitlab::Middleware::ReadOnly do
context 'whitelisted requests' do context 'whitelisted requests' do
it 'expects a PATCH request to geo_nodes update URL to be allowed' do it 'expects a PATCH request to geo_nodes update URL to be allowed' do
expect(Rails.application.routes).to receive(:recognize_path).and_call_original expect(Rails.application.routes).to receive(:recognize_path).and_call_original
response = request.patch('/admin/geo_nodes/1') response = request.patch('/admin/geo/nodes/1')
expect(response).not_to be_redirect expect(response).not_to be_redirect
expect(subject).not_to disallow_request expect(subject).not_to disallow_request
......
...@@ -34,7 +34,7 @@ describe API::GeoNodes, :geo, :prometheus, api: true do ...@@ -34,7 +34,7 @@ describe API::GeoNodes, :geo, :prometheus, api: true do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node', dir: 'ee') expect(response).to match_response_schema('public_api/v4/geo_node', dir: 'ee')
expect(json_response['web_edit_url']).to end_with("/admin/geo_nodes/#{primary.id}/edit") expect(json_response['web_edit_url']).to end_with("/admin/geo/nodes/#{primary.id}/edit")
links = json_response['_links'] links = json_response['_links']
expect(links['self']).to end_with("/api/v4/geo_nodes/#{primary.id}") expect(links['self']).to end_with("/api/v4/geo_nodes/#{primary.id}")
......
...@@ -2,23 +2,47 @@ ...@@ -2,23 +2,47 @@
require 'spec_helper' require 'spec_helper'
describe 'EE-specific admin routing' do describe 'EE-specific admin routing' do
describe Admin::GeoProjectsController, 'routing' do describe Admin::Geo::ProjectsController, 'routing' do
let(:project_registry) { create(:geo_project_registry) } let(:project_registry) { create(:geo_project_registry) }
it 'routes ../ to #index' do it 'routes / to #index' do
expect(get('/admin/geo_projects')).to route_to('admin/geo_projects#index') expect(get('/admin/geo/projects')).to route_to('admin/geo/projects#index')
end end
it 'routes ../:id/recheck to #recheck' do it 'routes /:id/recheck to #recheck' do
expect(post("admin/geo_projects/#{project_registry.id}/recheck")).to route_to('admin/geo_projects#recheck', id: project_registry.id.to_s) expect(post("admin/geo/projects/#{project_registry.id}/recheck")).to route_to('admin/geo/projects#recheck', id: project_registry.to_param)
end end
it 'routes ../id:/resync to #resync' do it 'routes /id:/resync to #resync' do
expect(post("admin/geo_projects/#{project_registry.id}/resync")).to route_to('admin/geo_projects#resync', id: project_registry.id.to_s) expect(post("admin/geo/projects/#{project_registry.id}/resync")).to route_to('admin/geo/projects#resync', id: project_registry.to_param)
end end
it 'routes ../id:/force_redownload to #force_redownload' do it 'routes /id:/force_redownload to #force_redownload' do
expect(post("admin/geo_projects/#{project_registry.id}/force_redownload")).to route_to('admin/geo_projects#force_redownload', id: project_registry.id.to_s) expect(post("admin/geo/projects/#{project_registry.id}/force_redownload")).to route_to('admin/geo/projects#force_redownload', id: project_registry.to_param)
end
end
describe Admin::Geo::NodesController, 'routing' do
let(:geo_node) { create(:geo_node) }
it 'routes / to #index' do
expect(get('/admin/geo/nodes')).to route_to('admin/geo/nodes#index')
end
it 'routes /new to #new' do
expect(get('/admin/geo/nodes/new')).to route_to('admin/geo/nodes#new')
end
it 'routes /edit to #edit' do
expect(get("/admin/geo/nodes/#{geo_node.id}/edit")).to route_to('admin/geo/nodes#edit', id: geo_node.to_param)
end
it 'routes post / to #create' do
expect(post('/admin/geo/nodes/')).to route_to('admin/geo/nodes#create')
end
it 'routes patch /:id to #update' do
expect(patch("/admin/geo/nodes/#{geo_node.id}")).to route_to('admin/geo/nodes#update', id: geo_node.to_param)
end end
end end
end end
...@@ -5,12 +5,12 @@ module QA ...@@ -5,12 +5,12 @@ module QA
module Geo module Geo
module Nodes module Nodes
class New < QA::Page::Base class New < QA::Page::Base
view 'ee/app/views/admin/geo_nodes/_form.html.haml' do view 'ee/app/views/admin/geo/nodes/_form.html.haml' do
element :node_url_field, 'text_field :url' element :node_url_field, 'text_field :url'
element :node_url_placeholder, "label :url, 'URL'" element :node_url_placeholder, "label :url, 'URL'"
end end
view 'ee/app/views/admin/geo_nodes/new.html.haml' do view 'ee/app/views/admin/geo/nodes/new.html.haml' do
element :add_node_button, "submit 'Add Node'" element :add_node_button, "submit 'Add Node'"
end end
......
...@@ -5,7 +5,7 @@ module QA ...@@ -5,7 +5,7 @@ module QA
module Geo module Geo
module Nodes module Nodes
class Show < QA::Page::Base class Show < QA::Page::Base
view 'ee/app/views/admin/geo_nodes/index.html.haml' do view 'ee/app/views/admin/geo/nodes/index.html.haml' do
element :new_node_link, /link_to .*New node/ element :new_node_link, /link_to .*New node/
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