diff options
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index dbf600cf0df..72ebdf61787 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -15,9 +15,11 @@ class Snippet < ApplicationRecord include FromUnion include IgnorableColumns include HasRepository + include AfterCommitQueue extend ::Gitlab::Utils::Override - MAX_FILE_COUNT = 1 + MAX_FILE_COUNT = 10 + MAX_SINGLE_FILE_COUNT = 1 cache_markdown_field :title, pipeline: :single_line cache_markdown_field :description @@ -101,6 +103,10 @@ class Snippet < ApplicationRecord where(project_id: nil) end + def self.only_project_snippets + where.not(project_id: nil) + end + def self.only_include_projects_visible_to(current_user = nil) levels = Gitlab::VisibilityLevel.levels_for_user(current_user) @@ -164,6 +170,10 @@ class Snippet < ApplicationRecord Snippet.find_by(id: id, project: project) end + def self.max_file_limit(user) + Feature.enabled?(:snippet_multiple_files, user) ? MAX_FILE_COUNT : MAX_SINGLE_FILE_COUNT + end + def initialize(attributes = {}) # We can't use default_value_for because the database has a default # value of 0 for visibility_level. If someone attempts to create a @@ -199,7 +209,7 @@ class Snippet < ApplicationRecord def blobs return [] unless repository_exists? - repository.ls_files(repository.root_ref).map { |file| Blob.lazy(self, repository.root_ref, file) } + repository.ls_files(repository.root_ref).map { |file| Blob.lazy(repository, repository.root_ref, file) } end def hook_attrs @@ -318,8 +328,10 @@ class Snippet < ApplicationRecord Digest::SHA256.hexdigest("#{title}#{description}#{created_at}#{updated_at}") end - def versioned_enabled_for?(user) - ::Feature.enabled?(:version_snippets, user) && repository_exists? + def file_name_on_repo + return if repository.empty? + + repository.ls_files(repository.root_ref).first end class << self @@ -334,17 +346,6 @@ class Snippet < ApplicationRecord fuzzy_search(query, [:title, :description, :file_name]) end - # Searches for snippets with matching content. - # - # This method uses ILIKE on PostgreSQL and LIKE on MySQL. - # - # query - The search query as a String. - # - # Returns an ActiveRecord::Relation. - def search_code(query) - fuzzy_search(query, [:content]) - end - def parent_class ::Project end |