Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] [ENTERPRISE] Allows to set a group of departments accepted for forwarding chats #17335

Merged
merged 9 commits into from
Apr 21, 2020
57 changes: 27 additions & 30 deletions app/livechat/client/views/app/tabbar/visitorForward.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,34 @@ <h3>{{_ "Forward_chat"}}</h3>
</div>
{{/with}}
<form>
{{#if showDefaultDepartmentForm}}
<div class="input-line">
<label for="name">{{_ "Forward_to_department"}}</label>
<div class="form-group">
{{> livechatAutocompleteUser
onClickTag=onClickTagDepartment
list=selectedDepartments
onSelect=onSelectDepartments
collection='CachedDepartmentList'
endpoint='livechat/department.autocomplete'
field='name'
sort='name'
icon="queue"
label="Enter_a_department_name"
placeholder="Enter_a_department_name"
name="department"
noMatchTemplate="userSearchEmpty"
templateItem="popupList_item_channel"
template="roomSearch"
noMatchTemplate="roomSearchEmpty"
modifier=departmentModifier
conditions=departmentConditions
}}
</div>
</div>
<div class="form-divisor">
<span>{{_ "or"}}</span>
<div class="input-line">
<label for="name">{{_ "Forward_to_department"}}</label>
<div class="form-group">
{{> livechatAutocompleteUser
onClickTag=onClickTagDepartment
list=selectedDepartments
onSelect=onSelectDepartments
collection='CachedDepartmentList'
endpoint='livechat/department.autocomplete'
field='name'
sort='name'
icon="queue"
label="Enter_a_department_name"
placeholder="Enter_a_department_name"
name="department"
noMatchTemplate="userSearchEmpty"
templateItem="popupList_item_channel"
template="roomSearch"
noMatchTemplate="roomSearchEmpty"
modifier=departmentModifier
conditions=departmentConditions
}}
</div>
{{else}}
{{> Template.dynamic template=customFieldsTemplate data=data }}
{{/if}}
</div>
<div class="form-divisor">
<span>{{_ "or"}}</span>
</div>

<div class="input-line">
<label for="agent">{{_ "Forward_to_user"}}</label>
<div class="form-group">
Expand Down
27 changes: 10 additions & 17 deletions app/livechat/client/views/app/tabbar/visitorForward.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ChatRoom } from '../../../../../models';
import { t } from '../../../../../utils';
import './visitorForward.html';
import { APIClient } from '../../../../../utils/client';
import { getCustomFormTemplate } from '../customTemplates/register';

Template.visitorForward.helpers({
visitor() {
Expand Down Expand Up @@ -54,16 +53,9 @@ Template.visitorForward.helpers({
return Template.instance().onSelectDepartments;
},
departmentConditions() {
return { enabled: true, numAgents: { $gt: 0 } };
},
customFieldsTemplate() {
return getCustomFormTemplate('visitorForward');
},
showDefaultDepartmentForm() {
return !getCustomFormTemplate('visitorForward') && Template.instance().departments.get().filter((department) => department.enabled === true).length > 0;
},
data() {
return Template.instance().room;
const departmentForwardRestrictions = Template.instance().departmentForwardRestrictions.get();
console.log(departmentForwardRestrictions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this console here =D

return { enabled: true, numAgents: { $gt: 0 }, ...departmentForwardRestrictions };
},
});

Expand All @@ -73,6 +65,7 @@ Template.visitorForward.onCreated(async function() {
this.departments = new ReactiveVar([]);
this.selectedAgents = new ReactiveVar([]);
this.selectedDepartments = new ReactiveVar([]);
this.departmentForwardRestrictions = new ReactiveVar();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.departmentForwardRestrictions = new ReactiveVar();
this.departmentForwardRestrictions = new ReactiveVar({});


this.onSelectDepartments = ({ item: department }) => {
department.text = department.name;
Expand All @@ -99,6 +92,12 @@ Template.visitorForward.onCreated(async function() {

this.autorun(() => {
this.room.set(ChatRoom.findOne({ _id: Template.currentData().roomId }));
const { departmentId } = this.room.get();
if (departmentId) {
Meteor.call('livechat:getDepartmentForwardRestrictions', departmentId, (err, result) => {
this.departmentForwardRestrictions.set(result);
});
}
});

const { departments } = await APIClient.v1.get('livechat/department');
Expand All @@ -123,12 +122,6 @@ Template.visitorForward.events({
transferData.departmentId = department && department._id;
}

instance.$('.customFormField').each((i, el) => {
const elField = instance.$(el);
const name = elField.attr('name');
transferData[name] = elField.val();
});

if (!transferData.userId && !transferData.departmentId) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions app/livechat/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import './methods/saveOfficeHours';
import './methods/sendTranscript';
import './methods/getFirstRoomMessage';
import './methods/getTagsList';
import './methods/getDepartmentForwardRestrictions';
import './lib/Analytics';
import './lib/QueueManager';
import './lib/OfficeClock';
Expand Down
13 changes: 13 additions & 0 deletions app/livechat/server/methods/getDepartmentForwardRestrictions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Meteor } from 'meteor/meteor';

import { callbacks } from '../../../callbacks';

Meteor.methods({
'livechat:getDepartmentForwardRestrictions'(departmentId) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:getTagsList' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:getTagsList' });
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'livechat:getDepartmentForwardRestrictions' });

}

return callbacks.run('livechat.onLoadForwardDepartmentRestrictions', departmentId);
},
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { addCustomFormTemplate } from '../../../../../../app/livechat/client/vie
import './customTemplates/livechatDepartmentCustomFieldsForm';
import './customTemplates/livechatAgentEditCustomFieldsForm';
import './customTemplates/livechatAgentInfoCustomFieldsForm';
import './customTemplates/visitorForwardCustomFieldsForm';

addCustomFormTemplate('livechatDepartmentForm', 'livechatDepartmentCustomFieldsForm');
addCustomFormTemplate('livechatAgentEditForm', 'livechatAgentEditCustomFieldsForm');
addCustomFormTemplate('livechatAgentInfoForm', 'livechatAgentInfoCustomFieldsForm');
addCustomFormTemplate('visitorForward', 'visitorForwardCustomFieldsForm');
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { callbacks } from '../../../../../app/callbacks';
import { LivechatDepartment } from '../../../../../app/models/server';

callbacks.add('livechat.onLoadForwardDepartmentRestrictions', (departmentId) => {
if (!departmentId) {
return {};
}
const department = LivechatDepartment.findOneById(departmentId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const department = LivechatDepartment.findOneById(departmentId);
const department = LivechatDepartment.findOneById(departmentId, { fields: { departmentsAllowedToForward: 1 } });

if (!department) {
return {};
}
const { departmentsAllowedToForward } = department;
if (!departmentsAllowedToForward) {
return {};
}
return { _id: { $in: departmentsAllowedToForward } };
}, callbacks.priority.MEDIUM, 'livechat-on-load-forward-department-restrictions');
1 change: 1 addition & 0 deletions ee/app/livechat-enterprise/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './hooks/beforeListTags';
import './hooks/setPredictedVisitorAbandonmentTime';
import './hooks/beforeForwardRoomToDepartment';
import './hooks/afterRemoveDepartment';
import './hooks/onLoadForwardDepartmentRestrictions';
import './methods/addMonitor';
import './methods/getUnitsFromUserRoles';
import './methods/removeMonitor';
Expand Down