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
#method_missing(method, *args, **kwargs, &block) ⇒ Object
121 122 123 124 125 126 127 |
# File 'app/models/panda_pal/organization.rb', line 121 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
.extend_platform_api(platform_type = CONST_PLATFORM_TYPE, &blk) ⇒ Object
Extend a particular type of Platform API.
131 132 133 134 |
# File 'app/models/panda_pal/organization.rb', line 131 def self.extend_platform_api(platform_type = CONST_PLATFORM_TYPE, &blk) scl = platform_type.organization_api scl.class_eval(&blk) end |
.for_apt_tenant(schema) ⇒ Object
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
#create_api(logic, expiration: nil, uses: nil, host: nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/panda_pal/organization.rb', line 89 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 |
#encryption_key ⇒ Object
79 80 81 82 83 84 85 86 87 |
# 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. if (Rails.application.secrets.secret_key_base) Rails.application.secrets.secret_key_base[0,32] else ENV["SECRET_KEY_BASE"][0,32] end end |
#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.
140 141 142 143 144 145 |
# File 'app/models/panda_pal/organization.rb', line 140 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 |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
… via method_missing/delegation if this is a multi-platform tool
113 114 115 116 117 118 119 |
# File 'app/models/panda_pal/organization.rb', line 113 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 |
#settings=(settings) ⇒ Object
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 |
#settings_panda_pal_super= ⇒ Object
50 |
# File 'app/models/panda_pal/organization.rb', line 50 alias_method "settings_panda_pal_super=", "settings=" |
#trusted_platform?(platform) ⇒ Boolean
Determines if the specified platform can create sessions in this organization
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/models/panda_pal/organization.rb', line 154 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 |