diff options
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 59faf35e051..37f4705adbd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -225,6 +225,7 @@ class Project < ActiveRecord::Base scope :with_project_feature, -> { joins('LEFT JOIN project_features ON projects.id = project_features.project_id') } scope :with_statistics, -> { includes(:statistics) } scope :with_shared_runners, -> { where(shared_runners_enabled: true) } + scope :inside_path, ->(path) { joins(:route).where('routes.path LIKE ?', "#{path}/%") } # "enabled" here means "not disabled". It includes private features! scope :with_feature_enabled, ->(feature) { @@ -591,10 +592,11 @@ class Project < ActiveRecord::Base end end - def to_reference(from_project = nil, full: false) - if full || cross_namespace_reference?(from_project) + # `from` argument can be a Namespace or Project. + def to_reference(from = nil, full: false) + if full || cross_namespace_reference?(from) path_with_namespace - elsif cross_project_reference?(from_project) + elsif cross_project_reference?(from) path end end @@ -1291,21 +1293,26 @@ class Project < ActiveRecord::Base private + def cross_namespace_reference?(from) + case from + when Project + namespace != from.namespace + when Namespace + namespace != from + end + end + # Check if a reference is being done cross-project - # - # from_project - Refering Project object - def cross_project_reference?(from_project) - from_project && self != from_project + def cross_project_reference?(from) + return true if from.is_a?(Namespace) + + from && self != from end def pushes_since_gc_redis_key "projects/#{id}/pushes_since_gc" end - def cross_namespace_reference?(from_project) - from_project && namespace != from_project.namespace - end - def default_branch_protected? current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL || current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE |