diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /app/finders/crm/contacts_finder.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'app/finders/crm/contacts_finder.rb')
-rw-r--r-- | app/finders/crm/contacts_finder.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/finders/crm/contacts_finder.rb b/app/finders/crm/contacts_finder.rb index 29f3d6f0f16..58ec4cf8a47 100644 --- a/app/finders/crm/contacts_finder.rb +++ b/app/finders/crm/contacts_finder.rb @@ -16,6 +16,11 @@ module Crm attr_reader :params, :current_user + def self.counts_by_state(current_user, params = {}) + params = params.merge(sort: nil) + new(current_user, params).execute.counts_by_state + end + def initialize(current_user, params = {}) @current_user = current_user @params = params @@ -28,11 +33,25 @@ module Crm contacts = by_ids(contacts) contacts = by_state(contacts) contacts = by_search(contacts) - contacts.sort_by_name + sort_contacts(contacts) end private + def sort_contacts(contacts) + return contacts.sort_by_name unless @params.key?(:sort) + return contacts if @params[:sort].nil? + + field = @params[:sort][:field] + direction = @params[:sort][:direction] + + if field == 'organization' + contacts.sort_by_organization(direction) + else + contacts.sort_by_field(field, direction) + end + end + def root_group strong_memoize(:root_group) do group = params[:group]&.root_ancestor |