diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob.rb | 30 | ||||
-rw-r--r-- | app/models/ci/trigger.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/discussion_on_diff.rb | 8 | ||||
-rw-r--r-- | app/models/concerns/note_on_diff.rb | 14 | ||||
-rw-r--r-- | app/models/concerns/noteable.rb | 4 | ||||
-rw-r--r-- | app/models/container_repository.rb | 4 | ||||
-rw-r--r-- | app/models/diff_discussion.rb | 1 | ||||
-rw-r--r-- | app/models/diff_note.rb | 14 | ||||
-rw-r--r-- | app/models/issue.rb | 2 | ||||
-rw-r--r-- | app/models/legacy_diff_discussion.rb | 8 | ||||
-rw-r--r-- | app/models/legacy_diff_note.rb | 3 | ||||
-rw-r--r-- | app/models/merge_request.rb | 9 | ||||
-rw-r--r-- | app/models/merge_request_diff.rb | 10 | ||||
-rw-r--r-- | app/models/note.rb | 8 | ||||
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
16 files changed, 87 insertions, 36 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 801d3442803..55872acef51 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -42,12 +42,16 @@ class Blob < SimpleDelegator size && truncated? end + def extension + extname.downcase.delete('.') + end + def svg? text? && language && language.name == 'SVG' end def pdf? - name && File.extname(name) == '.pdf' + extension == 'pdf' end def ipython_notebook? @@ -55,11 +59,15 @@ class Blob < SimpleDelegator end def sketch? - binary? && extname.downcase.delete('.') == 'sketch' + binary? && extension == 'sketch' end def stl? - extname.downcase.delete('.') == 'stl' + extension == 'stl' + end + + def markup? + text? && Gitlab::MarkupHelper.markup?(name) end def size_within_svg_limits? @@ -77,8 +85,10 @@ class Blob < SimpleDelegator else 'text' end - elsif image? || svg? + elsif image? 'image' + elsif svg? + 'svg' elsif pdf? 'pdf' elsif ipython_notebook? @@ -87,8 +97,18 @@ class Blob < SimpleDelegator 'sketch' elsif stl? 'stl' + elsif markup? + if only_display_raw? + 'too_large' + else + 'markup' + end elsif text? - 'text' + if only_display_raw? + 'too_large' + else + 'text' + end else 'download' end diff --git a/app/models/ci/trigger.rb b/app/models/ci/trigger.rb index b59e235c425..2f64f70685a 100644 --- a/app/models/ci/trigger.rb +++ b/app/models/ci/trigger.rb @@ -7,7 +7,7 @@ module Ci belongs_to :project belongs_to :owner, class_name: "User" - has_many :trigger_requests, dependent: :destroy + has_many :trigger_requests has_one :trigger_schedule, dependent: :destroy validates :token, presence: true, uniqueness: true diff --git a/app/models/concerns/discussion_on_diff.rb b/app/models/concerns/discussion_on_diff.rb index 87db0c810c3..67b1cace3eb 100644 --- a/app/models/concerns/discussion_on_diff.rb +++ b/app/models/concerns/discussion_on_diff.rb @@ -5,8 +5,6 @@ module DiscussionOnDiff included do NUMBER_OF_TRUNCATED_DIFF_LINES = 16 - memoized_values << :active - delegate :line_code, :original_line_code, :diff_file, @@ -29,12 +27,6 @@ module DiscussionOnDiff true end - def active? - return @active if @active.present? - - @active = first_note.active? - end - # Returns an array of at most 16 highlighted lines above a diff note def truncated_diff_lines(highlight: true) lines = highlight ? highlighted_diff_lines : diff_lines diff --git a/app/models/concerns/note_on_diff.rb b/app/models/concerns/note_on_diff.rb index 1a5a7007a2b..6c27dd5aa5c 100644 --- a/app/models/concerns/note_on_diff.rb +++ b/app/models/concerns/note_on_diff.rb @@ -25,4 +25,18 @@ module NoteOnDiff def diff_attributes raise NotImplementedError end + + def active?(diff_refs = nil) + raise NotImplementedError + end + + private + + def noteable_diff_refs + if noteable.respond_to?(:diff_sha_refs) + noteable.diff_sha_refs + else + noteable.diff_refs + end + end end diff --git a/app/models/concerns/noteable.rb b/app/models/concerns/noteable.rb index 772ff6a6d2f..dd1e6630642 100644 --- a/app/models/concerns/noteable.rb +++ b/app/models/concerns/noteable.rb @@ -36,10 +36,10 @@ module Noteable .discussions(self) end - def grouped_diff_discussions + def grouped_diff_discussions(*args) # Doesn't use `discussion_notes`, because this may include commit diff notes # besides MR diff notes, that we do no want to display on the MR Changes tab. - notes.inc_relations_for_view.grouped_diff_discussions + notes.inc_relations_for_view.grouped_diff_discussions(*args) end def resolvable_discussions diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 9682df3a586..82f4182d59a 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -23,6 +23,10 @@ class ContainerRepository < ActiveRecord::Base @path ||= [project.full_path, name].select(&:present?).join('/') end + def location + File.join(registry.path, path) + end + def tag(tag) ContainerRegistry::Tag.new(self, tag) end diff --git a/app/models/diff_discussion.rb b/app/models/diff_discussion.rb index d9b7e484e0f..6a6466b493b 100644 --- a/app/models/diff_discussion.rb +++ b/app/models/diff_discussion.rb @@ -10,6 +10,7 @@ class DiffDiscussion < Discussion delegate :position, :original_position, + :latest_merge_request_diff, to: :first_note diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index 1523244f8a8..abe4518d62a 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -65,20 +65,18 @@ class DiffNote < Note self.position.diff_refs == diff_refs end + def latest_merge_request_diff + return unless for_merge_request? + + self.noteable.merge_request_diff_for(self.position.diff_refs) + end + private def supported? for_commit? || self.noteable.has_complete_diff_refs? end - def noteable_diff_refs - if noteable.respond_to?(:diff_sha_refs) - noteable.diff_sha_refs - else - noteable.diff_refs - end - end - def set_original_position self.original_position = self.position.dup unless self.original_position&.complete? end diff --git a/app/models/issue.rb b/app/models/issue.rb index d8d9db477d2..d39ae3a6c92 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -26,8 +26,6 @@ class Issue < ActiveRecord::Base validates :project, presence: true - scope :cared, ->(user) { where(assignee_id: user) } - scope :open_for, ->(user) { opened.assigned_to(user) } scope :in_projects, ->(project_ids) { where(project_id: project_ids) } scope :without_due_date, -> { where(due_date: nil) } diff --git a/app/models/legacy_diff_discussion.rb b/app/models/legacy_diff_discussion.rb index cb2651a03f8..e617ce36f56 100644 --- a/app/models/legacy_diff_discussion.rb +++ b/app/models/legacy_diff_discussion.rb @@ -7,6 +7,8 @@ class LegacyDiffDiscussion < Discussion include DiscussionOnDiff + memoized_values << :active + def legacy_diff_discussion? true end @@ -15,6 +17,12 @@ class LegacyDiffDiscussion < Discussion LegacyDiffNote end + def active?(*args) + return @active if @active.present? + + @active = first_note.active?(*args) + end + def collapsed? !active? end diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb index 9a77557ebcd..d7c627432d2 100644 --- a/app/models/legacy_diff_note.rb +++ b/app/models/legacy_diff_note.rb @@ -56,11 +56,12 @@ class LegacyDiffNote < Note # # If the note's current diff cannot be matched in the MergeRequest's current # diff, it's considered inactive. - def active? + def active?(diff_refs = nil) return @active if defined?(@active) return true if for_commit? return true unless diff_line return false unless noteable + return false if diff_refs && diff_refs != noteable_diff_refs noteable_diff = find_noteable_diff diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b71a9e17a93..1d4827375d7 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -104,7 +104,6 @@ class MergeRequest < ActiveRecord::Base scope :by_source_or_target_branch, ->(branch_name) do where("source_branch = :branch OR target_branch = :branch", branch: branch_name) end - scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) } scope :by_milestone, ->(milestone) { where(milestone_id: milestone) } scope :of_projects, ->(ids) { where(target_project_id: ids) } scope :from_project, ->(project) { where(source_project_id: project.id) } @@ -367,6 +366,14 @@ class MergeRequest < ActiveRecord::Base merge_request_diff(true) end + def merge_request_diff_for(diff_refs) + @merge_request_diffs_by_diff_refs ||= Hash.new do |h, diff_refs| + h[diff_refs] = merge_request_diffs.viewable.select_without_diff.find_by_diff_refs(diff_refs) + end + + @merge_request_diffs_by_diff_refs[diff_refs] + end + def reload_diff_if_branch_changed if source_branch_changed? || target_branch_changed? reload_diff diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 6ad56b842b2..6604af2b47e 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -31,6 +31,10 @@ class MergeRequestDiff < ActiveRecord::Base # It allows you to override variables like head_commit_sha before getting diff. after_create :save_git_content, unless: :importing? + def self.find_by_diff_refs(diff_refs) + find_by(start_commit_sha: diff_refs.start_sha, head_commit_sha: diff_refs.head_sha, base_commit_sha: diff_refs.base_sha) + end + def self.select_without_diff select(column_names - ['st_diffs']) end @@ -130,6 +134,12 @@ class MergeRequestDiff < ActiveRecord::Base st_commits.map { |commit| commit[:id] } end + def diff_refs=(new_diff_refs) + self.base_commit_sha = new_diff_refs&.base_sha + self.start_commit_sha = new_diff_refs&.start_sha + self.head_commit_sha = new_diff_refs&.head_sha + end + def diff_refs return unless start_commit_sha || base_commit_sha diff --git a/app/models/note.rb b/app/models/note.rb index 1ea7b946061..c85692c5aec 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -113,11 +113,11 @@ class Note < ActiveRecord::Base Discussion.build(notes) end - def grouped_diff_discussions + def grouped_diff_discussions(diff_refs = nil) diff_notes. fresh. discussions. - select(&:active?). + select { |n| n.active?(diff_refs) }. group_by(&:line_code) end @@ -140,6 +140,10 @@ class Note < ActiveRecord::Base true end + def latest_merge_request_diff + nil + end + def max_attachment_size current_application_settings.max_attachment_size.megabytes.to_i end diff --git a/app/models/repository.rb b/app/models/repository.rb index f4c51cdfdf4..526ab1e77a7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -407,8 +407,6 @@ class Repository # Runs code after a repository has been forked/imported. def after_import expire_content_cache - expire_tags_cache - expire_branches_cache end # Runs code after a new commit has been pushed. diff --git a/app/models/user.rb b/app/models/user.rb index 31e975b8e53..457ba05fb04 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -587,10 +587,6 @@ class User < ActiveRecord::Base name.split.first unless name.blank? end - def cared_merge_requests - MergeRequest.cared(self) - end - def projects_limit_left projects_limit - personal_projects.count end |