Select namespace where to fork project
Now you can fork project into group or personal namespace. Also I moved fork logic from ProjectsController to own fork resource Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
18c8226566
commit
e08e405ac4
8 changed files with 78 additions and 41 deletions
22
app/controllers/projects/forks_controller.rb
Normal file
22
app/controllers/projects/forks_controller.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Projects::ForksController < Projects::ApplicationController
|
||||
# Authorize
|
||||
before_filter :authorize_download_code!
|
||||
before_filter :require_non_empty_project
|
||||
|
||||
def new
|
||||
@namespaces = current_user.manageable_namespaces
|
||||
@namespaces.delete(@project.namespace)
|
||||
end
|
||||
|
||||
def create
|
||||
namespace = Namespace.find(params[:namespace_id])
|
||||
@forked_project = ::Projects::ForkService.new(project, current_user, namespace: namespace).execute
|
||||
|
||||
if @forked_project.saved? && @forked_project.forked?
|
||||
redirect_to(@forked_project, notice: 'Project was successfully forked.')
|
||||
else
|
||||
@title = 'Fork project'
|
||||
render :error
|
||||
end
|
||||
end
|
||||
end
|
|
@ -111,22 +111,6 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def fork
|
||||
@forked_project = ::Projects::ForkService.new(project, current_user).execute
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
if @forked_project.saved? && @forked_project.forked?
|
||||
redirect_to(@forked_project, notice: 'Project was successfully forked.')
|
||||
else
|
||||
@title = 'Fork project'
|
||||
render "fork"
|
||||
end
|
||||
end
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete_sources
|
||||
note_type = params['type']
|
||||
note_id = params['type_id']
|
||||
|
|
|
@ -551,4 +551,14 @@ class User < ActiveRecord::Base
|
|||
UsersStarProject.create!(project: project, user: self)
|
||||
end
|
||||
end
|
||||
|
||||
def manageable_namespaces
|
||||
@manageable_namespaces ||=
|
||||
begin
|
||||
namespaces = []
|
||||
namespaces << namespace
|
||||
namespaces += owned_groups
|
||||
namespaces += masters_groups
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
= link_to project_path(current_user.fork_of(@project)), title: 'Go to my fork' do
|
||||
= link_to_toggle_fork
|
||||
- else
|
||||
= link_to fork_project_path(@project), title: "Fork project", method: "POST" do
|
||||
= link_to new_project_fork_path(@project), title: "Fork project" do
|
||||
= link_to_toggle_fork
|
||||
|
||||
.star-buttons
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
.alert.alert-danger.alert-block
|
||||
%h4
|
||||
%i.fa.fa-code-fork
|
||||
Fork Error!
|
||||
%p
|
||||
You tried to fork
|
||||
= link_to_project @project
|
||||
but it failed for the following reason:
|
||||
|
||||
|
||||
- if @forked_project && @forked_project.errors.any?
|
||||
%p
|
||||
–
|
||||
= @forked_project.errors.full_messages.first
|
||||
|
||||
%p
|
||||
= link_to fork_project_path(@project), title: "Fork", class: "btn", method: "POST" do
|
||||
%i.fa.fa-code-fork
|
||||
Try to Fork again
|
20
app/views/projects/forks/error.html.haml
Normal file
20
app/views/projects/forks/error.html.haml
Normal file
|
@ -0,0 +1,20 @@
|
|||
- if @forked_project && !@forked_project.saved?
|
||||
.alert.alert-danger.alert-block
|
||||
%h4
|
||||
%i.fa.fa-code-fork
|
||||
Fork Error!
|
||||
%p
|
||||
You tried to fork
|
||||
= link_to_project @project
|
||||
but it failed for the following reason:
|
||||
|
||||
|
||||
- if @forked_project && @forked_project.errors.any?
|
||||
%p
|
||||
–
|
||||
= @forked_project.errors.full_messages.first
|
||||
|
||||
%p
|
||||
= link_to new_project_fork_path(@project), title: "Fork", class: "btn" do
|
||||
%i.fa.fa-code-fork
|
||||
Try to Fork again
|
19
app/views/projects/forks/new.html.haml
Normal file
19
app/views/projects/forks/new.html.haml
Normal file
|
@ -0,0 +1,19 @@
|
|||
%h3.page-title Fork project
|
||||
%p.lead Select namespace where to fork this project
|
||||
%hr
|
||||
|
||||
- @namespaces.in_groups_of(6, false) do |group|
|
||||
.row
|
||||
- group.each do |namespace|
|
||||
.col-md-2.col-sm-3
|
||||
.thumbnail
|
||||
= link_to project_fork_path(@project, namespace_id: namespace.id), title: "Fork here", method: "POST" do
|
||||
- if namespace.kind_of?(Group)
|
||||
= image_tag group_icon(namespace.path)
|
||||
- else
|
||||
= image_tag avatar_icon(namespace.owner.email, 200)
|
||||
.caption
|
||||
%h4=namespace.human_name
|
||||
%p
|
||||
= namespace.path
|
||||
|
|
@ -181,7 +181,6 @@ Gitlab::Application.routes.draw do
|
|||
resources :projects, constraints: { id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do
|
||||
member do
|
||||
put :transfer
|
||||
post :fork
|
||||
post :archive
|
||||
post :unarchive
|
||||
post :upload_image
|
||||
|
@ -214,11 +213,11 @@ Gitlab::Application.routes.draw do
|
|||
|
||||
match "/compare/:from...:to" => "compare#show", as: "compare", via: [:get, :post], constraints: {from: /.+/, to: /.+/}
|
||||
|
||||
resources :snippets, constraints: {id: /\d+/} do
|
||||
member do
|
||||
get "raw"
|
||||
end
|
||||
resources :snippets, constraints: {id: /\d+/} do
|
||||
member do
|
||||
get "raw"
|
||||
end
|
||||
end
|
||||
|
||||
resources :wikis, only: [:show, :edit, :destroy, :create], constraints: {id: /[a-zA-Z.0-9_\-\/]+/} do
|
||||
collection do
|
||||
|
@ -232,6 +231,8 @@ Gitlab::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resource :fork, only: [:new, :create]
|
||||
|
||||
resource :repository, only: [:show] do
|
||||
member do
|
||||
get "archive", constraints: { format: Gitlab::Regex.archive_formats_regex }
|
||||
|
|
Loading…
Reference in a new issue