From e08e405ac4c448d8b720ed2ef6181c15e3f3dfc1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 13 Nov 2014 22:06:19 +0200 Subject: [PATCH] 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 --- app/controllers/projects/forks_controller.rb | 22 ++++++++++++++++++++ app/controllers/projects_controller.rb | 16 -------------- app/models/user.rb | 10 +++++++++ app/views/projects/_home_panel.html.haml | 2 +- app/views/projects/fork.html.haml | 19 ----------------- app/views/projects/forks/error.html.haml | 20 ++++++++++++++++++ app/views/projects/forks/new.html.haml | 19 +++++++++++++++++ config/routes.rb | 11 +++++----- 8 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 app/controllers/projects/forks_controller.rb delete mode 100644 app/views/projects/fork.html.haml create mode 100644 app/views/projects/forks/error.html.haml create mode 100644 app/views/projects/forks/new.html.haml diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb new file mode 100644 index 00000000000..a0481d11582 --- /dev/null +++ b/app/controllers/projects/forks_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b5910c902e4..b3181fa310e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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'] diff --git a/app/models/user.rb b/app/models/user.rb index d400edc0df5..fc191a78f53 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index 672a91e0eef..c2fa1c4bccc 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -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 diff --git a/app/views/projects/fork.html.haml b/app/views/projects/fork.html.haml deleted file mode 100644 index d8f5c7b98d6..00000000000 --- a/app/views/projects/fork.html.haml +++ /dev/null @@ -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 diff --git a/app/views/projects/forks/error.html.haml b/app/views/projects/forks/error.html.haml new file mode 100644 index 00000000000..76d3aa5bf00 --- /dev/null +++ b/app/views/projects/forks/error.html.haml @@ -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 diff --git a/app/views/projects/forks/new.html.haml b/app/views/projects/forks/new.html.haml new file mode 100644 index 00000000000..db7486b00e8 --- /dev/null +++ b/app/views/projects/forks/new.html.haml @@ -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 + diff --git a/config/routes.rb b/config/routes.rb index 2534153758b..470fe7f4dc1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 }