Class: Warrant::Tenant
- Includes:
- WarrantObject
- Defined in:
- lib/warrant/models/tenant.rb
Constant Summary collapse
- OBJECT_TYPE =
"tenant"
Instance Attribute Summary
Attributes inherited from Object
#created_at, #meta, #object_id, #object_type
Class Method Summary collapse
-
.batch_create(tenants, options = {}) ⇒ Array<Tenant>
Batch creates multiple tenants with given parameters.
-
.batch_delete(tenants, options = {}) ⇒ nil
Batch deletes multiple tenants with given parameters.
-
.create(params = {}, options = {}) ⇒ Tenant
Creates a tenant with the given parameters.
-
.delete(tenant_id, options = {}) ⇒ nil
Deletes a tenant with given tenant id.
-
.get(tenant_id, options = {}) ⇒ Tenant
Get a tenant with the given tenant_id.
-
.list(filters = {}, options = {}) ⇒ Array<Tenant>
Lists all tenants for your organization.
-
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Tenant>
List all tenants for a user.
-
.update(tenant_id, meta, options = {}) ⇒ Tenant
Updates a tenant with the given tenant_id.
Instance Method Summary collapse
-
#assign_feature(feature_id, relation: "member", options: {}) ⇒ Feature
Assign a feature to a tenant.
-
#assign_pricing_tier(pricing_tier_id, relation: "member", options: {}) ⇒ PricingTier
Assign a pricing tier to a tenant.
-
#assign_user(user_id, relation: "member", options: {}) ⇒ Warrant
Add a user to a tenant.
-
#has_feature?(feature_id, relation: "member", options: {}) ⇒ Boolean
Check whether a tenant has a given feature.
-
#list_features(filters = {}, options = {}) ⇒ Array<Feature>
List features for a tenant.
-
#list_pricing_tiers(filters = {}, options = {}) ⇒ Array<Feature>
List pricing tiers for a tenant.
-
#list_users(filters = {}, options = {}) ⇒ Array<User>
List all users for a tenant.
-
#remove_feature(feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a tenant.
-
#remove_pricing_tier(pricing_tier_id, relation: "member", options: {}) ⇒ nil
Remove a pricing_tier from a tenant.
-
#remove_user(user_id, relation: "member", options: {}) ⇒ nil
Remove a user from a tenant.
-
#update(meta, options = {}) ⇒ Tenant
Updates the tenant with the given params.
- #warrant_object_id ⇒ Object
- #warrant_object_type ⇒ Object
Class Method Details
.batch_create(tenants, options = {}) ⇒ Array<Tenant>
Batch creates multiple tenants with given parameters
54 55 56 57 |
# File 'lib/warrant/models/tenant.rb', line 54 def self.batch_create(tenants, = {}) res = Object.batch_create(tenants.map{ |tenant| { object_type: OBJECT_TYPE, object_id: tenant[:tenant_id], meta: tenant[:meta] }}, ) return res.map{ |obj| Tenant.new(obj.object_id, obj., obj.created_at)} end |
.batch_delete(tenants, options = {}) ⇒ nil
Batch deletes multiple tenants with given parameters
89 90 91 92 93 94 95 96 97 |
# File 'lib/warrant/models/tenant.rb', line 89 def self.batch_delete(tenants, = {}) return Object.batch_delete(tenants.map{ |tenant| if tenant.instance_of? Tenant { object_type: OBJECT_TYPE, object_id: tenant.object_id } else { object_type: OBJECT_TYPE, object_id: tenant[:tenant_id] } end }, ) end |
.create(params = {}, options = {}) ⇒ Tenant
Creates a tenant with the given parameters
32 33 34 35 |
# File 'lib/warrant/models/tenant.rb', line 32 def self.create(params = {}, = {}) object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:tenant_id], meta: params[:meta] }, ) return Tenant.new(object.object_id, object., object.created_at) end |
.delete(tenant_id, options = {}) ⇒ nil
Deletes a tenant with given tenant id
71 72 73 |
# File 'lib/warrant/models/tenant.rb', line 71 def self.delete(tenant_id, = {}) return Object.delete(OBJECT_TYPE, tenant_id, ) end |
.get(tenant_id, options = {}) ⇒ Tenant
Get a tenant with the given tenant_id
135 136 137 138 |
# File 'lib/warrant/models/tenant.rb', line 135 def self.get(tenant_id, = {}) object = Object.get(OBJECT_TYPE, tenant_id, ) return Tenant.new(object.object_id, object., object.created_at) end |
.list(filters = {}, options = {}) ⇒ Array<Tenant>
Lists all tenants for your organization
118 119 120 121 122 123 |
# File 'lib/warrant/models/tenant.rb', line 118 def self.list(filters = {}, = {}) filters.merge({ object_type: "tenant" }) list_response = Object.list(filters, ) tenants = list_response.results.map{ |object| Tenant.new(object.object_id, object., object.created_at)} return ListResponse.new(tenants, list_response.prev_cursor, list_response.next_cursor) end |
.list_for_user(user_id, filters = {}, options = {}) ⇒ Array<Tenant>
List all tenants for a user
227 228 229 230 231 |
# File 'lib/warrant/models/tenant.rb', line 227 def self.list_for_user(user_id, filters = {}, = {}) query_response = Warrant.query("select tenant where user:#{user_id} is *", filters: filters, options: ) tenants = query_response.results.map{ |result| Tenant.new(result.object_id, result.) } return ListResponse.new(tenants, query_response.prev_cursor, query_response.next_cursor) end |
.update(tenant_id, meta, options = {}) ⇒ Tenant
Updates a tenant with the given tenant_id
155 156 157 158 |
# File 'lib/warrant/models/tenant.rb', line 155 def self.update(tenant_id, , = {}) object = Object.update(OBJECT_TYPE, tenant_id, , ) return Tenant.new(object.object_id, object., object.created_at) end |
Instance Method Details
#assign_feature(feature_id, relation: "member", options: {}) ⇒ Feature
Assign a feature to a tenant
331 332 333 |
# File 'lib/warrant/models/tenant.rb', line 331 def assign_feature(feature_id, relation: "member", options: {}) return Feature.assign_to_tenant(tenant_id, feature_id, relation: relation, options: ) end |
#assign_pricing_tier(pricing_tier_id, relation: "member", options: {}) ⇒ PricingTier
Assign a pricing tier to a tenant
278 279 280 |
# File 'lib/warrant/models/tenant.rb', line 278 def assign_pricing_tier(pricing_tier_id, relation: "member", options: {}) return PricingTier.assign_to_tenant(tenant_id, pricing_tier_id, relation: relation, options: ) end |
#assign_user(user_id, relation: "member", options: {}) ⇒ Warrant
Add a user to a tenant
190 191 192 |
# File 'lib/warrant/models/tenant.rb', line 190 def assign_user(user_id, relation: "member", options: {}) return User.assign_to_tenant(tenant_id, user_id, relation: relation, options: ) end |
#has_feature?(feature_id, relation: "member", options: {}) ⇒ Boolean
Check whether a tenant has a given feature
364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/warrant/models/tenant.rb', line 364 def has_feature?(feature_id, relation: "member", options: {}) return Warrant.has_feature?({ feature_id: feature_id, relation: relation, subject: { object_type: "tenant", object_id: tenant_id }, context: [:context], debug: [:debug] }, ) end |
#list_features(filters = {}, options = {}) ⇒ Array<Feature>
List features for a tenant
315 316 317 |
# File 'lib/warrant/models/tenant.rb', line 315 def list_features(filters = {}, = {}) return Feature.list_for_tenant(tenant_id, filters, ) end |
#list_pricing_tiers(filters = {}, options = {}) ⇒ Array<Feature>
List pricing tiers for a tenant
262 263 264 |
# File 'lib/warrant/models/tenant.rb', line 262 def list_pricing_tiers(filters = {}, = {}) return PricingTier.list_for_tenant(tenant_id, filters, ) end |
#list_users(filters = {}, options = {}) ⇒ Array<User>
List all users for a tenant
241 242 243 |
# File 'lib/warrant/models/tenant.rb', line 241 def list_users(filters = {}, = {}) return User.list_for_tenant(tenant_id, filters, ) end |
#remove_feature(feature_id, relation: "member", options: {}) ⇒ nil
Remove a feature from a tenant
347 348 349 |
# File 'lib/warrant/models/tenant.rb', line 347 def remove_feature(feature_id, relation: "member", options: {}) return Feature.remove_from_tenant(tenant_id, feature_id, relation: relation, options: ) end |
#remove_pricing_tier(pricing_tier_id, relation: "member", options: {}) ⇒ nil
Remove a pricing_tier from a tenant
294 295 296 |
# File 'lib/warrant/models/tenant.rb', line 294 def remove_pricing_tier(pricing_tier_id, relation: "member", options: {}) return PricingTier.remove_from_tenant(tenant_id, pricing_tier_id, relation: relation, options: ) end |
#remove_user(user_id, relation: "member", options: {}) ⇒ nil
Remove a user from a tenant
205 206 207 |
# File 'lib/warrant/models/tenant.rb', line 205 def remove_user(user_id, relation: "member", options: {}) return User.remove_from_tenant(tenant_id, user_id, relation: relation, options: ) end |
#update(meta, options = {}) ⇒ Tenant
Updates the tenant with the given params
174 175 176 |
# File 'lib/warrant/models/tenant.rb', line 174 def update(, = {}) return Tenant.update(tenant_id, , ) end |
#warrant_object_id ⇒ Object
381 382 383 |
# File 'lib/warrant/models/tenant.rb', line 381 def warrant_object_id tenant_id end |
#warrant_object_type ⇒ Object
377 378 379 |
# File 'lib/warrant/models/tenant.rb', line 377 def warrant_object_type "tenant" end |