df27b3a174
Closes #9014 The only difference with #9014 is that I thoughed the author should also be able to assign the issue. If this is unwanted behavior Ill revert it.
53 lines
1.4 KiB
Ruby
53 lines
1.4 KiB
Ruby
class AutocompleteController < ApplicationController
|
|
skip_before_action :authenticate_user!, only: [:users]
|
|
before_action :find_users, only: [:users]
|
|
|
|
def users
|
|
@users ||= User.none
|
|
@users = @users.search(params[:search]) if params[:search].present?
|
|
@users = @users.active
|
|
@users = @users.reorder(:name)
|
|
@users = @users.page(params[:page]).per(PER_PAGE)
|
|
|
|
if params[:search].blank?
|
|
# Include current user if available to filter by "Me"
|
|
if params[:current_user] && current_user
|
|
@users = [*@users, current_user]
|
|
end
|
|
|
|
if params[:author_id]
|
|
@users = [User.find(params[:author_id]), *@users]
|
|
end
|
|
|
|
@users.uniq!
|
|
end
|
|
|
|
render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
|
|
end
|
|
|
|
def user
|
|
@user = User.find(params[:id])
|
|
render json: @user, only: [:name, :username, :id], methods: [:avatar_url]
|
|
end
|
|
|
|
private
|
|
|
|
def find_users
|
|
@users =
|
|
if params[:project_id].present?
|
|
project = Project.find(params[:project_id])
|
|
return render_404 unless can?(current_user, :read_project, project)
|
|
|
|
project.team.users
|
|
elsif params[:group_id].present?
|
|
group = Group.find(params[:group_id])
|
|
return render_404 unless can?(current_user, :read_group, group)
|
|
|
|
group.users
|
|
elsif current_user
|
|
User.all
|
|
else
|
|
User.none
|
|
end
|
|
end
|
|
end
|