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