Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ee/app/canned-responses/server/methods/saveCannedResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ Meteor.methods({
if (!canSaveAll && !canSaveDepartment && ['department'].includes(responseData.scope)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed to modify canned responses on *department* scope', { method: 'saveCannedResponse' });
}

// to avoid inconsistencies
if (responseData.scope === 'user') {
delete responseData.departmentId;
}
// TODO: check if the department i'm trying to save is a department i can interact with

// check if the response already exists and we're not updating one
const duplicateShortcut = CannedResponse.findOneByShortcut(responseData.shortcut, { fields: { _id: 1 } });
if ((!_id && duplicateShortcut) || (_id && duplicateShortcut._id !== _id)) {
if ((!_id && duplicateShortcut) || (_id && duplicateShortcut && duplicateShortcut._id !== _id)) {
throw new Meteor.Error('error-invalid-shortcut', 'Shortcut provided already exists', { method: 'saveCannedResponse' });
}

Expand All @@ -55,7 +60,6 @@ Meteor.methods({
throw new Meteor.Error('error-canned-response-not-found', 'Canned Response not found', { method: 'saveCannedResponse' });
}

responseData.scope = cannedResponse.scope;
responseData.createdBy = cannedResponse.createdBy;
} else {
const user = Users.findOneById(Meteor.userId());
Expand Down
5 changes: 4 additions & 1 deletion ee/client/omnichannel/cannedResponses/CannedResponseEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ const CannedResponseEdit: FC<{
...(tags.length > 0 && { tags }),
...(departmentId && { departmentId: departmentId.value }),
});
dispatchToastMessage({ type: 'success', message: t('Canned_Response_Created') });
dispatchToastMessage({
type: 'success',
message: t(_id ? 'Canned_Response_Updated' : 'Canned_Response_Created'),
});
Route.push({
context: '',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ const WrapCreateCannedResponseModal: FC<{ data?: any; reloadCannedList?: any }>
...(tags.length > 0 && { tags }),
...(departmentId && { departmentId: departmentId.value }),
});
dispatchToastMessage({ type: 'success', message: t('Canned_Response_Created') });
dispatchToastMessage({
type: 'success',
message: t(_id ? 'Canned_Response_Updated' : 'Canned_Response_Created'),
});
closeModal(null);
reloadCannedList && reloadCannedList();
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@
"Cancel_message_input": "Cancel",
"Canceled": "Canceled",
"Canned Responses": "Canned Responses",
"Canned_Response_Created": "Canned Response Created",
"Canned_Response_Created": "Canned Response created",
"Canned_Response_Updated": "Canned Response updated",
"Canned_Response_Delete_Warning": "Deleting a canned response cannot be undone.",
"Canned_Response_Removed": "Canned Response Removed",
"Canned_Response_Sharing_Department_Description": "Anyone in the selected department can access this canned response",
Expand Down