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
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-17 02:31:30 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-18 17:00:53 +0300
commitc29da3f8ca1d759b8cbecb91b6e0529b18cc5c85 (patch)
treeb60d38cea7b271f52307ec48df1a14327915edda /app/models/todo.rb
parent1e76245d4e8c5ecbd915c517b6c8923e9c4bbd2d (diff)
Trigger a todo for mentions on commits page
Diffstat (limited to 'app/models/todo.rb')
-rw-r--r--app/models/todo.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/app/models/todo.rb b/app/models/todo.rb
index 5f91991f781..b00a1b3dc7d 100644
--- a/app/models/todo.rb
+++ b/app/models/todo.rb
@@ -27,7 +27,9 @@ class Todo < ActiveRecord::Base
delegate :name, :email, to: :author, prefix: true, allow_nil: true
- validates :action, :project, :target, :user, presence: true
+ validates :action, :project, :target_type, :user, presence: true
+ validates :target_id, presence: true, if: ->(t) { t.target_type.present? && t.target_type != 'Commit' }
+ validates :commit_id, presence: true, if: ->(t) { t.target_type.present? && t.target_type == 'Commit' }
default_scope { reorder(id: :desc) }
@@ -50,4 +52,29 @@ class Todo < ActiveRecord::Base
target.title
end
end
+
+ def for_commit?
+ target_type == "Commit"
+ end
+
+ # override to return commits, which are not active record
+ def target
+ if for_commit?
+ project.commit(commit_id)
+ else
+ super
+ end
+ # Temp fix to prevent app crash
+ # if note commit id doesn't exist
+ rescue
+ nil
+ end
+
+ def to_reference
+ if for_commit?
+ Commit.truncate_sha(commit_id)
+ else
+ target.to_reference
+ end
+ end
end