diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-12-18 20:02:00 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-12-18 20:02:00 +0200 |
commit | 9ada67881970b05d4be49cbe329b4bf50ffe4f77 (patch) | |
tree | 1c68833adba7876f20412b4e9ec6fef138eeb5fa /app/models | |
parent | aa8d4d9fea175e209ac3652f3743ce2801144a66 (diff) | |
download | gitlab-ce-9ada67881970b05d4be49cbe329b4bf50ffe4f77.tar.gz |
Split commit_id and noteable_id for Note
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/merge_request.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 10 | ||||
-rw-r--r-- | app/models/project.rb | 6 |
3 files changed, 11 insertions, 7 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 2409fb80acb..052e0850d96 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -204,7 +204,7 @@ class MergeRequest < ActiveRecord::Base def mr_and_commit_notes commit_ids = commits.map(&:id) - Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) + Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND commit_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) end # Returns the raw diff for this merge request diff --git a/app/models/note.rb b/app/models/note.rb index 219ed9b9332..28b3879239f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -20,7 +20,7 @@ require 'file_size_validator' class Note < ActiveRecord::Base attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id, - :attachment, :line_code + :attachment, :line_code, :commit_id attr_accessor :notify attr_accessor :notify_author @@ -35,10 +35,14 @@ class Note < ActiveRecord::Base validates :note, :project, presence: true validates :attachment, file_size: { maximum: 10.megabytes.to_i } + validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } + validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' } + mount_uploader :attachment, AttachmentUploader # Scopes - scope :common, ->{ where(noteable_id: nil) } + scope :for_commits, ->{ where(noteable_type: "Commit") } + scope :common, ->{ where(noteable_id: nil, commit_id: nil) } scope :today, ->{ where("created_at >= :date", date: Date.today) } scope :last_week, ->{ where("created_at >= :date", date: (Date.today - 7.days)) } scope :since, ->(day) { where("created_at >= :date", date: (day)) } @@ -66,7 +70,7 @@ class Note < ActiveRecord::Base # override to return commits, which are not active record def noteable if for_commit? - project.commit(noteable_id) + project.commit(commit_id) else super end diff --git a/app/models/project.rb b/app/models/project.rb index 5871bc67f69..eb6e7cb1b08 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -203,15 +203,15 @@ class Project < ActiveRecord::Base end def build_commit_note(commit) - notes.new(noteable_id: commit.id, noteable_type: "Commit") + notes.new(commit_id: commit.id, noteable_type: "Commit") end def commit_notes(commit) - notes.where(noteable_id: commit.id, noteable_type: "Commit", line_code: nil) + notes.where(commit_id: commit.id, noteable_type: "Commit", line_code: nil) end def commit_line_notes(commit) - notes.where(noteable_id: commit.id, noteable_type: "Commit").where("line_code IS NOT NULL") + notes.where(commit_id: commit.id, noteable_type: "Commit").where("line_code IS NOT NULL") end def public? |