fix: Facebook reauthorization mailer (#4695)
This commit is contained in:
parent
bad24f97ab
commit
772d92a4d3
9 changed files with 49 additions and 5 deletions
|
@ -27,7 +27,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
|
|||
end
|
||||
ensure_contact_avatar
|
||||
rescue Koala::Facebook::AuthenticationError
|
||||
Rails.logger.error "Facebook Authorization expired for Inbox #{@inbox.id}"
|
||||
@inbox.channel.authorization_error!
|
||||
rescue StandardError => e
|
||||
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
||||
true
|
||||
|
|
|
@ -95,6 +95,7 @@ export default {
|
|||
),
|
||||
type: inbox.channel_type,
|
||||
phoneNumber: inbox.phone_number,
|
||||
reauthorizationRequired: inbox.reauthorization_required,
|
||||
}))
|
||||
.sort((a, b) =>
|
||||
a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1
|
||||
|
|
|
@ -30,6 +30,14 @@
|
|||
<span v-if="count" class="badge" :class="{ secondary: !isActive }">
|
||||
{{ count }}
|
||||
</span>
|
||||
<span v-if="warningIcon" class="badge--icon">
|
||||
<fluent-icon
|
||||
v-tooltip.top-end="$t('SIDEBAR.FACEBOOK_REAUTHORIZE')"
|
||||
class="inbox-icon"
|
||||
:icon="warningIcon"
|
||||
size="12"
|
||||
/>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</router-link>
|
||||
|
@ -57,6 +65,10 @@ export default {
|
|||
type: String,
|
||||
default: '',
|
||||
},
|
||||
warningIcon: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
count: {
|
||||
type: String,
|
||||
default: '',
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
:label-color="child.color"
|
||||
:should-truncate="child.truncateLabel"
|
||||
:icon="computedInboxClass(child)"
|
||||
:warning-icon="computedInboxErrorClass(child)"
|
||||
/>
|
||||
<router-link
|
||||
v-if="showItem(menuItem)"
|
||||
|
@ -63,7 +64,10 @@
|
|||
import { mapGetters } from 'vuex';
|
||||
|
||||
import adminMixin from '../../../mixins/isAdmin';
|
||||
import { getInboxClassByType } from 'dashboard/helper/inbox';
|
||||
import {
|
||||
getInboxClassByType,
|
||||
getInboxWarningIconClass,
|
||||
} from 'dashboard/helper/inbox';
|
||||
|
||||
import SecondaryChildNavItem from './SecondaryChildNavItem';
|
||||
|
||||
|
@ -136,6 +140,15 @@ export default {
|
|||
const classByType = getInboxClassByType(type, phoneNumber);
|
||||
return classByType;
|
||||
},
|
||||
computedInboxErrorClass(child) {
|
||||
const { type, reauthorizationRequired } = child;
|
||||
if (!type) return '';
|
||||
const warningClass = getInboxWarningIconClass(
|
||||
type,
|
||||
reauthorizationRequired
|
||||
);
|
||||
return warningClass;
|
||||
},
|
||||
newLinkClick(e, navigate) {
|
||||
if (this.menuItem.newLinkRouteName) {
|
||||
navigate(e);
|
||||
|
|
|
@ -35,3 +35,10 @@ export const getInboxClassByType = (type, phoneNumber) => {
|
|||
return 'chat';
|
||||
}
|
||||
};
|
||||
|
||||
export const getInboxWarningIconClass = (type, reauthorizationRequired) => {
|
||||
if (type === INBOX_TYPES.FB && reauthorizationRequired) {
|
||||
return 'warning';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { getInboxClassByType } from '../inbox';
|
||||
import { getInboxClassByType, getInboxWarningIconClass } from '../inbox';
|
||||
|
||||
describe('#Inbox Helpers', () => {
|
||||
describe('getInboxClassByType', () => {
|
||||
|
@ -34,4 +34,12 @@ describe('#Inbox Helpers', () => {
|
|||
expect(getInboxClassByType('Channel::Email')).toEqual('mail');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getInboxWarningIconClass', () => {
|
||||
it('should return correct class for warning', () => {
|
||||
expect(getInboxWarningIconClass('Channel::FacebookPage', true)).toEqual(
|
||||
'warning'
|
||||
);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
|
@ -185,7 +185,8 @@
|
|||
"REPORTS_TEAM": "Team",
|
||||
"SET_AVAILABILITY_TITLE": "Set yourself as",
|
||||
"BETA": "Beta",
|
||||
"REPORTS_OVERVIEW": "Overview"
|
||||
"REPORTS_OVERVIEW": "Overview",
|
||||
"FACEBOOK_REAUTHORIZE": "Your Facebook connection has expired, please reconnect your Facebook page to continue services"
|
||||
},
|
||||
"CREATE_ACCOUNT": {
|
||||
"NO_ACCOUNT_WARNING": "Uh oh! We could not find any Chatwoot accounts. Please create a new account to continue.",
|
||||
|
|
|
@ -37,7 +37,7 @@ describe ::Messages::Facebook::MessageBuilder do
|
|||
allow(fb_object).to receive(:get_object).and_raise(Koala::Facebook::AuthenticationError.new(500, 'Error validating access token'))
|
||||
message_builder
|
||||
|
||||
expect(facebook_channel.authorization_error_count).to eq(1)
|
||||
expect(facebook_channel.authorization_error_count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,9 +22,11 @@ RSpec.describe Channel::FacebookPage do
|
|||
it 'calls channel notifier mail for facebook' do
|
||||
admin_mailer = double
|
||||
mailer_double = double
|
||||
|
||||
expect(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).and_return(admin_mailer)
|
||||
expect(admin_mailer).to receive(:facebook_disconnect).with(channel.inbox).and_return(mailer_double)
|
||||
expect(mailer_double).to receive(:deliver_later)
|
||||
|
||||
channel.prompt_reauthorization!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue