Class: PandaPal::Organization
- Inherits:
-
PandaPalRecord
- Object
- ActiveRecord::Base
- PandaPalRecord
- PandaPal::Organization
- Includes:
- PandaPal::OrganizationConcerns::MultiDatabaseSharding, PandaPal::OrganizationConcerns::OrganizationBuilder, PandaPal::OrganizationConcerns::SettingsValidation, PandaPal::OrganizationConcerns::TaskScheduling, PandaPal::OrganizationConcerns::TenantHandling, SkipSymmetricEncAttrEncrypted
- Defined in:
- app/models/panda_pal/organization.rb
Constant Summary collapse
- CONST_PLATFORM_TYPE =
nil
Class Method Summary collapse
-
.extend_platform_api(platform_type = CONST_PLATFORM_TYPE, &blk) ⇒ Object
Extend a particular type of Platform API.
- .for_apt_tenant(schema) ⇒ Object
Instance Method Summary collapse
- #create_api(logic, expiration: nil, uses: nil, host: nil) ⇒ Object
- #encryption_key ⇒ Object
- #method_missing(method, *args, **kwargs, &block) ⇒ Object
-
#platform_api(platform_type = primary_platform) ⇒ Object
Retrieve the specified Platform API for this Organization.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
…
- #settings=(settings) ⇒ Object
- #settings_panda_pal_super= ⇒ Object
-
#trusted_platform?(platform) ⇒ Boolean
Determines if the specified platform can create sessions in this organization.
Methods included from PandaPal::OrganizationConcerns::MultiDatabaseSharding
Methods included from PandaPal::OrganizationConcerns::TenantHandling
#rename!, #switch_tenant, #tenant_name
Methods included from PandaPal::OrganizationConcerns::TaskScheduling
build_settings_entry, #generate_schedule, #sync_schedule
Methods included from PandaPal::OrganizationConcerns::SettingsValidation
#settings_structure, #validate_settings
Methods included from PandaPal::OrganizationConcerns::OrganizationBuilder
#generate_orgbuilder_ruby, #interactive_install!, #interactive_update!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink #method_missing(method, *args, **kwargs, &block) ⇒ Object
[View source]
122 123 124 125 126 127 128 |
# File 'app/models/panda_pal/organization.rb', line 122 def method_missing(method, *args, **kwargs, &block) if (self.class == PandaPal::Organization) && (plat_api = platform_api).present? plat_api.send(method, *args, **kwargs, &block) else super end end |
Class Method Details
permalink .extend_platform_api(platform_type = CONST_PLATFORM_TYPE, &blk) ⇒ Object
Extend a particular type of Platform API.
132 133 134 135 |
# File 'app/models/panda_pal/organization.rb', line 132 def self.extend_platform_api(platform_type = CONST_PLATFORM_TYPE, &blk) scl = platform_type.organization_api scl.class_eval(&blk) end |
permalink .for_apt_tenant(schema) ⇒ Object
[View source]
74 75 76 77 |
# File 'app/models/panda_pal/organization.rb', line 74 def self.for_apt_tenant(schema) shard, schema = Apartment::Tenant.split_tenant(schema) find_by(name: schema) end |
Instance Method Details
permalink #create_api(logic, expiration: nil, uses: nil, host: nil) ⇒ Object
[View source]
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/panda_pal/organization.rb', line 90 def create_api(logic, expiration: nil, uses: nil, host: nil) switch_tenant do logic = "current_organization.#{logic}" if logic.is_a?(Symbol) ac = ApiCall.create!( logic: logic, expiration: expiration, uses_remaining: uses, ) ac.call_url(host: host) end end |
permalink #encryption_key ⇒ Object
[View source]
79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/panda_pal/organization.rb', line 79 def encryption_key # production environment might not have loaded secret_key_base yet. # In that case, just read it from env. secret_key_base = Rails.application.try(:secret_key_base) secret_key_base ||= Rails.application.credentials.secret_key_base if Rails.version > "7.0" secret_key_base ||= Rails.application.secrets.secret_key_base if Rails.version < "7.2" secret_key_base ||= ENV["SECRET_KEY_BASE"] secret_key_base[0,32] end |
permalink #platform_api(platform_type = primary_platform) ⇒ Object
Retrieve the specified Platform API for this Organization. If only a single Platform is used (when lti_options is a constant string or nil), passing the platform_type is unnecessary
The API is currently an Organization subclass (using ‘becomes()`), but such may change.
141 142 143 144 145 146 |
# File 'app/models/panda_pal/organization.rb', line 141 def platform_api(platform_type = primary_platform) return nil if platform_type.nil? scl = platform_type.organization_api return self if scl == self.class becomes(scl) end |
permalink #respond_to_missing?(name, include_private = false) ⇒ Boolean
… via method_missing/delegation if this is a multi-platform tool
114 115 116 117 118 119 120 |
# File 'app/models/panda_pal/organization.rb', line 114 def respond_to_missing?(name, include_private = false) if (self.class == PandaPal::Organization) && (plat_api = platform_api).present? plat_api.respond_to?(name, include_private) else super end end |
permalink #settings=(settings) ⇒ Object
[View source]
51 52 53 54 |
# File 'app/models/panda_pal/organization.rb', line 51 def settings=(settings) settings = settings.with_indifferent_access if settings.is_a?(Hash) && !settings.is_a?(HashWithIndifferentAccess) self.settings_panda_pal_super = settings end |
permalink #settings_panda_pal_super= ⇒ Object
[View source]
50 |
# File 'app/models/panda_pal/organization.rb', line 50 alias_method "settings_panda_pal_super=", "settings=" |
permalink #trusted_platform?(platform) ⇒ Boolean
Determines if the specified platform can create sessions in this organization
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/models/panda_pal/organization.rb', line 155 def trusted_platform?(platform) # Trust Instructure-hosted Canvas return true if platform.is_a?(PandaPal::Platform::Canvas) && platform.is_trusted_env? # Trust issuers added to the Org settings if (issuer = platform.platform_uri rescue nil).present? trusted_issuers = settings.dig(:lti, :trusted_platforms) || [] return true if trusted_issuers.include?(issuer) end false end |