BigW Consortium Gitlab

Commit cf8b465c by Dmitriy Zaporozhets

Remove Global namespace from options. Prepared file for migration of global projects

parent 6e35acef
......@@ -33,7 +33,7 @@ module Projects
# Find matching namespace and check if it allowed
# for current user if namespace_id passed.
if allowed_namespace?(current_user, namespace_id)
@project.namespace_id = namespace_id unless namespace_id == Namespace.global_id
@project.namespace_id = namespace_id
else
deny_namespace
return @project
......@@ -75,12 +75,8 @@ module Projects
end
def allowed_namespace?(user, namespace_id)
if namespace_id == Namespace.global_id
return user.admin
else
namespace = Namespace.find_by_id(namespace_id)
current_user.can?(:manage_namespace, namespace)
end
namespace = Namespace.find_by_id(namespace_id)
current_user.can?(:manage_namespace, namespace)
end
end
end
......@@ -5,12 +5,7 @@ module Projects
allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin
if allowed_transfer && namespace_id.present?
if namespace_id == Namespace.global_id
if project.namespace.present?
# Transfer to global namespace from anyone
project.transfer(nil)
end
elsif namespace_id.to_i != project.namespace_id
if namespace_id.to_i != project.namespace_id
# Transfer to someone namespace
namespace = Namespace.find(namespace_id)
project.transfer(namespace)
......
......@@ -9,7 +9,6 @@ class Admin::ProjectsController < Admin::ApplicationController
@projects = @projects.where(public: true) if params[:public_only].present?
@projects = @projects.with_push if params[:with_push].present?
@projects = @projects.abandoned if params[:abandoned].present?
@projects = @projects.where(namespace_id: nil) if params[:namespace_id] == Namespace.global_id
@projects = @projects.search(params[:name]) if params[:name].present?
@projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
end
......
......@@ -3,7 +3,6 @@ module NamespacesHelper
groups = current_user.owned_groups.select {|n| n.type == 'Group'}
users = current_user.namespaces.reject {|n| n.type == 'Group'}
global_opts = ["Global", [['/', Namespace.global_id]] ]
group_opts = ["Groups", groups.sort_by(&:human_name).map {|g| [g.human_name, g.id]} ]
users_opts = [ "Users", users.sort_by(&:human_name).map {|u| [u.human_name, u.id]} ]
......
......@@ -129,7 +129,7 @@
%span Namespace
.controls
.clearfix
= f.select :namespace_id, namespaces_options(@project.namespace_id || Namespace::global_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'}
= f.select :namespace_id, namespaces_options(@project.namespace_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'}
%ul
%li Be careful. Changing project namespace can have unintended side effects
%li You can transfer project only to namespaces you can manage
......
desc "GITLAB | Migrate Global Projects to Namespaces"
task migrate_global_projects: :environment do
puts "This will move all projects without namespace to owner namespace"
ask_to_continue
Project.where(namespace_id: nil).find_each(batch_size: 20) do |project|
# TODO: transfer code here
print '.'
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