Commit de12eba25c840a533cd7fa8edddc5fb3b96634f8

Authored by Dmitriy Zaporozhets
1 parent 7b6f2fb1

Dont show fork button in personal projects. Point to fork if already forked project

app/models/ability.rb
... ... @@ -69,7 +69,6 @@ class Ability
69 69 :download_code,
70 70 :write_snippet,
71 71 :fork_project
72   -
73 72 ]
74 73 end
75 74  
... ...
app/models/user.rb
... ... @@ -326,4 +326,18 @@ class User < ActiveRecord::Base
326 326 def tm_of(project)
327 327 project.team_member_by_id(self.id)
328 328 end
  329 +
  330 + def already_forked? project
  331 + !!fork_of(project)
  332 + end
  333 +
  334 + def fork_of project
  335 + links = ForkedProjectLink.where(forked_from_project_id: project, forked_to_project_id: personal_projects)
  336 +
  337 + if links.any?
  338 + links.first.forked_to_project
  339 + else
  340 + nil
  341 + end
  342 + end
329 343 end
... ...
app/views/projects/_clone_panel.html.haml
... ... @@ -5,10 +5,14 @@
5 5 .span3.pull-right
6 6 .pull-right
7 7 - unless @project.empty_repo?
8   - - if can? current_user, :fork_project, @project
9   - = link_to fork_project_path(@project), title: "Fork", class: "btn grouped", method: "POST" do
10   - %i.icon-copy
11   - Fork
  8 + - if can?(current_user, :fork_project, @project) && @project.namespace != current_user.namespace
  9 + - if current_user.already_forked?(@project)
  10 + = link_to project_path(current_user.fork_of(@project)), class: 'btn grouped success' do
  11 + Forked
  12 + - else
  13 + = link_to fork_project_path(@project), title: "Fork", class: "btn grouped", method: "POST" do
  14 + %i.icon-copy
  15 + Fork
12 16 - if can? current_user, :download_code, @project
13 17 = link_to archive_project_repository_path(@project), class: "btn grouped" do
14 18 %i.icon-download-alt
... ...
app/views/projects/show.html.haml
... ... @@ -40,3 +40,7 @@
40 40 %p Repo Size: #{@project.repository.size} MB
41 41 %p Created at: #{@project.created_at.stamp('Aug 22, 2013')}
42 42 %p Owner: #{link_to @project.owner_name, @project.owner}
  43 + - if @project.forked_from_project
  44 + %p
  45 + Forked from:
  46 + = link_to @project.forked_from_project.name_with_namespace, project_path(@project.forked_from_project)
... ...