chore: Validation for purchased pricing_plan_quantity (#8809)
- Add validations based on purchased pricing_plan_quantity - Modify the Dashboard to support the new error message
This commit is contained in:
@@ -130,15 +130,23 @@ export default {
|
|||||||
this.showAlert(this.$t('AGENT_MGMT.ADD.API.SUCCESS_MESSAGE'));
|
this.showAlert(this.$t('AGENT_MGMT.ADD.API.SUCCESS_MESSAGE'));
|
||||||
this.onClose();
|
this.onClose();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const { response: { data: { error: errorResponse = '' } = {} } = {} } =
|
const {
|
||||||
error;
|
response: {
|
||||||
|
data: {
|
||||||
|
error: errorResponse = '',
|
||||||
|
attributes: attributes = [],
|
||||||
|
message: attrError = '',
|
||||||
|
} = {},
|
||||||
|
} = {},
|
||||||
|
} = error;
|
||||||
|
|
||||||
let errorMessage = '';
|
let errorMessage = '';
|
||||||
if (error.response.status === 422) {
|
if (error.response.status === 422 && !attributes.includes('base')) {
|
||||||
errorMessage = this.$t('AGENT_MGMT.ADD.API.EXIST_MESSAGE');
|
errorMessage = this.$t('AGENT_MGMT.ADD.API.EXIST_MESSAGE');
|
||||||
} else {
|
} else {
|
||||||
errorMessage = this.$t('AGENT_MGMT.ADD.API.ERROR_MESSAGE');
|
errorMessage = this.$t('AGENT_MGMT.ADD.API.ERROR_MESSAGE');
|
||||||
}
|
}
|
||||||
this.showAlert(errorResponse || errorMessage);
|
this.showAlert(errorResponse || attrError || errorMessage);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -161,3 +161,4 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
User.include_mod_with('Audit::User')
|
User.include_mod_with('Audit::User')
|
||||||
|
User.include_mod_with('Concerns::User')
|
||||||
|
|||||||
13
enterprise/app/models/enterprise/concerns/user.rb
Normal file
13
enterprise/app/models/enterprise/concerns/user.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module Enterprise::Concerns::User
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
before_validation :ensure_installation_pricing_plan_quantity
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensure_installation_pricing_plan_quantity
|
||||||
|
return unless ChatwootHub.pricing_plan == 'premium'
|
||||||
|
|
||||||
|
errors.add(:base, 'User limit reached. Please purchase more licenses from super admin') if User.count >= ChatwootHub.pricing_plan_quantity
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,6 +5,44 @@ require 'rails_helper'
|
|||||||
RSpec.describe User do
|
RSpec.describe User do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
describe 'before validation for pricing plans' do
|
||||||
|
let(:new_user) { build(:user) }
|
||||||
|
|
||||||
|
context 'when pricing plan is not premium' do
|
||||||
|
before do
|
||||||
|
allow(ChatwootHub).to receive(:pricing_plan).and_return('community')
|
||||||
|
allow(ChatwootHub).to receive(:pricing_plan_quantity).and_return(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not add an error to the user' do
|
||||||
|
new_user.valid?
|
||||||
|
expect(new_user.errors[:base]).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when pricing plan is premium' do
|
||||||
|
before do
|
||||||
|
allow(ChatwootHub).to receive(:pricing_plan).and_return('premium')
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the user limit is reached' do
|
||||||
|
it 'adds an error to the user' do
|
||||||
|
allow(ChatwootHub).to receive(:pricing_plan_quantity).and_return(1)
|
||||||
|
user.valid?
|
||||||
|
expect(user.errors[:base]).to include('User limit reached. Please purchase more licenses from super admin')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the user limit is not reached' do
|
||||||
|
it 'does not add an error to the user' do
|
||||||
|
allow(ChatwootHub).to receive(:pricing_plan_quantity).and_return(2)
|
||||||
|
user.valid?
|
||||||
|
expect(user.errors[:base]).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'audit log' do
|
describe 'audit log' do
|
||||||
context 'when user is created' do
|
context 'when user is created' do
|
||||||
it 'has no associated audit log created' do
|
it 'has no associated audit log created' do
|
||||||
|
|||||||
Reference in New Issue
Block a user