Commit f6a5eae4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'mk/dry-up-geo-for-frontend' into 'master'

Geo: Generalize replicables route, controller, view, and index.js

Closes #219315

See merge request gitlab-org/gitlab!35443
parents 41017301 a05cefec
# frozen_string_literal: true
class Admin::Geo::PackageFilesController < Admin::Geo::ApplicationController
before_action :check_license!
def index
end
end
# frozen_string_literal: true
class Admin::Geo::ReplicablesController < Admin::Geo::ApplicationController
before_action :check_license!
before_action :set_replicator_class, only: :index
def index
end
def set_replicator_class
replicable_name = params[:replicable_name_plural].singularize
@replicator_class = Gitlab::Geo::Replicator.for_replicable_name(replicable_name)
rescue NotImplementedError
render_404
end
end
= render "admin/geo/shared/replication_nav"
- if Feature.enabled?(:geo_self_service_framework)
#js-geo-replicable{ data: { "geo-replicable-empty-svg-path" => image_path("illustrations/empty-state/geo-replication-empty.svg"),
"geo-troubleshooting-link" => help_page_path("administration/geo/replication/troubleshooting.md"),
"replicable-type" => "package_files",
"graphql-field-name" => 'packageFileRegistries'} }
= render "admin/geo/shared/replication_nav"
#js-geo-replicable{ data: { "geo-replicable-empty-svg-path" => image_path("illustrations/empty-state/geo-replication-empty.svg"),
"geo-troubleshooting-link" => help_page_path("administration/geo/replication/troubleshooting.html"),
"replicable-type" => @replicator_class.replicable_name_plural,
"graphql-field-name" => @replicator_class.graphql_field_name } }
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
= link_to admin_geo_designs_path, title: _('Designs') do = link_to admin_geo_designs_path, title: _('Designs') do
%span %span
= _('Designs') = _('Designs')
= nav_link(path: 'admin/geo/package_files#index', html_options: { class: 'gl-pr-2' }) do - if Feature.enabled?(:geo_self_service_framework)
= link_to admin_geo_package_files_path, title: _('Package Files') do - Gitlab::Geo.replicator_classes.each do |replicator_class|
= nav_link(page: [{ controller: 'admin/geo/replicables', action: 'index', replicable_name_plural: replicator_class.replicable_name_plural }], html_options: { class: 'gl-pr-2' }) do
= link_to admin_geo_replicables_path(replicable_name_plural: replicator_class.replicable_name_plural), title: replicator_class.replicable_title_plural do
%span %span
= _('Package Files') = replicator_class.replicable_title_plural
= nav_link(controller: %w(admin/geo/nodes admin/geo/projects admin/geo/uploads admin/geo/settings admin/geo/designs admin/geo/package_files)) do = nav_link(controller: %w(admin/geo/nodes admin/geo/projects admin/geo/uploads admin/geo/settings admin/geo/designs admin/geo/replicables)) do
= link_to admin_geo_nodes_path, class: "qa-link-geo-menu" do = link_to admin_geo_nodes_path, class: "qa-link-geo-menu" do
.nav-icon-container .nav-icon-container
= sprite_icon('location-dot') = sprite_icon('location-dot')
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
%span %span
= _('Nodes') = _('Nodes')
- if Gitlab::Geo.secondary? - if Gitlab::Geo.secondary?
= nav_link(controller: %w(admin/geo/projects admin/geo/uploads admin/geo/designs admin/geo/package_files)) do = nav_link(controller: %w(admin/geo/projects admin/geo/uploads admin/geo/designs admin/geo/replicables)) do
= link_to admin_geo_projects_path, title: _('Replication') do = link_to admin_geo_projects_path, title: _('Replication') do
%span %span
= _('Replication') = _('Replication')
......
...@@ -78,7 +78,7 @@ module Geo ...@@ -78,7 +78,7 @@ module Geo
end end
def replicator_classes def replicator_classes
Gitlab::Geo::ReplicableModel.replicators Gitlab::Geo.replicator_classes
end end
end end
end end
...@@ -60,9 +60,10 @@ namespace :admin do ...@@ -60,9 +60,10 @@ namespace :admin do
end end
resources :designs, only: [:index] resources :designs, only: [:index]
resources :package_files, only: [:index]
resources :uploads, only: [:index, :destroy] resources :uploads, only: [:index, :destroy]
get '/:replicable_name_plural', to: 'replicables#index', as: 'replicables'
end end
resource :settings, only: [:show, :update] resource :settings, only: [:show, :update]
......
...@@ -157,5 +157,12 @@ module Gitlab ...@@ -157,5 +157,12 @@ module Gitlab
_(template) % { url: url } _(template) % { url: url }
end end
# TODO: Avoid having to maintain a list. Discussions related to possible
# solutions can be found at
# https://gitlab.com/gitlab-org/gitlab/-/issues/227693
def self.replicator_classes
[::Geo::PackageFileReplicator]
end
end end
end end
...@@ -25,8 +25,6 @@ module Gitlab ...@@ -25,8 +25,6 @@ module Gitlab
def with_replicator(klass) def with_replicator(klass)
raise ArgumentError, 'Must be a class inheriting from Gitlab::Geo::Replicator' unless klass < ::Gitlab::Geo::Replicator raise ArgumentError, 'Must be a class inheriting from Gitlab::Geo::Replicator' unless klass < ::Gitlab::Geo::Replicator
Gitlab::Geo::ReplicableModel.add_replicator(klass)
class_eval <<-RUBY, __FILE__, __LINE__ + 1 class_eval <<-RUBY, __FILE__, __LINE__ + 1
define_method :replicator do define_method :replicator do
@_replicator ||= klass.new(model_record: self) @_replicator ||= klass.new(model_record: self)
...@@ -39,16 +37,6 @@ module Gitlab ...@@ -39,16 +37,6 @@ module Gitlab
end end
end end
def self.add_replicator(klass)
@_replicators ||= []
@_replicators << klass
end
def self.replicators
@_replicators ||= []
@_replicators.filter { |replicator| const_defined?(replicator.to_s) }
end
# Geo Replicator # Geo Replicator
# #
# @abstract # @abstract
......
...@@ -54,10 +54,10 @@ module Gitlab ...@@ -54,10 +54,10 @@ module Gitlab
@events.include?(event_name.to_sym) @events.include?(event_name.to_sym)
end end
# Return the name of the replicable, e.g. "package_file" # Return the canonical name of the replicable, e.g. "package_file".
# #
# This can be used to retrieve the replicator class again # This can be used to retrieve the replicator class again
# by using the `.for_replicable_name` method # by using the `.for_replicable_name` method.
# #
# @see .for_replicable_name # @see .for_replicable_name
# @return [String] slug that identifies this replicator # @return [String] slug that identifies this replicator
...@@ -65,6 +65,29 @@ module Gitlab ...@@ -65,6 +65,29 @@ module Gitlab
self.name.demodulize.sub('Replicator', '').underscore self.name.demodulize.sub('Replicator', '').underscore
end end
# Return the pluralized replicable name, e.g. "package_files". In general,
# it is preferable to use the canonical replicable_name if possible.
#
# @return [String] slug that identifies this replicator, pluralized
def self.replicable_name_plural
self.replicable_name.pluralize
end
# @return [String] human-readable title of this replicator. E.g. "Package File"
def self.replicable_title
self.replicable_name.titleize
end
# @return [String] human-readable title of this replicator, pluralized. E.g. "Package Files"
def self.replicable_title_plural
self.replicable_name.pluralize.titleize
end
# @return [String] GraphQL registries field name. E.g. "packageFileRegistries"
def self.graphql_field_name
"#{self.replicable_name.camelize(:lower)}Registries"
end
# Return the registry related to the replicable resource # Return the registry related to the replicable resource
# #
# @return [Class<Geo::BaseRegistry>] registry class # @return [Class<Geo::BaseRegistry>] registry class
......
...@@ -44,9 +44,11 @@ RSpec.describe 'admin Geo Replication Nav', :js, :geo do ...@@ -44,9 +44,11 @@ RSpec.describe 'admin Geo Replication Nav', :js, :geo do
end end
end end
describe 'visit admin/geo/replication/package_files' do describe 'visit admin/geo/replication/*' do
it_behaves_like 'active sidebar link', 'Package Files' do Gitlab::Geo.replicator_classes.each do |replicator_class|
let(:path) { admin_geo_package_files_path } it_behaves_like 'active sidebar link', replicator_class.replicable_title_plural do
let(:path) { admin_geo_replicables_path(replicable_name_plural: replicator_class.replicable_name_plural) }
end
end end
end end
end end
...@@ -64,9 +64,11 @@ RSpec.describe 'admin Geo Sidebar', :js, :geo do ...@@ -64,9 +64,11 @@ RSpec.describe 'admin Geo Sidebar', :js, :geo do
end end
end end
describe 'visiting geo package files' do describe 'visiting geo replicables' do
Gitlab::Geo.replicator_classes.each do |replicator_class|
it_behaves_like 'active sidebar link', 'Replication' do it_behaves_like 'active sidebar link', 'Replication' do
let(:path) { admin_geo_package_files_path } let(:path) { admin_geo_replicables_path(replicable_name_plural: replicator_class.replicable_name_plural) }
end
end end
end end
end end
......
...@@ -335,4 +335,13 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do ...@@ -335,4 +335,13 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do
expect(described_class.interacting_with_primary_message(url)).to eq(message) expect(described_class.interacting_with_primary_message(url)).to eq(message)
end end
end end
describe '.replicator_classes' do
it 'returns an Array of replicator classes' do
result = described_class.replicator_classes
expect(result).to be_an(Array)
expect(result).to include(Geo::PackageFileReplicator)
end
end
end end
...@@ -44,9 +44,11 @@ RSpec.describe 'EE-specific admin routing' do ...@@ -44,9 +44,11 @@ RSpec.describe 'EE-specific admin routing' do
end end
end end
describe Admin::Geo::PackageFilesController, 'routing' do describe Admin::Geo::ReplicablesController, 'routing' do
it 'routes / to #index' do Gitlab::Geo.replicator_classes.map(&:replicable_name_plural).each do |replicable_name_plural|
expect(get('/admin/geo/replication/package_files')).to route_to('admin/geo/package_files#index') it "routes /admin/geo/replication/#{replicable_name_plural} to replicables#index" do
expect(get("/admin/geo/replication/#{replicable_name_plural}")).to route_to('admin/geo/replicables#index', replicable_name_plural: replicable_name_plural)
end
end end
end end
......
...@@ -16260,9 +16260,6 @@ msgstr "" ...@@ -16260,9 +16260,6 @@ msgstr ""
msgid "Owner" msgid "Owner"
msgstr "" msgstr ""
msgid "Package Files"
msgstr ""
msgid "Package Registry" msgid "Package Registry"
msgstr "" msgstr ""
......
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