Skip to content

Commit

Permalink
Adds a new setting to prevent Livechat agents from activating service…
Browse files Browse the repository at this point in the history
… status when office hours are closed. (RocketChat#14921)
  • Loading branch information
renatobecker committed Jul 4, 2019
1 parent 3661c63 commit da42a95
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 17 deletions.
1 change: 0 additions & 1 deletion app/livechat/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import '../lib/LivechatExternalMessage';
import './roomType';
import './route';
import './ui';
import './methods/changeLivechatStatus';
import './startup/notifyUnreadRooms';
import './views/app/analytics/livechatAnalytics';
import './views/app/analytics/livechatAnalyticsCustomDaterange';
Expand Down
15 changes: 0 additions & 15 deletions app/livechat/client/methods/changeLivechatStatus.js

This file was deleted.

8 changes: 8 additions & 0 deletions app/livechat/client/views/app/livechatOfficeHours.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
<label for="displayOfflineFormFalse">{{_ "False"}}</label>
</fieldset>

<fieldset>
<legend>{{_ "Allow_Online_Agents_Outside_Office_Hours"}}</legend>
<input type="radio" class="preview-settings" name="allowAgentsOnlineOutOfficeHours" id="allowAgentsOnlineOutOfficeHoursTrue" checked="{{allowAgentsOnlineOutOfficeHoursTrueChecked}}" value="true">
<label for="displayOfflineFormTrue">{{_ "True"}}</label>
<input type="radio" class="preview-settings" name="allowAgentsOnlineOutOfficeHours" id="allowAgentsOnlineOutOfficeHoursFalse" checked="{{allowAgentsOnlineOutOfficeHoursFalseChecked}}" value="false">
<label for="displayOfflineFormFalse">{{_ "False"}}</label>
</fieldset>

<!-- days open -->
<fieldset>
<legend>{{_ "Open_days_of_the_week"}}</legend>
Expand Down
14 changes: 14 additions & 0 deletions app/livechat/client/views/app/livechatOfficeHours.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ Template.livechatOfficeHours.helpers({
return 'checked';
}
},
allowAgentsOnlineOutOfficeHoursTrueChecked() {
if (Template.instance().allowAgentsOnlineOutOfficeHours.get()) {
return 'checked';
}
},
allowAgentsOnlineOutOfficeHoursFalseChecked() {
if (!Template.instance().allowAgentsOnlineOutOfficeHours.get()) {
return 'checked';
}
},
});

Template.livechatOfficeHours.events({
Expand Down Expand Up @@ -97,6 +107,8 @@ Template.livechatOfficeHours.events({
}
}

settings.set('Livechat_allow_online_agents_outside_office_hours', instance.allowAgentsOnlineOutOfficeHours.get());

settings.set('Livechat_enable_office_hours', instance.enableOfficeHours.get(), (err/* , success*/) => {
if (err) {
return handleError(err);
Expand Down Expand Up @@ -158,8 +170,10 @@ Template.livechatOfficeHours.onCreated(function() {
});

this.enableOfficeHours = new ReactiveVar(null);
this.allowAgentsOnlineOutOfficeHours = new ReactiveVar(null);

this.autorun(() => {
this.enableOfficeHours.set(settings.get('Livechat_enable_office_hours'));
this.allowAgentsOnlineOutOfficeHours.set(settings.get('Livechat_allow_online_agents_outside_office_hours'));
});
});
8 changes: 8 additions & 0 deletions app/livechat/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ Meteor.startup(function() {
i18nLabel: 'Office_hours_enabled',
});

settings.add('Livechat_allow_online_agents_outside_office_hours', true, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Allow_Online_Agents_Outside_Office_Hours',
enableQuery: { _id: 'Livechat_enable_office_hours', value: true },
});

settings.add('Livechat_continuous_sound_notification_new_livechat_room', false, {
type: 'boolean',
group: 'Livechat',
Expand Down
29 changes: 28 additions & 1 deletion app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ import { QueueMethods } from './QueueMethods';
import { Analytics } from './Analytics';
import { settings } from '../../../settings';
import { callbacks } from '../../../callbacks';
import { Users, Rooms, Messages, Subscriptions, Settings, LivechatDepartmentAgents, LivechatDepartment, LivechatCustomField, LivechatVisitors } from '../../../models';
import {
Users,
Rooms,
Messages,
Subscriptions,
Settings,
LivechatDepartmentAgents,
LivechatDepartment,
LivechatCustomField,
LivechatVisitors,
LivechatOfficeHour,
} from '../../../models';
import { Logger } from '../../../logger';
import { sendMessage, deleteMessage, updateMessage } from '../../../lib';
import { addUserRoles, removeUserFromRoles } from '../../../authorization';
Expand Down Expand Up @@ -928,6 +939,22 @@ export const Livechat = {
});
});
},

allowAgentChangeServiceStatus(statusLivechat) {
if (!settings.get('Livechat_enable_office_hours')) {
return true;
}

if (settings.get('Livechat_allow_online_agents_outside_office_hours')) {
return true;
}

if (statusLivechat !== 'available') {
return true;
}

return LivechatOfficeHour.isNowWithinHours();
},
};

Livechat.stream = new Meteor.Streamer('livechat-room');
Expand Down
4 changes: 4 additions & 0 deletions app/livechat/server/methods/changeLivechatStatus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';

import { Users } from '../../../models';
import { Livechat } from '../lib/Livechat';

Meteor.methods({
'livechat:changeLivechatStatus'() {
Expand All @@ -11,6 +12,9 @@ Meteor.methods({
const user = Meteor.user();

const newStatus = user.statusLivechat === 'available' ? 'not-available' : 'available';
if (!Livechat.allowAgentChangeServiceStatus(newStatus)) {
throw new Meteor.Error('error-office-hours-are-closed', 'Not allowed', { method: 'livechat:changeLivechatStatus' });
}

return Users.setLivechatStatus(user._id, newStatus);
},
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"Allow_Invalid_SelfSigned_Certs_Description": "Allow invalid and self-signed SSL certificate's for link validation and previews.",
"Allow_switching_departments": "Allow Visitor to Switch Departments",
"Allow_Marketing_Emails": "Allow Marketing Emails",
"Allow_Online_Agents_Outside_Office_Hours" : "Allow online agents outside of office hours",
"Almost_done": "Almost done",
"Alphabetical": "Alphabetical",
"Always_open_in_new_window": "Always Open in New Window",
Expand Down Expand Up @@ -1266,6 +1267,7 @@
"error-no-tokens-for-this-user": "There are no tokens for this user",
"error-not-allowed": "Not allowed",
"error-not-authorized": "Not authorized",
"error-office-hours-are-closed": "The office hours are closed.",
"error-password-policy-not-met": "Password does not meet the server's policy",
"error-password-policy-not-met-maxLength": "Password does not meet the server's policy of maximum length (password too long)",
"error-password-policy-not-met-minLength": "Password does not meet the server's policy of minimum length (password too short)",
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Allow_Invalid_SelfSigned_Certs_Description": "Permitir certificado SSL inválidos e auto-assinados para validação de link e previews.",
"Allow_switching_departments": "Permitir que Visitantes Mudem de Departamento",
"Allow_Marketing_Emails": "Permitir emails de marketing",
"Allow_Online_Agents_Outside_Office_Hours" : "Permitir agentes online fora do horário de escritório",
"Almost_done": "Quase pronto",
"Alphabetical": "Alfabética",
"Always_open_in_new_window": "Sempra Abrir em Janela Nova",
Expand Down Expand Up @@ -1227,6 +1228,7 @@
"error-no-tokens-for-this-user": "Não existem tokens para este usuário",
"error-not-allowed": "Não permitido",
"error-not-authorized": "Não autorizado",
"error-office-hours-are-closed": "O horário de escritório esta fechado.",
"error-password-policy-not-met": "A senha não atende a política do servidor",
"error-password-policy-not-met-maxLength": "A senha não está de acordo com a política de comprimento máximo do servidor (senha muito longa)",
"error-password-policy-not-met-minLength": "A senha não está de acordo com a política de comprimento mínimo do servidor (senha muito curta)",
Expand Down

0 comments on commit da42a95

Please sign in to comment.