Module: Rhino
- Defined in:
- lib/rhino.rb,
lib/rhino/query.rb,
lib/rhino/engine.rb,
lib/rhino/routes.rb,
lib/rhino/context.rb,
lib/rhino/railtie.rb,
lib/rhino/version.rb,
lib/rhino/auth_hooks.rb,
lib/rhino/auth_rejected.rb,
lib/rhino/configuration.rb,
lib/rhino/query_builder.rb,
lib/rhino/resource_scope.rb,
lib/rhino/blueprint/sorter.rb,
lib/rhino/group_membership.rb,
lib/rhino/models/audit_log.rb,
lib/rhino/concerns/has_uuid.rb,
lib/rhino/concerns/has_rhino.rb,
lib/rhino/models/rhino_model.rb,
lib/rhino/permissions_migrator.rb,
lib/rhino/commands/base_command.rb,
lib/rhino/missing_tenant_context.rb,
lib/rhino/scopes_to_organization.rb,
lib/rhino/concerns/has_auto_scope.rb,
lib/rhino/concerns/has_validation.rb,
lib/rhino/scope_not_allowed_error.rb,
lib/rhino/commands/install_command.rb,
lib/rhino/concerns/has_audit_trail.rb,
lib/rhino/concerns/has_permissions.rb,
lib/rhino/concerns/hidable_columns.rb,
lib/rhino/policies/resource_policy.rb,
lib/rhino/commands/generate_command.rb,
lib/rhino/mailers/invitation_mailer.rb,
lib/rhino/routing/domain_constraint.rb,
lib/rhino/blueprint/blueprint_parser.rb,
lib/rhino/blueprint/manifest_manager.rb,
lib/rhino/commands/blueprint_command.rb,
lib/rhino/policies/invitation_policy.rb,
lib/rhino/controllers/auth_controller.rb,
lib/rhino/blueprint/blueprint_validator.rb,
lib/rhino/commands/export_types_command.rb,
lib/rhino/routing/route_group_validator.rb,
lib/rhino/models/organization_invitation.rb,
lib/rhino/commands/export_postman_command.rb,
lib/rhino/commands/invitation_link_command.rb,
lib/rhino/concerns/belongs_to_organization.rb,
lib/rhino/controllers/resources_controller.rb,
lib/rhino/controllers/invitations_controller.rb,
lib/rhino/blueprint/generators/test_generator.rb,
lib/rhino/blueprint/generators/policy_generator.rb,
lib/rhino/blueprint/generators/seeder_generator.rb,
lib/rhino/blueprint/generators/factory_generator.rb,
lib/rhino/middleware/resolve_organization_from_route.rb
Defined Under Namespace
Modules: BelongsToOrganization, Blueprint, Commands, Context, GroupMembership, HasAuditTrail, HasAutoScope, HasPermissions, HasRhino, HasUuid, HasValidation, HidableColumns, Middleware, Routes, Routing, ScopesToOrganization Classes: AuditLog, AuthController, AuthHooks, AuthRejected, Configuration, Engine, InvitationMailer, InvitationPolicy, InvitationsController, MissingTenantContext, OrganizationInvitation, PendingScopedContext, PermissionsMigrator, QueryBuilder, Railtie, ResourcePolicy, ResourceScope, ResourcesController, RhinoModel, RouteGroupConflictError, ScopeNotAllowedError
Constant Summary collapse
- VERSION =
"4.5.0"
Class Method Summary collapse
-
.apply_named_scope(relation, model_class, scope_name = nil) ⇒ Object
private
Apply a whitelisted named scope to
relationformodel_class. - .configuration ⇒ Object (also: config)
- .configure {|configuration| ... } ⇒ Object
-
.context ⇒ Object
The ambient context resolver.
-
.for_user(user) ⇒ Object
Begin the fluent explicit builder for
user. -
.query(model_class) ⇒ Object
Build a tenant-scoped relation for
model_classusing the ambient context. - .reset_configuration! ⇒ Object
-
.scoped_query(model_class, scope_name = nil) ⇒ Object
Build a tenant-scoped relation and apply a whitelisted ?scope= named scope on top of it.
Class Method Details
.apply_named_scope(relation, model_class, scope_name = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Apply a whitelisted named scope to relation for model_class.
Shared by Rhino.scoped_query and PendingScopedContext#scoped_query. Uses the
same allowed_scopes / default_rhino_scope mechanism as the QueryBuilder.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rhino/query.rb', line 60 def apply_named_scope(relation, model_class, scope_name = nil) requested = scope_name.to_s.presence name = requested ? requested.underscore : model_class.try(:default_rhino_scope) return relation unless name allowed = model_class.try(:allowed_scopes) || {} entry = allowed[name] entry ||= name.to_sym if name == model_class.try(:default_rhino_scope) raise Rhino::ScopeNotAllowedError, (requested || name) if entry.nil? user = defined?(RequestStore) ? RequestStore.store[:rhino_current_user] : nil case entry when Symbol relation.merge(model_class.public_send(entry)) when Proc entry.call(relation, user) else entry.new.apply(relation) end end |
.configuration ⇒ Object Also known as: config
26 27 28 |
# File 'lib/rhino.rb', line 26 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
22 23 24 |
# File 'lib/rhino.rb', line 22 def configure yield(configuration) end |
.context ⇒ Object
The ambient context resolver.
52 53 54 |
# File 'lib/rhino/query.rb', line 52 def context Rhino::Context end |
.for_user(user) ⇒ Object
Begin the fluent explicit builder for user.
47 48 49 |
# File 'lib/rhino/query.rb', line 47 def for_user(user) Rhino::PendingScopedContext.new(user: user) end |
.query(model_class) ⇒ Object
Build a tenant-scoped relation for model_class using the ambient context.
Applies the same org scoping as CRUD plus the model's default_scopes (BelongsToOrganization / HasAutoScope read RequestStore at BUILD time).
Fail closed: an org-scopable model with no org context RAISES Rhino::MissingTenantContext rather than returning an unscoped relation.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rhino/query.rb', line 24 def query(model_class) org = Rhino::Context.organization # default_scope (org via RequestStore) + auto-scope are baked here at build. relation = model_class.all if Rhino::ScopesToOrganization.organization_scoped?(model_class) raise Rhino::MissingTenantContext, model_class.name unless org relation = Rhino::ScopesToOrganization.scope_to_organization(relation, model_class, org, strict: true) end relation end |
.reset_configuration! ⇒ Object
32 33 34 |
# File 'lib/rhino.rb', line 32 def reset_configuration! @configuration = Configuration.new end |
.scoped_query(model_class, scope_name = nil) ⇒ Object
Build a tenant-scoped relation and apply a whitelisted ?scope= named scope
on top of it. scope_name is the wire name (camelCase accepted); nil falls
back to the model's rhino_default_scope.
42 43 44 |
# File 'lib/rhino/query.rb', line 42 def scoped_query(model_class, scope_name = nil) apply_named_scope(query(model_class), model_class, scope_name) end |