Commit 0a4283b50adb10c13cf2f00c83e372549a004a05

Authored by Marin Jankovski
1 parent eda2c0c6

Extract sorting into a method.

app/controllers/projects_controller.rb
... ... @@ -130,14 +130,13 @@ class ProjectsController < ApplicationController
130 130 else
131 131 []
132 132 end
133   - team_members = @project.team.members.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
  133 + team_members = sorted(@project.team.members)
134 134 participants = team_members + participating
135   - #participating = @project.issues.map { |issue| issue.participants.sort_by(&:username).map { |user| { username: user.username, name: user.name } } }.flatten
136 135 @suggestions = {
137 136 emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } },
138 137 issues: @project.issues.select([:iid, :title, :description]),
139 138 mergerequests: @project.merge_requests.select([:iid, :title, :description]),
140   - members: participants.uniq
  139 + members: participants
141 140 }
142 141  
143 142 respond_to do |format|
... ... @@ -174,14 +173,19 @@ class ProjectsController < ApplicationController
174 173 end
175 174  
176 175 def participants_in(type, id)
177   - note = case type
  176 + users = case type
178 177 when "Issue", "MergeRequest"
179   - type.constantize.find_by_iid(id)
180   - when "Commits"
181   - type.constantize.find(id)
  178 + type.constantize.find_by_iid(id).participants
  179 + when "Commit"
  180 + author_ids = Note.for_commit_id(id).pluck(:author_id).uniq
  181 + User.where(id: author_ids)
182 182 else
183 183 []
184 184 end
185   - note.participants.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
  185 + sorted(users)
  186 + end
  187 +
  188 + def sorted(users)
  189 + users.uniq.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
186 190 end
187 191 end
... ...
app/models/user.rb
... ... @@ -169,7 +169,6 @@ class User < ActiveRecord::Base
169 169 scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all }
170 170 scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)') }
171 171 scope :ldap, -> { where(provider: 'ldap') }
172   - scope :participating, ->(notes){ where(id: notes.inc_author.map(&:author_id))}
173 172  
174 173 scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
175 174  
... ...