diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-01 00:06:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-01 00:06:28 +0300 |
commit | 8f210aebe1d740e8ee194f171f1f33a6e1fba313 (patch) | |
tree | f43c545801bb96fd0737f18493fb30ab92972627 /app/models | |
parent | 996f700997805b3590da8d8afdd19d193989078a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_setting.rb | 5 | ||||
-rw-r--r-- | app/models/application_setting_implementation.rb | 1 | ||||
-rw-r--r-- | app/models/deployment.rb | 5 | ||||
-rw-r--r-- | app/models/environment.rb | 1 | ||||
-rw-r--r-- | app/models/project_wiki.rb | 42 | ||||
-rw-r--r-- | app/models/wiki_directory.rb | 63 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 43 |
7 files changed, 46 insertions, 114 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 4ecc9bc2153..cfae79ec016 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -104,6 +104,11 @@ class ApplicationSetting < ApplicationRecord hostname: true, if: :snowplow_enabled + validates :snowplow_iglu_registry_url, + addressable_url: true, + allow_blank: true, + if: :snowplow_enabled + validates :pendo_url, presence: true, public_url: true, diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index 0312183d11f..6cc77cca8a3 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -129,6 +129,7 @@ module ApplicationSettingImplementation snowplow_cookie_domain: nil, snowplow_enabled: false, snowplow_site_id: nil, + snowplow_iglu_registry_url: nil, custom_http_clone_url_root: nil, pendo_enabled: false, pendo_url: nil diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 7ccd5e98360..698988e9295 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -75,6 +75,11 @@ class Deployment < ApplicationRecord find(ids) end + def self.distinct_on_environment + order('environment_id, deployments.id DESC') + .select('DISTINCT ON (environment_id) deployments.*') + end + def self.find_successful_deployment!(iid) success.find_by!(iid: iid) end diff --git a/app/models/environment.rb b/app/models/environment.rb index b426941d8af..602dce89c4a 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -10,6 +10,7 @@ class Environment < ApplicationRecord has_many :successful_deployments, -> { success }, class_name: 'Deployment' has_one :last_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment' + has_one :last_visible_deployment, -> { visible.distinct_on_environment }, class_name: 'Deployment' before_validation :nullify_external_url before_validation :generate_slug, if: ->(env) { env.slug.blank? } diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index e0fcebf2642..bb222ac7629 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -17,13 +17,6 @@ class ProjectWiki CREATED_AT_ORDER = 'created_at' DIRECTION_DESC = 'desc' DIRECTION_ASC = 'asc' - SORT_ORDERS = [TITLE_ORDER, CREATED_AT_ORDER].freeze - SORT_DIRECTIONS = [DIRECTION_ASC, DIRECTION_DESC].freeze - - NESTING_FLAT = 'flat' - NESTING_TREE = 'tree' - NESTING_CLOSED = 'hidden' - NESTINGS = [NESTING_TREE, NESTING_CLOSED, NESTING_FLAT].freeze # Returns a string describing what went wrong after # an operation fails. @@ -65,11 +58,7 @@ class ProjectWiki end def wiki_base_path - ::File.join(project_base_path, 'wikis') - end - - def wiki_page_path - ::File.join(project_base_path, '-', 'wiki_pages') + [Gitlab.config.gitlab.relative_url_root, '/', @project.full_path, '/wikis'].join('') end # Returns the Gitlab::Git::Wiki object. @@ -136,23 +125,6 @@ class ProjectWiki end end - # Finds directory within the repository based on a slug - # - # dir_name - The directory prefix. - # - # Returns an initialized WikiDirectory instance or nil - def find_dir(dir_name, sort = nil, direction = DIRECTION_ASC) - descending = direction == DIRECTION_DESC - # WikiListPagesRequest currently does not support server-side - # filtering. Ideally this logic should be moved to the gitaly - # side. - pages = wiki - .list_pages(sort: sort, direction_desc: descending) - .map { |page| WikiPage.new(self, page, true) } - .select { |wp| wp.directory == dir_name } - WikiDirectory.new(dir_name, pages) if pages.present? - end - def find_sidebar(version = nil) find_page(SIDEBAR, version) end @@ -172,12 +144,6 @@ class ProjectWiki false end - def build_page(attrs) - WikiPage.new(self).tap do |page| - page.update_attributes(attrs) # rubocop:disable Rails/ActiveRecordAliases - end - end - def update_page(page, content:, title: nil, format: :markdown, message: nil) commit = commit_details(:updated, message, page.title) @@ -205,7 +171,7 @@ class ProjectWiki title_array = title.split("/") title = title_array.pop - [title, ::File.join(title_array)] + [title, title_array.join("/")] end def repository @@ -232,10 +198,6 @@ class ProjectWiki private - def project_base_path - ::File.join(Gitlab.config.gitlab.relative_url_root, @project.full_path) - end - def create_repo!(raw_repository) gitlab_shell.create_wiki_repository(project) diff --git a/app/models/wiki_directory.rb b/app/models/wiki_directory.rb index 6c86c11e7fb..712ba79bbd2 100644 --- a/app/models/wiki_directory.rb +++ b/app/models/wiki_directory.rb @@ -1,75 +1,20 @@ # frozen_string_literal: true class WikiDirectory - include StaticModel include ActiveModel::Validations attr_accessor :slug, :pages validates :slug, presence: true - # StaticModel overrides and configuration: - - def self.primary_key - 'slug' - end - - def id - "#{slug}@#{last_version&.sha}" - end - - def self.model_name - ActiveModel::Name.new(self, nil, 'wiki_dir') - end - - alias_method :to_param, :slug - alias_method :title, :slug - - # Sorts and groups pages by directory. - # - # pages - an array of WikiPage objects. - # - # Returns an array of WikiPage and WikiDirectory objects. - # The entries are sorted in the order of the input array, where - # directories appear in the position of their first member. - def self.group_by_directory(pages) - grouped = [] - dirs = Hash.new do |h, k| - new(k).tap { |dir| grouped << (h[k] = dir) } - end - - Array.wrap(pages).each_with_object(grouped) do |page, top_level| - group = page.directory.present? ? dirs[page.directory] : top_level - - group << page - end - end - def initialize(slug, pages = []) @slug = slug @pages = pages end - def <<(page) - @pages << page - @last_version = nil - end - - def last_version - @last_version ||= @pages.map(&:last_version).max_by(&:authored_date) - end - - def page_count - @pages.size - end - - def empty? - page_count.zero? - end - - def to_partial_path(context = nil) - name = [context, 'wiki_directory'].compact.join('_') - - "projects/wiki_directories/#{name}" + # Relative path to the partial to be used when rendering collections + # of this object. + def to_partial_path + 'projects/wikis/wiki_directory' end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 3006753e9e7..68241d2bd95 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -15,7 +15,30 @@ class WikiPage end def self.model_name - ActiveModel::Name.new(self, nil, 'wiki_page') + ActiveModel::Name.new(self, nil, 'wiki') + end + + # Sorts and groups pages by directory. + # + # pages - an array of WikiPage objects. + # + # Returns an array of WikiPage and WikiDirectory objects. The entries are + # sorted by alphabetical order (directories and pages inside each directory). + # Pages at the root level come before everything. + def self.group_by_directory(pages) + return [] if pages.blank? + + pages.each_with_object([]) do |page, grouped_pages| + next grouped_pages << page unless page.directory.present? + + directory = grouped_pages.find do |obj| + obj.is_a?(WikiDirectory) && obj.slug == page.directory + end + + next directory.pages << page if directory + + grouped_pages << WikiDirectory.new(page.directory, [page]) + end end def self.unhyphenize(name) @@ -43,16 +66,6 @@ class WikiPage Gitlab::HookData::WikiPageBuilder.new(self).build end - # Create a new WikiPage - # - # == Parameters: - # wiki:: - # A `ProjectWiki` model object - # page:: - # A `Gitlab::Git::WikiPage` business object, to which this class provides a facade - # persisted:: - # Is this page fully saved on disk? - # def initialize(wiki, page = nil, persisted = false) @wiki = wiki @page = page @@ -243,10 +256,10 @@ class WikiPage end end - def to_partial_path(context = nil) - name = [context, 'wiki_page'].compact.join('_') - - "projects/wiki_pages/#{name}" + # Relative path to the partial to be used when rendering collections + # of this object. + def to_partial_path + 'projects/wikis/wiki_page' end def id |