diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-03 18:06:09 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-07 12:46:23 +0300 |
commit | f90b27da7777b0c72782d2a930f770e2f27757e2 (patch) | |
tree | 50f1d5b84e40c45c29a1be2b8150029da7db2d87 /app | |
parent | 8160550439d2027c12d5556c8ce1f8afd250628a (diff) |
Find forks within users/namespaces using fork memberships
Diffstat (limited to 'app')
-rw-r--r-- | app/models/fork_network.rb | 4 | ||||
-rw-r--r-- | app/models/namespace.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/models/user.rb | 10 |
4 files changed, 13 insertions, 10 deletions
diff --git a/app/models/fork_network.rb b/app/models/fork_network.rb index fd2510d0a4c..218e37a5312 100644 --- a/app/models/fork_network.rb +++ b/app/models/fork_network.rb @@ -8,4 +8,8 @@ class ForkNetwork < ActiveRecord::Base def add_root_as_member projects << root_project end + + def find_forks_in(other_projects) + projects.where(id: other_projects) + end end diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e279d8dd8c5..4672881e220 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -139,7 +139,9 @@ class Namespace < ActiveRecord::Base end def find_fork_of(project) - projects.joins(:forked_project_link).find_by('forked_project_links.forked_from_project_id = ?', project.id) + return nil unless project.fork_network + + project.fork_network.find_forks_in(projects).first end def lfs_enabled? diff --git a/app/models/project.rb b/app/models/project.rb index 4a883552a8d..ad1c339ae78 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1009,6 +1009,11 @@ class Project < ActiveRecord::Base end def forked? + return true if fork_network && fork_network.root_project != self + + # TODO: Use only the above conditional using the `fork_network` + # This is the old conditional that looks at the `forked_project_link`, we + # fall back to this while we're migrating the new models !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?) end diff --git a/app/models/user.rb b/app/models/user.rb index 959738ba608..c3f115ca074 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -697,15 +697,7 @@ class User < ActiveRecord::Base end def fork_of(project) - links = ForkedProjectLink.where( - forked_from_project_id: project, - forked_to_project_id: personal_projects.unscope(:order) - ) - if links.any? - links.first.forked_to_project - else - nil - end + namespace.find_fork_of(project) end def ldap_user? |