2012-11-29 05:29:11 +01:00
|
|
|
class ProjectUpdateContext < BaseContext
|
|
|
|
def execute(role = :default)
|
|
|
|
namespace_id = params[:project].delete(:namespace_id)
|
|
|
|
|
2012-12-04 21:48:24 +01:00
|
|
|
allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin
|
|
|
|
|
|
|
|
if allowed_transfer && namespace_id.present?
|
2012-11-29 05:29:11 +01:00
|
|
|
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
|
|
|
|
# Transfer to someone namespace
|
|
|
|
namespace = Namespace.find(namespace_id)
|
|
|
|
project.transfer(namespace)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
project.update_attributes(params[:project], as: role)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|