Module: Bp3::Core::Tenantable

Extended by:
ActiveSupport::Concern
Included in:
Test
Defined in:
lib/bp3/core/tenantable.rb

Instance Method Summary collapse

Instance Method Details

#set_sites_site_idObject (private)



16
17
18
19
20
# File 'lib/bp3/core/tenantable.rb', line 16

def set_sites_site_id
  return if sites_site_id || sites_site

  self.sites_site_id = GlobalRequestState.either_site_id
end

#set_tenant_idObject (private)



22
23
24
25
26
# File 'lib/bp3/core/tenantable.rb', line 22

def set_tenant_id
  return if tenant_id || tenant

  self.tenant_id = GlobalRequestState.either_tenant_id
end

#set_workspaces_workspace_idObject (private)



38
39
40
41
42
# File 'lib/bp3/core/tenantable.rb', line 38

def set_workspaces_workspace_id
  return if workspaces_workspace_id || workspaces_workspace

  self.workspaces_workspace_id = GlobalRequestState.either_workspace_id
end

#tenant_matches_siteObject (private)



28
29
30
31
32
33
34
35
36
# File 'lib/bp3/core/tenantable.rb', line 28

def tenant_matches_site
  tid = tenant_id || tenant&.id
  return if tid.nil?

  tenant ||= Tenant.find(tid)
  return if (sites_site_id || sites_site&.id) == tenant.sites_site_id

  errors.add(:tenant, :must_match_site)
end

#workspaces_workspace_matches_siteObject (private)



44
45
46
47
48
49
50
51
52
# File 'lib/bp3/core/tenantable.rb', line 44

def workspaces_workspace_matches_site
  wid = workspaces_workspace_id || workspaces_workspace&.id
  return if wid.nil?

  workspaces_workspace ||= Workspaces::Workspace.find(wid)
  return if (sites_site_id || sites_site&.id) == workspaces_workspace.sites_site_id

  errors.add(:workspaces_workspace, :must_match_site)
end