summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-22 11:31:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-22 11:31:16 +0000
commit905c1110b08f93a19661cf42a276c7ea90d0a0ff (patch)
tree756d138db422392c00471ab06acdff92c5a9b69c /app/models/project.rb
parent50d93f8d1686950fc58dda4823c4835fd0d8c14b (diff)
downloadgitlab-ce-905c1110b08f93a19661cf42a276c7ea90d0a0ff.tar.gz
Add latest changes from gitlab-org/gitlab@12-4-stable-ee
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb99
1 files changed, 87 insertions, 12 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 5c3bf4a3b5d..3525f37f8d5 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -68,7 +68,7 @@ class Project < ApplicationRecord
:snippets_access_level, :builds_access_level, :repository_access_level,
to: :project_feature, allow_nil: true
- delegate :base_dir, :disk_path, :ensure_storage_path_exists, to: :storage
+ delegate :base_dir, :disk_path, to: :storage
delegate :scheduled?, :started?, :in_progress?,
:failed?, :finished?,
@@ -104,6 +104,9 @@ class Project < ApplicationRecord
unless: :ci_cd_settings,
if: proc { ProjectCiCdSetting.available? }
+ after_create :create_pages_metadatum,
+ unless: :pages_metadatum
+
after_create :set_timestamps_for_create
after_update :update_forks_visibility_level
@@ -119,8 +122,6 @@ class Project < ApplicationRecord
# Storage specific hooks
after_initialize :use_hashed_storage
after_create :check_repository_absence!
- after_create :ensure_storage_path_exists
- after_save :ensure_storage_path_exists, if: :saved_change_to_namespace_id?
acts_as_ordered_taggable
@@ -192,6 +193,7 @@ class Project < ApplicationRecord
has_one :project_repository, inverse_of: :project
has_one :error_tracking_setting, inverse_of: :project, class_name: 'ErrorTracking::ProjectErrorTrackingSetting'
has_one :metrics_setting, inverse_of: :project, class_name: 'ProjectMetricsSetting'
+ has_one :grafana_integration, inverse_of: :project
# Merge Requests for target project should be removed with it
has_many :merge_requests, foreign_key: 'target_project_id', inverse_of: :target_project
@@ -242,8 +244,8 @@ class Project < ApplicationRecord
has_one :cluster_project, class_name: 'Clusters::Project'
has_many :clusters, through: :cluster_project, class_name: 'Clusters::Cluster'
- has_many :cluster_ingresses, through: :clusters, source: :application_ingress, class_name: 'Clusters::Applications::Ingress'
has_many :kubernetes_namespaces, class_name: 'Clusters::KubernetesNamespace'
+ has_many :management_clusters, class_name: 'Clusters::Cluster', foreign_key: :management_project_id, inverse_of: :management_project
has_many :prometheus_metrics
@@ -273,12 +275,13 @@ class Project < ApplicationRecord
has_many :builds, class_name: 'Ci::Build', inverse_of: :project, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :build_trace_section_names, class_name: 'Ci::BuildTraceSectionName'
has_many :build_trace_chunks, class_name: 'Ci::BuildTraceChunk', through: :builds, source: :trace_chunks
+ has_many :job_artifacts, class_name: 'Ci::JobArtifact'
has_many :runner_projects, class_name: 'Ci::RunnerProject', inverse_of: :project
has_many :runners, through: :runner_projects, source: :runner, class_name: 'Ci::Runner'
has_many :variables, class_name: 'Ci::Variable'
has_many :triggers, class_name: 'Ci::Trigger'
has_many :environments
- has_many :deployments, -> { success }
+ has_many :deployments
has_many :pipeline_schedules, class_name: 'Ci::PipelineSchedule'
has_many :project_deploy_tokens
has_many :deploy_tokens, through: :project_deploy_tokens
@@ -294,6 +297,11 @@ class Project < ApplicationRecord
has_many :external_pull_requests, inverse_of: :project
+ has_many :sourced_pipelines, class_name: 'Ci::Sources::Pipeline', foreign_key: :source_project_id
+ has_many :source_pipelines, class_name: 'Ci::Sources::Pipeline', foreign_key: :project_id
+
+ has_one :pages_metadatum, class_name: 'ProjectPagesMetadatum', inverse_of: :project
+
accepts_nested_attributes_for :variables, allow_destroy: true
accepts_nested_attributes_for :project_feature, update_only: true
accepts_nested_attributes_for :import_data
@@ -306,6 +314,7 @@ class Project < ApplicationRecord
accepts_nested_attributes_for :error_tracking_setting, update_only: true
accepts_nested_attributes_for :metrics_setting, update_only: true, allow_destroy: true
+ accepts_nested_attributes_for :grafana_integration, update_only: true, allow_destroy: true
delegate :name, to: :owner, allow_nil: true, prefix: true
delegate :members, to: :team, prefix: true
@@ -424,6 +433,15 @@ class Project < ApplicationRecord
.where(project_ci_cd_settings: { group_runners_enabled: true })
end
+ scope :with_pages_deployed, -> do
+ joins(:pages_metadatum).merge(ProjectPagesMetadatum.deployed)
+ end
+
+ scope :pages_metadata_not_migrated, -> do
+ left_outer_joins(:pages_metadatum)
+ .where(project_pages_metadata: { project_id: nil })
+ end
+
enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 }
chronic_duration_attr :build_timeout_human_readable, :build_timeout,
@@ -650,7 +668,7 @@ class Project < ApplicationRecord
def emails_disabled?
strong_memoize(:emails_disabled) do
# disabling in the namespace overrides the project setting
- Feature.enabled?(:emails_disabled, self, default_enabled: true) && (super || namespace.emails_disabled?)
+ super || namespace.emails_disabled?
end
end
@@ -1018,8 +1036,8 @@ class Project < ApplicationRecord
end
end
- def web_url
- Gitlab::Routing.url_helpers.project_url(self)
+ def web_url(only_path: nil)
+ Gitlab::Routing.url_helpers.project_url(self, only_path: only_path)
end
def readme_url
@@ -1298,7 +1316,18 @@ class Project < ApplicationRecord
end
def http_url_to_repo
- "#{web_url}.git"
+ custom_root = Gitlab::CurrentSettings.custom_http_clone_url_root
+
+ project_url = if custom_root.present?
+ Gitlab::Utils.append_path(
+ custom_root,
+ web_url(only_path: true)
+ )
+ else
+ web_url
+ end
+
+ "#{project_url}.git"
end
# Is overridden in EE
@@ -1647,6 +1676,10 @@ class Project < ApplicationRecord
"#{url}/#{url_path}"
end
+ def pages_group_root?
+ pages_group_url == pages_url
+ end
+
def pages_subdomain
full_path.partition('/').first
end
@@ -1685,6 +1718,7 @@ class Project < ApplicationRecord
# Projects with a missing namespace cannot have their pages removed
return unless namespace
+ mark_pages_as_not_deployed unless destroyed?
::Projects::UpdatePagesConfigurationService.new(self).execute
# 1. We rename pages to temporary directory
@@ -1698,6 +1732,14 @@ class Project < ApplicationRecord
end
# rubocop: enable CodeReuse/ServiceClass
+ def mark_pages_as_deployed
+ ensure_pages_metadatum.update!(deployed: true)
+ end
+
+ def mark_pages_as_not_deployed
+ ensure_pages_metadatum.update!(deployed: false)
+ end
+
# rubocop:disable Gitlab/RailsLogger
def write_repository_config(gl_full_path: full_path)
# We'd need to keep track of project full path otherwise directory tree
@@ -1821,6 +1863,7 @@ class Project < ApplicationRecord
Gitlab::Ci::Variables::Collection.new
.append(key: 'CI_PROJECT_ID', value: id.to_s)
.append(key: 'CI_PROJECT_NAME', value: path)
+ .append(key: 'CI_PROJECT_TITLE', value: title)
.append(key: 'CI_PROJECT_PATH', value: full_path)
.append(key: 'CI_PROJECT_PATH_SLUG', value: full_path_slug)
.append(key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path)
@@ -2217,12 +2260,37 @@ class Project < ApplicationRecord
members.maintainers.order_recent_sign_in.limit(ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT)
end
- def pages_lookup_path(domain: nil)
- Pages::LookupPath.new(self, domain: domain)
+ def pages_lookup_path(trim_prefix: nil, domain: nil)
+ Pages::LookupPath.new(self, trim_prefix: trim_prefix, domain: domain)
+ end
+
+ def closest_setting(name)
+ setting = read_attribute(name)
+ setting = closest_namespace_setting(name) if setting.nil?
+ setting = app_settings_for(name) if setting.nil?
+ setting
+ end
+
+ def drop_visibility_level!
+ if group && group.visibility_level < visibility_level
+ self.visibility_level = group.visibility_level
+ end
+
+ if Gitlab::CurrentSettings.restricted_visibility_levels.include?(visibility_level)
+ self.visibility_level = Gitlab::VisibilityLevel::PRIVATE
+ end
end
private
+ def closest_namespace_setting(name)
+ namespace.closest_setting(name)
+ end
+
+ def app_settings_for(name)
+ Gitlab::CurrentSettings.send(name) # rubocop:disable GitlabSecurity/PublicSend
+ end
+
def merge_requests_allowing_collaboration(source_branch = nil)
relation = source_of_merge_requests.opened.where(allow_collaboration: true)
relation = relation.where(source_branch: source_branch) if source_branch
@@ -2268,7 +2336,7 @@ class Project < ApplicationRecord
end
def repository_with_same_path_already_exists?
- gitlab_shell.exists?(repository_storage, "#{disk_path}.git")
+ gitlab_shell.repository_exists?(repository_storage, "#{disk_path}.git")
end
def set_timestamps_for_create
@@ -2346,6 +2414,13 @@ class Project < ApplicationRecord
def services_templates
@services_templates ||= Service.where(template: true)
end
+
+ def ensure_pages_metadatum
+ pages_metadatum || create_pages_metadatum!
+ rescue ActiveRecord::RecordNotUnique
+ reset
+ retry
+ end
end
Project.prepend_if_ee('EE::Project')