blob: 739940c44ca5b498fff83b06491cd68206167262 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
|