Commit eb7a9868002a3d96675a1509d75be52cfe43fa2f

Authored by Dmitriy Zaporozhets
2 parents f0adf28e 9dd58c32

Merge branch 'improve_at_mentions' into 'master'

Allow at mentions for people who are not members of the project
CHANGELOG
  1 +v 6.8.0
  2 + - Ability to at mention users that are participating in issue and merge req. discussion
  3 +
  4 +v 6.7.2
  5 + - Fix upgrader script
  6 +
  7 +v 6.7.1
  8 + - Fix GitLab CI integration
  9 +
1 10 v 6.7.0
2 11 - Increased the example Nginx client_max_body_size from 5MB to 20MB, consider updating it manually on existing installations
3 12 - Add support for Gemnasium as a Project Service (Olivier Gonzalez)
... ...
VERSION
1   -6.7.0
  1 +6.7.2
... ...
app/controllers/projects_controller.rb
... ... @@ -123,11 +123,20 @@ class ProjectsController < ApplicationController
123 123 end
124 124  
125 125 def autocomplete_sources
  126 + note_type = params['type']
  127 + note_id = params['type_id']
  128 + participating = if note_type && note_id
  129 + participants_in(note_type, note_id)
  130 + else
  131 + []
  132 + end
  133 + team_members = sorted(@project.team.members)
  134 + participants = team_members + participating
126 135 @suggestions = {
127 136 emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } },
128 137 issues: @project.issues.select([:iid, :title, :description]),
129 138 mergerequests: @project.merge_requests.select([:iid, :title, :description]),
130   - members: @project.team.members.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
  139 + members: participants.uniq
131 140 }
132 141  
133 142 respond_to do |format|
... ... @@ -162,4 +171,25 @@ class ProjectsController < ApplicationController
162 171 def user_layout
163 172 current_user ? "projects" : "public_projects"
164 173 end
  174 +
  175 + def participants_in(type, id)
  176 + users = case type
  177 + when "Issue"
  178 + issue = @project.issues.find_by_iid(id)
  179 + issue ? issue.participants : []
  180 + when "MergeRequest"
  181 + merge_request = @project.merge_requests.find_by_iid(id)
  182 + merge_request ? merge_request.participants : []
  183 + when "Commit"
  184 + author_ids = Note.for_commit_id(id).pluck(:author_id).uniq
  185 + User.where(id: author_ids)
  186 + else
  187 + []
  188 + end
  189 + sorted(users)
  190 + end
  191 +
  192 + def sorted(users)
  193 + users.uniq.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
  194 + end
165 195 end
... ...
app/views/layouts/_init_auto_complete.html.haml
1 1 :javascript
2   - GitLab.GfmAutoComplete.dataSource = "#{autocomplete_sources_project_path(@project)}"
  2 + GitLab.GfmAutoComplete.dataSource = "#{autocomplete_sources_project_path(@project, type: @noteable.class, type_id: params[:id])}"
3 3 GitLab.GfmAutoComplete.setup();
... ...
lib/gitlab/markdown.rb
... ... @@ -166,8 +166,8 @@ module Gitlab
166 166 end
167 167  
168 168 def reference_user(identifier)
169   - if member = @project.team_members.find { |user| user.username == identifier }
170   - link_to("@#{identifier}", user_url(identifier), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}")) if member
  169 + if user = User.find_by_username(identifier)
  170 + link_to("@#{identifier}", user_url(identifier), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}"))
171 171 end
172 172 end
173 173  
... ...