Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/organizations/user_organizations_finder.rb')
-rw-r--r--app/finders/organizations/user_organizations_finder.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/finders/organizations/user_organizations_finder.rb b/app/finders/organizations/user_organizations_finder.rb
new file mode 100644
index 00000000000..739940c44ca
--- /dev/null
+++ b/app/finders/organizations/user_organizations_finder.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module Organizations
+ class UserOrganizationsFinder
+ def initialize(current_user, target_user, params = {})
+ @current_user = current_user
+ @target_user = target_user
+ @params = params
+ end
+
+ def execute
+ return Organizations::Organization.none unless can_read_user_organizations?
+ return Organizations::Organization.none if target_user.blank?
+
+ target_user.organizations
+ end
+
+ private
+
+ attr_reader :current_user, :target_user, :params
+
+ def can_read_user_organizations?
+ current_user&.can?(:read_user_organizations, target_user)
+ end
+ end
+end