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
|
end
|
||||||
ensure_contact_avatar
|
ensure_contact_avatar
|
||||||
rescue Koala::Facebook::AuthenticationError
|
rescue Koala::Facebook::AuthenticationError
|
||||||
Rails.logger.error "Facebook Authorization expired for Inbox #{@inbox.id}"
|
@inbox.channel.authorization_error!
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
||||||
true
|
true
|
||||||
|
|
|
@ -95,6 +95,7 @@ export default {
|
||||||
),
|
),
|
||||||
type: inbox.channel_type,
|
type: inbox.channel_type,
|
||||||
phoneNumber: inbox.phone_number,
|
phoneNumber: inbox.phone_number,
|
||||||
|
reauthorizationRequired: inbox.reauthorization_required,
|
||||||
}))
|
}))
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1
|
a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1
|
||||||
|
|
|
@ -30,6 +30,14 @@
|
||||||
<span v-if="count" class="badge" :class="{ secondary: !isActive }">
|
<span v-if="count" class="badge" :class="{ secondary: !isActive }">
|
||||||
{{ count }}
|
{{ count }}
|
||||||
</span>
|
</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>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</router-link>
|
</router-link>
|
||||||
|
@ -57,6 +65,10 @@ export default {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
warningIcon: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
count: {
|
count: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
:label-color="child.color"
|
:label-color="child.color"
|
||||||
:should-truncate="child.truncateLabel"
|
:should-truncate="child.truncateLabel"
|
||||||
:icon="computedInboxClass(child)"
|
:icon="computedInboxClass(child)"
|
||||||
|
:warning-icon="computedInboxErrorClass(child)"
|
||||||
/>
|
/>
|
||||||
<router-link
|
<router-link
|
||||||
v-if="showItem(menuItem)"
|
v-if="showItem(menuItem)"
|
||||||
|
@ -63,7 +64,10 @@
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
|
|
||||||
import adminMixin from '../../../mixins/isAdmin';
|
import adminMixin from '../../../mixins/isAdmin';
|
||||||
import { getInboxClassByType } from 'dashboard/helper/inbox';
|
import {
|
||||||
|
getInboxClassByType,
|
||||||
|
getInboxWarningIconClass,
|
||||||
|
} from 'dashboard/helper/inbox';
|
||||||
|
|
||||||
import SecondaryChildNavItem from './SecondaryChildNavItem';
|
import SecondaryChildNavItem from './SecondaryChildNavItem';
|
||||||
|
|
||||||
|
@ -136,6 +140,15 @@ export default {
|
||||||
const classByType = getInboxClassByType(type, phoneNumber);
|
const classByType = getInboxClassByType(type, phoneNumber);
|
||||||
return classByType;
|
return classByType;
|
||||||
},
|
},
|
||||||
|
computedInboxErrorClass(child) {
|
||||||
|
const { type, reauthorizationRequired } = child;
|
||||||
|
if (!type) return '';
|
||||||
|
const warningClass = getInboxWarningIconClass(
|
||||||
|
type,
|
||||||
|
reauthorizationRequired
|
||||||
|
);
|
||||||
|
return warningClass;
|
||||||
|
},
|
||||||
newLinkClick(e, navigate) {
|
newLinkClick(e, navigate) {
|
||||||
if (this.menuItem.newLinkRouteName) {
|
if (this.menuItem.newLinkRouteName) {
|
||||||
navigate(e);
|
navigate(e);
|
||||||
|
|
|
@ -35,3 +35,10 @@ export const getInboxClassByType = (type, phoneNumber) => {
|
||||||
return 'chat';
|
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('#Inbox Helpers', () => {
|
||||||
describe('getInboxClassByType', () => {
|
describe('getInboxClassByType', () => {
|
||||||
|
@ -34,4 +34,12 @@ describe('#Inbox Helpers', () => {
|
||||||
expect(getInboxClassByType('Channel::Email')).toEqual('mail');
|
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",
|
"REPORTS_TEAM": "Team",
|
||||||
"SET_AVAILABILITY_TITLE": "Set yourself as",
|
"SET_AVAILABILITY_TITLE": "Set yourself as",
|
||||||
"BETA": "Beta",
|
"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": {
|
"CREATE_ACCOUNT": {
|
||||||
"NO_ACCOUNT_WARNING": "Uh oh! We could not find any Chatwoot accounts. Please create a new account to continue.",
|
"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'))
|
allow(fb_object).to receive(:get_object).and_raise(Koala::Facebook::AuthenticationError.new(500, 'Error validating access token'))
|
||||||
message_builder
|
message_builder
|
||||||
|
|
||||||
expect(facebook_channel.authorization_error_count).to eq(1)
|
expect(facebook_channel.authorization_error_count).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,9 +22,11 @@ RSpec.describe Channel::FacebookPage do
|
||||||
it 'calls channel notifier mail for facebook' do
|
it 'calls channel notifier mail for facebook' do
|
||||||
admin_mailer = double
|
admin_mailer = double
|
||||||
mailer_double = double
|
mailer_double = double
|
||||||
|
|
||||||
expect(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).and_return(admin_mailer)
|
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(admin_mailer).to receive(:facebook_disconnect).with(channel.inbox).and_return(mailer_double)
|
||||||
expect(mailer_double).to receive(:deliver_later)
|
expect(mailer_double).to receive(:deliver_later)
|
||||||
|
|
||||||
channel.prompt_reauthorization!
|
channel.prompt_reauthorization!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue