Class: Biovision::Components::RegionsComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/services/biovision/components/regions_component.rb

Overview

Handler for regions component

Constant Summary collapse

SLUG =
'regions'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_country_idObject



13
14
15
# File 'app/services/biovision/components/regions_component.rb', line 13

def self.default_country_id
  Country.first&.id
end

.privilege_namesObject



9
10
11
# File 'app/services/biovision/components/regions_component.rb', line 9

def self.privilege_names
  %w[manager]
end

Instance Method Details

#allow_regions?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'app/services/biovision/components/regions_component.rb', line 17

def allow_regions?
  return true if allow?('manager')

  RegionUser.where(user: user).exists?
end

#allowed_region_idsObject



23
24
25
26
27
28
29
# File 'app/services/biovision/components/regions_component.rb', line 23

def allowed_region_ids
  return nil if allow?('manager')
  return nil if RegionUser.where(user: user, region_id: nil).exists?

  parent_region_ids = RegionUser.where(user: user).pluck(:region_id)
  parent_region_ids + RegionUser.allowed_region_ids(user)
end