summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-12-23 01:03:57 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-12-23 01:03:57 +0100
commitdb2c15369c365340aeaf4e431e8838714b40396b (patch)
tree26ca045a337132370b67cc8f2ed4010e3087dfa5 /app/models/note.rb
parentb47173da6a0fea0982d009f91e2c4d042f9b5c37 (diff)
parent68c43d59f09a66cca0da1b9a50c11421d52eac9a (diff)
downloadgitlab-ce-db2c15369c365340aeaf4e431e8838714b40396b.tar.gz
Merge branch 'master' into discussions
Conflicts: app/assets/stylesheets/main.scss app/models/project.rb app/views/notes/_common_form.html.haml app/views/notes/_per_line_form.html.haml lib/gitlab/markdown.rb spec/models/note_spec.rb
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index a8ae9080627..b62b3fe61d5 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -19,7 +19,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 :line_code, format: { with: /\A\d+_\d+_\d+\Z/ }, allow_blank: 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)) }
@@ -122,7 +126,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
@@ -151,4 +155,12 @@ class Note < ActiveRecord::Base
def votable?
for_issue? || (for_merge_request? && !for_diff_line?)
end
+
+ def noteable_type_name
+ if noteable_type.present?
+ noteable_type.downcase
+ else
+ "wall"
+ end
+ end
end