From ec6cd4bbba81bc99a7383aad64d96a0d8dd0bcf4 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Sat, 22 Aug 2020 22:20:22 +0530 Subject: [PATCH] feat: Use order_by_name as default sort order for inbox/user (#1160) --- app/controllers/api/v1/accounts/agents_controller.rb | 2 +- app/controllers/api/v1/accounts/inboxes_controller.rb | 2 +- app/models/inbox.rb | 2 +- app/models/user.rb | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/accounts/agents_controller.rb b/app/controllers/api/v1/accounts/agents_controller.rb index 030c08045..dacd66e46 100644 --- a/app/controllers/api/v1/accounts/agents_controller.rb +++ b/app/controllers/api/v1/accounts/agents_controller.rb @@ -64,6 +64,6 @@ class Api::V1::Accounts::AgentsController < Api::V1::Accounts::BaseController end def agents - @agents ||= Current.account.users + @agents ||= Current.account.users.order_by_full_name end end diff --git a/app/controllers/api/v1/accounts/inboxes_controller.rb b/app/controllers/api/v1/accounts/inboxes_controller.rb index 9360b700f..d2b0dcb60 100644 --- a/app/controllers/api/v1/accounts/inboxes_controller.rb +++ b/app/controllers/api/v1/accounts/inboxes_controller.rb @@ -4,7 +4,7 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController before_action :check_authorization def index - @inboxes = policy_scope(Current.account.inboxes.order_by_id.includes(:channel, :avatar_attachment)) + @inboxes = policy_scope(Current.account.inboxes.order_by_name.includes(:channel, :avatar_attachment)) end def create diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 24e9fea56..efdeba6b8 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -46,7 +46,7 @@ class Inbox < ApplicationRecord after_destroy :delete_round_robin_agents - scope :order_by_id, -> { order(id: :asc) } + scope :order_by_name, -> { order('lower(name) ASC') } def add_member(user_id) member = inbox_members.new(user_id: user_id) diff --git a/app/models/user.rb b/app/models/user.rb index 34e4799ce..133b7d660 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -81,6 +81,8 @@ class User < ApplicationRecord after_create :create_access_token after_save :update_presence_in_redis, if: :saved_change_to_availability? + scope :order_by_full_name, -> { order('lower(name) ASC') } + def send_devise_notification(notification, *args) devise_mailer.send(notification, self, *args).deliver_later end