feat: Add APIs for limit check in accounts (#7242)

This commit is contained in:
Shivam Mishra
2023-06-15 20:11:40 -07:00
committed by GitHub
parent 0d465362ac
commit e8a27bea4b
9 changed files with 223 additions and 5 deletions
+21
View File
@@ -0,0 +1,21 @@
module BillingHelper
private
def default_plan?(account)
installation_config = InstallationConfig.find_by(name: 'CHATWOOT_CLOUD_PLANS')
default_plan = installation_config&.value&.first
# Return false if not plans are configured, so that no checks are enforced
return false if default_plan.blank?
account.custom_attributes['plan_name'].nil? || account.custom_attributes['plan_name'] == default_plan['name']
end
def conversations_this_month(account)
account.conversations.where('created_at > ?', 30.days.ago).count
end
def non_web_inboxes(account)
account.inboxes.where.not(channel_type: Channel::WebWidget.to_s).count
end
end
+4
View File
@@ -7,6 +7,10 @@ class AccountPolicy < ApplicationPolicy
@account_user.administrator? || @account_user.agent?
end
def limits?
@account_user.administrator?
end
def update?
@account_user.administrator?
end
@@ -4,6 +4,8 @@ if resource.custom_attributes.present?
json.custom_attributes do
json.plan_name resource.custom_attributes['plan_name']
json.subscribed_quantity resource.custom_attributes['subscribed_quantity']
json.subscription_status resource.custom_attributes['subscription_status']
json.subscription_ends_on resource.custom_attributes['subscription_ends_on']
end
end
json.domain @account.domain