diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 03:11:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 03:11:02 +0300 |
commit | c95fc172145f1bdbc8d959b6cee31555fc545784 (patch) | |
tree | 5aa4940ddefb9bea164905d61916593cc265a05c /app/finders | |
parent | eda321fc0b96e44e296341f6288dd7f1a27ba93a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/crm/organizations_finder.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/finders/crm/organizations_finder.rb b/app/finders/crm/organizations_finder.rb index 5a8ab148ef3..69f72235c71 100644 --- a/app/finders/crm/organizations_finder.rb +++ b/app/finders/crm/organizations_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,20 @@ module Crm organizations = by_ids(organizations) organizations = by_search(organizations) organizations = by_state(organizations) - organizations.sort_by_name + sort_organizations(organizations) end private + def sort_organizations(organizations) + return organizations.sort_by_name unless @params.key?(:sort) + return organizations if @params[:sort].nil? + + field = @params[:sort][:field] + direction = @params[:sort][:direction] + organizations.sort_by_field(field, direction) + end + def root_group strong_memoize(:root_group) do group = params[:group]&.root_ancestor |