Commit 8c535095 authored by Illya Klymov's avatar Illya Klymov Committed by Stan Hu

Add import/namespaces controller

This MR adds a new, tiny `import/namespaces` controller.

This controller lists available namespaces for import. Moving this to
separate controller has following rationale:

* `namespaces` are required for each controller, provided in `import/`
  folder. They are identical, does not have any customization, etc.

* ATM `namespaces` are returned as the part of `status` in
  `base_controller`. With our intention to add pagination to `status` we
  need to move "static part of the content" (namespaces) away from part,
  which will be paginated (repos)

Related issues:

* https://gitlab.com/gitlab-org/gitlab/-/issues/233059
* https://gitlab.com/gitlab-org/gitlab/-/issues/222889
* https://gitlab.com/gitlab-org/gitlab/-/issues/27370
parent 270f0a1b
# frozen_string_literal: true
class Import::AvailableNamespacesController < ApplicationController
def index
render json: NamespaceSerializer.new.represent(current_user.manageable_groups_with_routes)
end
end
...@@ -8,6 +8,8 @@ Devise.omniauth_providers.map(&:downcase).each do |provider| ...@@ -8,6 +8,8 @@ Devise.omniauth_providers.map(&:downcase).each do |provider|
end end
namespace :import do namespace :import do
resources :available_namespaces, only: [:index], controller: :available_namespaces
resource :github, only: [:create, :new], controller: :github do resource :github, only: [:create, :new], controller: :github do
post :personal_access_token post :personal_access_token
get :status get :status
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Import::AvailableNamespacesController do
let_it_be(:user) { create(:user) }
let_it_be(:manageable_groups) { [create(:group), create(:group)] }
before do
sign_in(user)
manageable_groups.each { |group| group.add_maintainer(user) }
end
describe "GET index" do
it "returns list of available namespaces" do
unrelated_group = create(:group)
get :index
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_kind_of(Array)
response_ids = json_response.map { |n| n["id"] }
expect(response_ids).not_to include(unrelated_group.id)
expect(response_ids).to contain_exactly(*manageable_groups.map(&:id))
end
context "with an anonymous user" do
before do
sign_out(user)
end
it "redirects to sign-in page" do
get :index
expect(response).to redirect_to(new_user_session_path)
end
end
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