Skip to content

Commit

Permalink
Filter private usernames in selectize functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead committed Mar 24, 2023
1 parent 329e330 commit d7a4614
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def update
end

def search
fields = %i[username id name]
fields << :email if current_user.is_admin?
respond_to do |format|
format.json do
render json: { users:
User.active.where(
'username ILIKE :search OR email ILIKE :search OR name ILIKE :search',
search: "%#{params[:query]}%"
).as_json(only:
%i[username id name email], methods: :dropdwon_display) }
).as_json(only: fields, methods: :dropdwon_display) }
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ def self.empty?
end

def dropdwon_display
"#{name} (#{username} #{email})"
more_info = email_public? ? username : "#{username} #{email}"
"#{name} (#{more_info})"
end

private
Expand Down

0 comments on commit d7a4614

Please sign in to comment.