Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-10-13 18:23:12 +0400
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-10-13 18:23:12 +0400
commitb1461de993daf6d43c8a54482eecacc6bb58df4d (patch)
tree56ed0f0fda021640620a824a261170c8e14aca0e /app
parentdb3d90cbcb41c5b9a62998b185c90c10f9d03968 (diff)
Make Note methods saner
Diffstat (limited to 'app')
-rw-r--r--app/helpers/notes_helper.rb4
-rw-r--r--app/mailers/notify.rb2
-rw-r--r--app/models/note.rb17
-rw-r--r--app/roles/static_model.rb8
-rw-r--r--app/views/notes/_note.html.haml6
5 files changed, 22 insertions, 15 deletions
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index 99db8b6f6b7..ffcc7acc8da 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -13,9 +13,7 @@ module NotesHelper
end
def link_to_commit_diff_line_note(note)
- return unless note.line_note?
-
- commit = note.target
+ commit = note.noteable
diff_index, diff_old_line, diff_new_line = note.line_code.split('_')
link_file = commit.diffs[diff_index.to_i].new_path
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 0afc1d31ef4..9e64b64a86e 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -29,7 +29,7 @@ class Notify < ActionMailer::Base
def note_commit_email(recipient_id, note_id)
@note = Note.find(note_id)
- @commit = @note.target
+ @commit = @note.noteable
@commit = CommitDecorator.decorate(@commit)
@project = @note.project
mail(to: recipient(recipient_id), subject: subject("note for commit #{@commit.short_id}", @commit.title))
diff --git a/app/models/note.rb b/app/models/note.rb
index ae51e486675..e2f4a89d7d6 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -48,11 +48,12 @@ class Note < ActiveRecord::Base
@notify_author ||= false
end
- def target
- if commit?
+ # override to return commits, which are not active record
+ def noteable
+ if for_commit?
project.commit(noteable_id)
else
- noteable
+ super
end
# Temp fix to prevent app crash
# if note commit id doesnt exist
@@ -74,22 +75,22 @@ class Note < ActiveRecord::Base
# Boolean
#
def notify_only_author?(user)
- commit? && commit_author &&
+ for_commit? && commit_author &&
commit_author.email != user.email
end
- def commit?
+ def for_commit?
noteable_type == "Commit"
end
- def line_note?
+ def for_diff_line?
line_code.present?
end
def commit_author
@commit_author ||=
- project.users.find_by_email(target.author_email) ||
- project.users.find_by_name(target.author_name)
+ project.users.find_by_email(noteable.author_email) ||
+ project.users.find_by_name(noteable.author_name)
rescue
nil
end
diff --git a/app/roles/static_model.rb b/app/roles/static_model.rb
index d67af2439c7..5b64be1f041 100644
--- a/app/roles/static_model.rb
+++ b/app/roles/static_model.rb
@@ -36,4 +36,12 @@ module StaticModel
def destroyed?
false
end
+
+ def ==(other)
+ if other.is_a? StaticModel
+ id == other.id
+ else
+ super
+ end
+ end
end
diff --git a/app/views/notes/_note.html.haml b/app/views/notes/_note.html.haml
index 0901e4b8302..70baa212d10 100644
--- a/app/views/notes/_note.html.haml
+++ b/app/views/notes/_note.html.haml
@@ -8,10 +8,10 @@
ago
- unless note_for_main_target?(note)
- - if note.commit?
+ - if note.for_commit?
%span.cgray
- on #{link_to note.target.short_id, project_commit_path(@project, note.target)}
- = link_to_commit_diff_line_note(note) if note.line_note?
+ on #{link_to note.noteable.short_id, project_commit_path(@project, note.noteable)}
+ = link_to_commit_diff_line_note(note) if note.for_diff_line?
-# only show vote if it's a note for the main target
- if note_for_main_target?(note)