Commit daf40c42 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '321387-include-own-namespace-in-new-fork-form' into 'master'

Include user namespace in list of fork targets

See merge request gitlab-org/gitlab!56956
parents 0c13730b a0423551
...@@ -44,13 +44,17 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -44,13 +44,17 @@ class Projects::ForksController < Projects::ApplicationController
def new def new
respond_to do |format| respond_to do |format|
format.html do 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 @project = project
end end
format.json do format.json do
namespaces = load_namespaces_with_associations - [project.namespace] 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: { render json: {
namespaces: ForkNamespaceSerializer.new.represent(namespaces, project: project, current_user: current_user, memberships: memberships_hash) namespaces: ForkNamespaceSerializer.new.represent(namespaces, project: project, current_user: current_user, memberships: memberships_hash)
} }
...@@ -78,6 +82,10 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -78,6 +82,10 @@ class Projects::ForksController < Projects::ApplicationController
private private
def can_fork_to?(namespace)
ForkTargetsFinder.new(@project, current_user).execute.id_in(current_user.namespace).any?
end
def load_forks def load_forks
forks = ForkProjectsFinder.new( forks = ForkProjectsFinder.new(
project, project,
......
...@@ -23,7 +23,7 @@ class ForkNamespaceEntity < Grape::Entity ...@@ -23,7 +23,7 @@ class ForkNamespaceEntity < Grape::Entity
end end
expose :relative_path do |namespace| expose :relative_path do |namespace|
polymorphic_path(namespace) group_path(namespace)
end end
expose :markdown_description do |namespace| expose :markdown_description do |namespace|
......
...@@ -103,6 +103,11 @@ module EE ...@@ -103,6 +103,11 @@ module EE
before_save :clear_feature_available_cache before_save :clear_feature_available_cache
end end
# Only groups can be marked for deletion
def marked_for_deletion?
false
end
def namespace_limit def namespace_limit
limit = has_parent? ? root_ancestor.namespace_limit : super limit = has_parent? ? root_ancestor.namespace_limit : super
......
...@@ -153,8 +153,11 @@ RSpec.describe Projects::ForksController do ...@@ -153,8 +153,11 @@ RSpec.describe Projects::ForksController do
end end
describe 'GET new' do describe 'GET new' do
subject do let(:format) { :html }
subject(:do_request) do
get :new, get :new,
format: format,
params: { params: {
namespace_id: project.namespace, namespace_id: project.namespace,
project_id: project project_id: project
...@@ -166,24 +169,32 @@ RSpec.describe Projects::ForksController do ...@@ -166,24 +169,32 @@ RSpec.describe Projects::ForksController do
sign_in(user) sign_in(user)
end end
context 'when JSON requested' do it 'responds with status 200' do
it 'responds with available groups' do request
get :new,
format: :json,
params: {
namespace_id: project.namespace,
project_id: project
}
expect(json_response['namespaces'].length).to eq(1) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['namespaces'].first['id']).to eq(group.id)
end end
context 'when JSON is requested' do
let(:format) { :json }
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 end
it 'responds with status 200' do it 'responds with group only when fork_project_form feature flag is disabled' do
subject stub_feature_flags(fork_project_form: false)
do_request
expect(response).to have_gitlab_http_status(:ok) 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
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