Regression: Allow users to update canned responses scope (#22738)

* Allow users to update canned responses scope

* Correct message when update/create responses

Co-authored-by: Martin Schoeler <martin.schoeler@rocket.chat>
pull/22741/head^2
Kevin Aleman 4 years ago committed by GitHub
parent 9ee7ed1847
commit 1f59b0c3c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      ee/app/canned-responses/server/methods/saveCannedResponse.js
  2. 5
      ee/client/omnichannel/cannedResponses/CannedResponseEdit.tsx
  3. 5
      ee/client/omnichannel/components/CannedResponse/modals/CreateCannedResponse/index.tsx
  4. 3
      packages/rocketchat-i18n/i18n/en.i18n.json

@ -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' });
}
@ -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());

@ -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: '',
});

@ -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) {

@ -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",

Loading…
Cancel
Save