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:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-24 23:13:00 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-24 23:13:00 +0400
commitd41940d36ee8ff693a3c22d6c317e864b53792f0 (patch)
tree60a0cf370682356e030eda6c6862cab3ea744ec0 /app/models/concerns
parent106764ab3b42f9d81a6ad81f2611ea1d78d7ae05 (diff)
parent884498c59f7083423eac7232091ff24215f4a0c7 (diff)
Merge branch 'master' into 6-0-dev
Conflicts: app/views/projects/issues/show.html.haml db/fixtures/development/09_issues.rb db/fixtures/development/10_merge_requests.rb
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/issuable.rb15
-rw-r--r--app/models/concerns/mentionable.rb37
2 files changed, 52 insertions, 0 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index cb238c15ed8..8868e818daa 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -6,6 +6,7 @@
#
module Issuable
extend ActiveSupport::Concern
+ include Mentionable
included do
belongs_to :project
@@ -96,4 +97,18 @@ module Issuable
def votes_count
upvotes + downvotes
end
+
+ # Return all users participating on the discussion
+ def participants
+ users = []
+ users << author
+ users << assignee if is_assigned?
+ mentions = []
+ mentions << self.mentioned_users
+ notes.each do |note|
+ users << note.author
+ mentions << note.mentioned_users
+ end
+ users.concat(mentions.reduce([], :|)).uniq
+ end
end
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
new file mode 100644
index 00000000000..f22070f8504
--- /dev/null
+++ b/app/models/concerns/mentionable.rb
@@ -0,0 +1,37 @@
+# == Mentionable concern
+#
+# Contains common functionality shared between Issues and Notes
+#
+# Used by Issue, Note
+#
+module Mentionable
+ extend ActiveSupport::Concern
+
+ def mentioned_users
+ users = []
+ return users if mentionable_text.blank?
+ has_project = self.respond_to? :project
+ matches = mentionable_text.scan(/@[a-zA-Z][a-zA-Z0-9_\-\.]*/)
+ matches.each do |match|
+ identifier = match.delete "@"
+ if has_project
+ id = project.users_projects.joins(:user).where(users: { username: identifier }).pluck(:user_id).first
+ else
+ id = User.where(username: identifier).pluck(:id).first
+ end
+ users << User.find(id) unless id.blank?
+ end
+ users.uniq
+ end
+
+ def mentionable_text
+ if self.class == Issue
+ description
+ elsif self.class == Note
+ note
+ else
+ nil
+ end
+ end
+
+end