Commit a0423551 authored by Nick Thomas's avatar Nick Thomas

Include user namespace in list of fork targets

With the fork_project_form feature flag enabled, we don't pay any
attention to the `@own_namespace` instance variable, instead expecting
to get the full list of namespaces we can fork to in the JSON payload
given by Projects::ForksController#new

Adding `@own_namespace` to that json payload allows us to render it
without any special handling. It does mean that we now have a mixed
array of Namespace and Group, so a few Group-specific things need to
be supported by Namespace.
parent dd243953
......@@ -44,13 +44,17 @@ class Projects::ForksController < Projects::ApplicationController
def new
respond_to do |format|
format.html do
@own_namespace = current_user.namespace if fork_service.valid_fork_targets.include?(current_user.namespace)
@own_namespace = current_user.namespace if can_fork_to?(current_user.namespace)
@project = project
end
format.json do
namespaces = load_namespaces_with_associations - [project.namespace]
namespaces = [current_user.namespace] + namespaces if
Feature.enabled?(:fork_project_form, project, default_enabled: :yaml) &&
can_fork_to?(current_user.namespace)
render json: {
namespaces: ForkNamespaceSerializer.new.represent(namespaces, project: project, current_user: current_user, memberships: memberships_hash)
}
......@@ -78,6 +82,10 @@ class Projects::ForksController < Projects::ApplicationController
private
def can_fork_to?(namespace)
ForkTargetsFinder.new(@project, current_user).execute.id_in(current_user.namespace).any?
end
def load_forks
forks = ForkProjectsFinder.new(
project,
......
......@@ -23,7 +23,7 @@ class ForkNamespaceEntity < Grape::Entity
end
expose :relative_path do |namespace|
polymorphic_path(namespace)
group_path(namespace)
end
expose :markdown_description do |namespace|
......
......@@ -103,6 +103,11 @@ module EE
before_save :clear_feature_available_cache
end
# Only groups can be marked for deletion
def marked_for_deletion?
false
end
def namespace_limit
limit = has_parent? ? root_ancestor.namespace_limit : super
......
......@@ -153,8 +153,11 @@ RSpec.describe Projects::ForksController do
end
describe 'GET new' do
subject do
let(:format) { :html }
subject(:do_request) do
get :new,
format: format,
params: {
namespace_id: project.namespace,
project_id: project
......@@ -166,24 +169,32 @@ RSpec.describe Projects::ForksController do
sign_in(user)
end
context 'when JSON requested' do
it 'responds with available groups' do
get :new,
format: :json,
params: {
namespace_id: project.namespace,
project_id: project
}
it 'responds with status 200' do
request
expect(json_response['namespaces'].length).to eq(1)
expect(json_response['namespaces'].first['id']).to eq(group.id)
end
expect(response).to have_gitlab_http_status(:ok)
end
it 'responds with status 200' do
subject
context 'when JSON is requested' do
let(:format) { :json }
expect(response).to have_gitlab_http_status(:ok)
it 'responds with user namespace + groups' do
do_request
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['namespaces'].length).to eq(2)
expect(json_response['namespaces'][0]['id']).to eq(user.namespace.id)
expect(json_response['namespaces'][1]['id']).to eq(group.id)
end
it 'responds with group only when fork_project_form feature flag is disabled' do
stub_feature_flags(fork_project_form: false)
do_request
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['namespaces'].length).to eq(1)
expect(json_response['namespaces'][0]['id']).to eq(group.id)
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