Skip to content

Commit

Permalink
fix(accounts): check if agent is assignee before deleting agent. #408
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jun 1, 2021
1 parent fefb8de commit 81fd6ea
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/controllers/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,16 @@ apiUsers.deleteUser = function (req, res) {
})
},
function (hasTickets, hasConversations, user, cb) {
if (hasTickets || hasConversations) {
var ticketSchema = require('../../../models/ticket')
ticketSchema.find({ assignee: user._id }, function (err, tickets) {
if (err) return cb(err)

var isAssignee = _.size(tickets) > 0
return cb(null, hasTickets, hasConversations, isAssignee, user)
})
},
function (hasTickets, hasConversations, isAssignee, user, cb) {
if (hasTickets || hasConversations || isAssignee) {
// Disable if the user has tickets or conversations
user.softDelete(function (err) {
if (err) return cb(err)
Expand Down

0 comments on commit 81fd6ea

Please sign in to comment.