#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_SECRET_ACCESS_KEY=
AWS_REGION= 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_API_KEY=
CHARGEBEE_SITE= CHARGEBEE_SITE=
CHARGEBEE_WEBHOOK_USERNAME= CHARGEBEE_WEBHOOK_USERNAME=
CHARGEBEE_WEBHOOK_PASSWORD= CHARGEBEE_WEBHOOK_PASSWORD=
#sentry
SENTRY_DSN=

View File

@@ -65,6 +65,10 @@ class ApplicationController < ActionController::Base
end end
def check_subscription 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 if current_subscription.trial? && current_subscription.expiry < Date.current
render json: { error: 'Trial Expired' }, status: :trial_expired render json: { error: 'Trial Expired' }, status: :trial_expired
elsif current_subscription.cancelled? elsif current_subscription.cancelled?

View File

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

View File

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

View File

@@ -42,7 +42,9 @@ class User < ApplicationRecord
end end
def serializable_hash(options = nil) 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 end
def notify_creation def notify_creation

View File

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

View File

@@ -44,18 +44,6 @@ Rails.application.routes.draw do
end end
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 resources :reports, only: [] do
collection do collection do
get :account get :account
@@ -79,6 +67,22 @@ Rails.application.routes.draw do
get :get_messages get :get_messages
end end
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
end end