#251 - Disable subscription in community edition (#277)

* #251 - Disable subscription in community edition

* Hide billing routes in sidebar for community edition

* Remove subscription serializer if billing disabled
This commit is contained in:
Sojan Jose 2019-11-24 19:09:17 +05:30 committed by Sony Mathew
parent 54556bfd58
commit 78adcf822d
8 changed files with 70 additions and 41 deletions

View file

@ -19,12 +19,13 @@ AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
#sentry
SENTRY_DSN=
#chargebee
#### This environment variables are only required in hosted version which has billing
ENABLE_BILLING=
## chargebee settings
CHARGEBEE_API_KEY=
CHARGEBEE_SITE=
CHARGEBEE_WEBHOOK_USERNAME=
CHARGEBEE_WEBHOOK_PASSWORD=
#sentry
SENTRY_DSN=
CHARGEBEE_WEBHOOK_PASSWORD=

View file

@ -65,6 +65,10 @@ class ApplicationController < ActionController::Base
end
def check_subscription
# This block is left over from the initial version of chatwoot
# We might reuse this later in the hosted version of chatwoot.
return unless ENV['BILLING_ENABLED']
if current_subscription.trial? && current_subscription.expiry < Date.current
render json: { error: 'Trial Expired' }, status: :trial_expired
elsif current_subscription.cancelled?

View file

@ -5,6 +5,8 @@ class AsyncDispatcher < BaseDispatcher
end
def listeners
[ReportingListener.instance, SubscriptionListener.instance]
listeners = [ReportingListener.instance]
listeners << SubscriptionListener.instance if ENV['BILLING_ENABLED']
listeners
end
end

View file

@ -15,6 +15,8 @@
/>
</transition-group>
</div>
<!-- this block is only required in the hosted version with billing enabled -->
<transition name="fade" mode="out-in">
<woot-status-bar
v-if="shouldShowStatusBox"
@ -25,6 +27,7 @@
:show-button="isAdmin()"
/>
</transition>
<div class="bottom-nav">
<transition name="menu-slide">
<div
@ -33,16 +36,13 @@
class="dropdown-pane top"
>
<ul class="vertical dropdown menu">
<!-- <li><a href="#">Help & Support</a></li> -->
<li><a href="#" @click.prevent="logout()">Logout</a></li>
</ul>
</div>
</transition>
<div class="current-user" @click.prevent="showOptions()">
<thumbnail
:src="gravatarUrl()"
:username="currentUser.name"
></thumbnail>
<thumbnail :src="gravatarUrl()" :username="currentUser.name">
</thumbnail>
<div class="current-user--data">
<h3 class="current-user--name">
{{ currentUser.name }}
@ -55,7 +55,6 @@
class="current-user--options icon ion-android-more-vertical"
></span>
</div>
<!-- <router-link class="icon ion-arrow-graph-up-right" tag="span" to="/settings/reports" active-class="active"></router-link> -->
</div>
</aside>
</template>
@ -110,25 +109,23 @@ export default {
}
}
const { role } = this.currentUser;
return menuItems.filter(
menuItem =>
window.roleWiseRoutes[role].indexOf(menuItem.toStateName) > -1
);
},
dashboardPath() {
return frontendURL('dashboard');
if (!window.chatwootConfig.billingEnabled) {
menuItems = this.filterBillingRoutes(menuItems);
}
return this.filterMenuItemsByRole(menuItems);
},
currentUser() {
return Auth.getCurrentUser();
},
trialMessage() {
return `${this.daysLeft} ${this.$t('APP_GLOBAL.TRIAL_MESSAGE')}`;
dashboardPath() {
return frontendURL('dashboard');
},
shouldShowStatusBox() {
return (
this.subscriptionData.state === 'trial' ||
this.subscriptionData.state === 'cancelled'
window.chatwootConfig.billingEnabled &&
(this.subscriptionData.state === 'trial' ||
this.subscriptionData.state === 'cancelled')
);
},
statusBarClass() {
@ -140,16 +137,31 @@ export default {
}
return '';
},
trialMessage() {
return `${this.daysLeft} ${this.$t('APP_GLOBAL.TRIAL_MESSAGE')}`;
},
},
methods: {
logout() {
Auth.logout();
},
gravatarUrl() {
const hash = md5(this.currentUser.email);
return `${window.WootConstants.GRAVATAR_URL}${hash}?default=404`;
},
filterBillingRoutes(menuItems) {
return menuItems.filter(
menuItem => !menuItem.toState.includes('billing')
);
},
filterMenuItemsByRole(menuItems) {
const { role } = this.currentUser;
return menuItems.filter(
menuItem =>
window.roleWiseRoutes[role].indexOf(menuItem.toStateName) > -1
);
},
logout() {
Auth.logout();
},
showOptions() {
this.showOptionsMenu = !this.showOptionsMenu;
},

View file

@ -1,3 +1,6 @@
# This listener is left over from the initial version of chatwoot
# We might reuse this later in the hosted version of chatwoot.
class SubscriptionListener < BaseListener
def subscription_created(event)
subscription = event.data[:subscription]

View file

@ -42,7 +42,9 @@ class User < ApplicationRecord
end
def serializable_hash(options = nil)
super(options).merge(confirmed: confirmed?, subscription: account.try(:subscription).try(:summary))
serialized_user = super(options).merge(confirmed: confirmed?)
serialized_user.merge(subscription: account.try(:subscription).try(:summary)) if ENV['BILLING_ENABLED']
serialized_user
end
def notify_creation

View file

@ -31,7 +31,8 @@
<%= yield %>
<script>
window.chatwootConfig = {
fbAppId: '<%= ENV['FB_APP_ID'] %>'
fbAppId: '<%= ENV['FB_APP_ID'] %>',
billingEnabled: '<%= ENV['BILLING_ENABLED'] %>'
}
</script>
</body>

View file

@ -44,18 +44,6 @@ Rails.application.routes.draw do
end
end
resources :subscriptions, only: [:index] do
collection do
get :summary
end
end
resources :webhooks, only: [] do
collection do
post :chargebee
end
end
resources :reports, only: [] do
collection do
get :account
@ -79,6 +67,22 @@ Rails.application.routes.draw do
get :get_messages
end
end
# this block is only required if subscription via chargebee is enabled
if ENV['BILLING_ENABLED']
resources :subscriptions, only: [:index] do
collection do
get :summary
end
end
resources :webhooks, only: [] do
collection do
post :chargebee
end
end
end
end
end