diff options
author | Krasimir Angelov <kangelov@gitlab.com> | 2019-09-10 10:26:17 +1200 |
---|---|---|
committer | Krasimir Angelov <kangelov@gitlab.com> | 2019-09-19 12:09:36 +1200 |
commit | 7469a7726f367c5b426be18970463c6c25ed5643 (patch) | |
tree | 6854568878c9d6551c10debe308e8184b6e0f71e /app/models/project.rb | |
parent | a7706bcb567ee31c6454c4197354b3210839b564 (diff) | |
download | gitlab-ce-61927-pages-namespaces-virtual-domain.tar.gz |
Add support for namespaces to Pages internal API61927-pages-namespaces-virtual-domain
Introduce new `project_pages_metadata` table, insert new record on
project creation. Update its `depoyed` flag when pages are
deployed/removed.
Return only these projects from namespace that have pages marked as
deployed. On-demand and mass data migration will handled in subsequent
commits.
Related to https://gitlab.com/gitlab-org/gitlab-ee/issues/28781.
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 18afccf7ddc..1115b370448 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -104,6 +104,9 @@ class Project < ApplicationRecord unless: :ci_cd_settings, if: proc { ProjectCiCdSetting.available? } + after_create :create_project_pages_metadatum, + unless: :project_pages_metadatum + after_create :set_timestamps_for_create after_update :update_forks_visibility_level @@ -295,6 +298,8 @@ class Project < ApplicationRecord has_many :external_pull_requests, inverse_of: :project + has_one :project_pages_metadatum, 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 @@ -425,6 +430,10 @@ class Project < ApplicationRecord .where(project_ci_cd_settings: { group_runners_enabled: true }) end + scope :with_pages_deployed, -> do + where('EXISTS (?)', ProjectPagesMetadatum.project_scoped.deployed.select(1)) + end + enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 } chronic_duration_attr :build_timeout_human_readable, :build_timeout, @@ -1643,6 +1652,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 @@ -1681,6 +1694,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 @@ -1694,6 +1708,14 @@ class Project < ApplicationRecord end # rubocop: enable CodeReuse/ServiceClass + def mark_pages_as_deployed + ProjectPagesMetadatum.update_pages_deployed(self, true) + end + + def mark_pages_as_not_deployed + ProjectPagesMetadatum.update_pages_deployed(self, 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 @@ -2213,8 +2235,8 @@ 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 private |