diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-03 18:08:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-03 18:08:08 +0300 |
commit | 946771d0b016ae92b15a60bc3290a33b94191ffe (patch) | |
tree | 64862c2433989483f5fce45d5539242577a362eb /app/models | |
parent | f1e2fca19a90a6992c2020cf8c2159cfb0b61bca (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_setting.rb | 3 | ||||
-rw-r--r-- | app/models/project_wiki.rb | 4 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 50 |
3 files changed, 27 insertions, 30 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 2f7d6164b9a..f9d7e8a2b7a 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -172,6 +172,7 @@ class ApplicationSetting < ApplicationRecord validates :gitaly_timeout_default, presence: true, + if: :gitaly_timeout_default_changed?, numericality: { only_integer: true, greater_than_or_equal_to: 0, @@ -180,6 +181,7 @@ class ApplicationSetting < ApplicationRecord validates :gitaly_timeout_medium, presence: true, + if: :gitaly_timeout_medium_changed?, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :gitaly_timeout_medium, numericality: { less_than_or_equal_to: :gitaly_timeout_default }, @@ -190,6 +192,7 @@ class ApplicationSetting < ApplicationRecord validates :gitaly_timeout_fast, presence: true, + if: :gitaly_timeout_fast_changed?, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :gitaly_timeout_fast, numericality: { less_than_or_equal_to: :gitaly_timeout_default }, diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index 7529047a73a..8ed7811b468 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -107,7 +107,7 @@ class ProjectWiki direction_desc: direction == DIRECTION_DESC, load_content: load_content ).map do |page| - WikiPage.new(self, page, true) + WikiPage.new(self, page) end end @@ -122,7 +122,7 @@ class ProjectWiki page_title, page_dir = page_title_and_dir(title) if page = wiki.page(title: page_title, version: version, dir: page_dir) - WikiPage.new(self, page, true) + WikiPage.new(self, page) end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index c5db42a40ac..c6481bdbb6c 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -70,10 +70,9 @@ class WikiPage Gitlab::HookData::WikiPageBuilder.new(self).build end - def initialize(wiki, page = nil, persisted = false) + def initialize(wiki, page = nil) @wiki = wiki @page = page - @persisted = persisted @attributes = {}.with_indifferent_access set_attributes if persisted? @@ -94,11 +93,7 @@ class WikiPage # The formatted title of this page. def title - if @attributes[:title] - CGI.unescape_html(self.class.unhyphenize(@attributes[:title])) - else - "" - end + @attributes[:title] || '' end # Sets the title of this page. @@ -176,7 +171,7 @@ class WikiPage # Returns boolean True or False if this instance # has been fully created on disk or not. def persisted? - @persisted == true + @page.present? end # Creates a new Wiki Page. @@ -196,7 +191,7 @@ class WikiPage def create(attrs = {}) update_attributes(attrs) - save(page_details: title) do + save do wiki.create_page(title, content, format, attrs[:message]) end end @@ -222,18 +217,12 @@ class WikiPage update_attributes(attrs) - if title_changed? - page_details = title - - if wiki.find_page(page_details).present? - @attributes[:title] = @page.url_path - raise PageRenameError - end - else - page_details = @page.url_path + if title.present? && title_changed? && wiki.find_page(title).present? + @attributes[:title] = @page.title + raise PageRenameError end - save(page_details: page_details) do + save do wiki.update_page( @page, content: content, @@ -266,7 +255,14 @@ class WikiPage end def title_changed? - title.present? && (@page.nil? || self.class.unhyphenize(@page.url_path) != title) + if persisted? + old_title, old_dir = wiki.page_title_and_dir(self.class.unhyphenize(@page.url_path)) + new_title, new_dir = wiki.page_title_and_dir(title) + + new_title != old_title || (title.include?('/') && new_dir != old_dir) + else + title.present? + end end # Updates the current @attributes hash by merging a hash of params @@ -313,26 +309,24 @@ class WikiPage attributes[:format] = @page.format end - def save(page_details:) - return unless valid? + def save + return false unless valid? unless yield errors.add(:base, wiki.error_message) return false end - page_title, page_dir = wiki.page_title_and_dir(page_details) - gitlab_git_wiki = wiki.wiki - @page = gitlab_git_wiki.page(title: page_title, dir: page_dir) - + @page = wiki.find_page(title).page set_attributes - @persisted = errors.blank? + + true end def validate_path_limits *dirnames, title = @attributes[:title].split('/') - if title.bytesize > MAX_TITLE_BYTES + if title && title.bytesize > MAX_TITLE_BYTES errors.add(:title, _("exceeds the limit of %{bytes} bytes") % { bytes: MAX_TITLE_BYTES }) end |