summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-04-24 13:54:46 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2019-04-24 14:48:52 +0200
commit5fc045114c9b6faf0e7f506f0af06b8ca3a2996b (patch)
tree69e8118885a933ab513ee207ee884cac088b4d35 /app/models
parent2a00858533f1dcae71e97ba52386bfb2bfc1f752 (diff)
downloadgitlab-ce-pages-host-api.tar.gz
Add `token`pages-host-api
Diffstat (limited to 'app/models')
-rw-r--r--app/models/project.rb36
-rw-r--r--app/models/project_feature.rb4
2 files changed, 29 insertions, 11 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 2e72de4e447..36b16a53fe8 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1566,23 +1566,37 @@ class Project < ApplicationRecord
def pages_group_url
# The host in URL always needs to be downcased
- Gitlab.config.pages.url.sub(%r{^https?://}) do |prefix|
- "#{prefix}#{pages_subdomain}."
- end.downcase
+ strong_memoize(:pages_group_url) do
+ Gitlab.config.pages.url.sub(%r{^https?://}) do |prefix|
+ "#{prefix}#{pages_subdomain}."
+ end.downcase
+ end
end
- def pages_url
- url = pages_group_url
- url_path = full_path.partition('/').last
-
- # If the project path is the same as host, we serve it as group page
- return url if url == "#{Settings.pages.protocol}://#{url_path}"
+ def pages_group_root?
+ strong_memoize(:pages_group_root?) do
+ pages_group_url == "#{Settings.pages.protocol}://#{pages_path}"
+ end
+ end
- "#{url}/#{url_path}"
+ def pages_url
+ if pages_group_root?
+ pages_group_url
+ else
+ "#{pages_group_url}/#{pages_path}"
+ end
end
def pages_subdomain
- full_path.partition('/').first
+ strong_memoize(:pages_subdomain) do
+ full_path.partition('/').first
+ end
+ end
+
+ def pages_path
+ strong_memoize(:pages_path) do
+ full_path.partition('/').drop(1).join('/')
+ end
end
def pages_path
diff --git a/app/models/project_feature.rb b/app/models/project_feature.rb
index 0542581c6e0..b6fb2c459bd 100644
--- a/app/models/project_feature.rb
+++ b/app/models/project_feature.rb
@@ -109,6 +109,10 @@ class ProjectFeature < ApplicationRecord
pages_access_level == PUBLIC || pages_access_level == ENABLED && project.public?
end
+ def private_pages?
+ !public_pages?
+ end
+
private
# Validates builds and merge requests access level