From de12eba25c840a533cd7fa8edddc5fb3b96634f8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 8 May 2013 19:40:31 +0300 Subject: [PATCH] Dont show fork button in personal projects. Point to fork if already forked project --- app/models/ability.rb | 1 - app/models/user.rb | 14 ++++++++++++++ app/views/projects/_clone_panel.html.haml | 12 ++++++++---- app/views/projects/show.html.haml | 4 ++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index cad5a832978..8f0a6141b75 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -69,7 +69,6 @@ class Ability :download_code, :write_snippet, :fork_project - ] end diff --git a/app/models/user.rb b/app/models/user.rb index 1d90ec3b37a..55aa5b563c5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -326,4 +326,18 @@ class User < ActiveRecord::Base def tm_of(project) project.team_member_by_id(self.id) end + + def already_forked? project + !!fork_of(project) + end + + def fork_of project + links = ForkedProjectLink.where(forked_from_project_id: project, forked_to_project_id: personal_projects) + + if links.any? + links.first.forked_to_project + else + nil + end + end end diff --git a/app/views/projects/_clone_panel.html.haml b/app/views/projects/_clone_panel.html.haml index f1f8bac3862..8bc90a264d7 100644 --- a/app/views/projects/_clone_panel.html.haml +++ b/app/views/projects/_clone_panel.html.haml @@ -5,10 +5,14 @@ .span3.pull-right .pull-right - unless @project.empty_repo? - - if can? current_user, :fork_project, @project - = link_to fork_project_path(@project), title: "Fork", class: "btn grouped", method: "POST" do - %i.icon-copy - Fork + - if can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace + - if current_user.already_forked?(@project) + = link_to project_path(current_user.fork_of(@project)), class: 'btn grouped success' do + Forked + - else + = link_to fork_project_path(@project), title: "Fork", class: "btn grouped", method: "POST" do + %i.icon-copy + Fork - if can? current_user, :download_code, @project = link_to archive_project_repository_path(@project), class: "btn grouped" do %i.icon-download-alt diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 2341a727bd7..6ee2e3827b2 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -40,3 +40,7 @@ %p Repo Size: #{@project.repository.size} MB %p Created at: #{@project.created_at.stamp('Aug 22, 2013')} %p Owner: #{link_to @project.owner_name, @project.owner} + - if @project.forked_from_project + %p + Forked from: + = link_to @project.forked_from_project.name_with_namespace, project_path(@project.forked_from_project)