diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-10-14 16:20:11 +0200 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-10-14 16:20:11 +0200 |
commit | 4a5b77188ec7525d1c3a1ee925c8791f841b040c (patch) | |
tree | c691a9271c6c4229db9893c34880abfccefbe95a | |
parent | 61d8f9617681973f04d264762b54840d44dea02a (diff) | |
download | gitlab-ce-4a5b77188ec7525d1c3a1ee925c8791f841b040c.tar.gz |
Participable doesn't need to know about Mentionable
-rw-r--r-- | app/models/commit.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/mentionable.rb | 6 | ||||
-rw-r--r-- | app/models/concerns/participable.rb | 9 | ||||
-rw-r--r-- | app/models/note.rb | 4 |
5 files changed, 16 insertions, 11 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index aff329d71fa..95ac7156bed 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -2,13 +2,13 @@ class Commit extend ActiveModel::Naming include ActiveModel::Conversion - include Mentionable include Participable + include Mentionable include Referable include StaticModel attr_mentionable :safe_message - participant :author, :committer, :notes, :mentioned_users + participant :author, :committer, :notes attr_accessor :project diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 4db4ffb2e79..feee8460b86 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -6,8 +6,8 @@ # module Issuable extend ActiveSupport::Concern - include Mentionable include Participable + include Mentionable included do belongs_to :author, class_name: "User" @@ -47,7 +47,7 @@ module Issuable prefix: true attr_mentionable :title, :description - participant :author, :assignee, :notes, :mentioned_users + participant :author, :assignee, :notes end module ClassMethods diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index 9339ecc4bce..715fc6f689d 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -20,6 +20,12 @@ module Mentionable end end + included do + if self < Participable + participant ->(current_user) { mentioned_users(current_user, load_lazy_references: false) } + end + end + # Returns the text used as the body of a Note when this object is referenced # # By default this will be the class name and the result of calling diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb index 7a2bea567df..0888de62f0a 100644 --- a/app/models/concerns/participable.rb +++ b/app/models/concerns/participable.rb @@ -12,7 +12,7 @@ # # # ... # -# participant :author, :assignee, :mentioned_users, :notes +# participant :author, :assignee, :notes, ->(current_user) { mentioned_users(current_user) } # end # # issue = Issue.last @@ -39,12 +39,11 @@ module Participable # Save result into variable if you are going to reuse it inside same request def participants(current_user = self.author, project = self.project, load_lazy_references: true) participants = self.class.participant_attrs.flat_map do |attr| - meth = method(attr) value = - if attr == :mentioned_users - meth.call(current_user, load_lazy_references: false) + if attr.respond_to?(:call) + instance_exec(current_user, &attr) else - meth.call + send(attr) end participants_for(value, current_user, project) diff --git a/app/models/note.rb b/app/models/note.rb index de3b6df88f7..2fbe4784159 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -22,14 +22,14 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' class Note < ActiveRecord::Base - include Mentionable include Gitlab::CurrentSettings include Participable + include Mentionable default_value_for :system, false attr_mentionable :note - participant :author, :mentioned_users + participant :author belongs_to :project belongs_to :noteable, polymorphic: true |