diff --git a/include/ajax.users.php b/include/ajax.users.php index c7259983f4b0a698da99c0e81023c34043ddbbd1..c835ba9807ef28053838620c53dc3834deb33bf8 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -217,11 +217,9 @@ class UsersAjaxAPI extends AjaxController { $info = array(); if ($_POST) { if ($user->tickets->count()) { - if (!$thisstaff->hasPerm(TicketModel::PERM_DELETE)) { - $info['error'] = __('You do not have permission to delete a user with tickets!'); - } elseif ($_POST['deletetickets']) { - foreach($user->tickets as $ticket) - $ticket->delete(); + if ($_POST['deletetickets']) { + if (!$user->deleteAllTickets()) + $info['error'] = __('You do not have permission to delete a user with tickets!'); } else { $info['error'] = __('You cannot delete a user with tickets!'); } diff --git a/include/class.orm.php b/include/class.orm.php index 57029871265b38038f32d5726038a724d39d3de0..39ad7728b7f8030226c1e97379f9b59a45acc419 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -1409,7 +1409,7 @@ class InstrumentedList extends ModelInstanceManager { // QuerySet delegates function count() { - return $this->queryset->count(); + return $this->objects()->count(); } function exists() { return $this->queryset->exists(); diff --git a/include/class.user.php b/include/class.user.php index 1b4e309d8af92aae4aef4e277ae23df2c0ffb894..9ab9009f32981e86fdf7e69ccf0c38094810b652 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -662,6 +662,18 @@ implements TemplateVariable { return parent::delete(); } + function deleteAllTickets() { + $deleted = TicketStatus::lookup(array('state' => 'deleted')); + foreach($this->tickets as $ticket) { + if (!$T = Ticket::lookup($ticket->getId())) + continue; + if (!$T->setStatus($deleted)) + return false; + } + $this->tickets->reset(); + return true; + } + static function lookupByEmail($email) { return static::lookup(array('emails__address'=>$email)); } diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index 7e4993ad459d2e9bc63f57060fc11f0714c4ec15..5dd3f64f9a7e42a5dd3aaba5dd70b05f7b6295d6 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -261,14 +261,20 @@ $(function() { ids.push($(this).val()); }); if (ids.length) { - var submit = function() { + var submit = function(data) { $form.find('#action').val(action); $.each(ids, function() { $form.append($('<input type="hidden" name="ids[]">').val(this)); }); + if (data) + $.each(data, function() { $form.append($('<input type="hidden">').attr('name', this.name).val(this.value)); }); $form.find('#selected-count').val(ids.length); $form.submit(); }; + var options = {}; + if (action === 'delete') + options['deletetickets'] + = __('Also delete all associated tickets and attachments'); if (!confirmed) - $.confirm(__('You sure?')).then(submit); + $.confirm(__('You sure?'), undefined, options).then(submit); else submit(); } diff --git a/scp/js/scp.js b/scp/js/scp.js index 1a3e35becf58a540e8eb6a6590bb8e92694210cd..6853a93d7e287179b0b3b87896d8f53a5e0fdeec 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -699,8 +699,9 @@ $.sysAlert = function (title, msg, cb) { } }; -$.confirm = function(message, title) { +$.confirm = function(message, title, options) { title = title || __('Please Confirm'); + options = options || {}; var D = $.Deferred(), $popup = $('.dialog#popup'), hide = function() { @@ -708,7 +709,7 @@ $.confirm = function(message, title) { $popup.hide(); }; $('div#popup-loading', $popup).hide(); - $('div.body', $popup).empty() + var body = $('div.body', $popup).empty() .append($('<h3></h3>').text(title)) .append($('<a class="close" href="#"><i class="icon-remove-circle"></i></a>')) .append($('<hr/>')) @@ -716,7 +717,20 @@ $.confirm = function(message, title) { .text(message) ).append($('<div></div>') .append($('<b>').text(__('Please confirm to continue.'))) - ).append($('<hr style="margin-top:1em"/>')) + ); + + if (Object.keys(options).length) + body.append('<hr>'); + $.each(options, function(k, v) { + body.append($('<div>') + .html(' '+v) + .prepend($('<input type="checkbox">') + .attr('name', k) + ) + ); + }); + + body.append($('<hr style="margin-top:1em"/>')) .append($('<p class="full-width"></p>') .append($('<span class="buttons pull-left"></span>') .append($('<input type="button" class="close"/>') @@ -725,7 +739,7 @@ $.confirm = function(message, title) { )).append($('<span class="buttons pull-right"></span>') .append($('<input type="button"/>') .attr('value', __('OK')) - .click(function() { hide(); D.resolve(); }) + .click(function() { hide(); D.resolve(body.find('input').serializeArray()); }) ))).append($('<div class="clear"></div>')); $.toggleOverlay(true); $popup.resize().show(); diff --git a/scp/users.php b/scp/users.php index 20956ae8b21381b093f8d9aeb51849fa5ece351b..4506941a08a777cbd8e6961045159197e0db99ec 100644 --- a/scp/users.php +++ b/scp/users.php @@ -93,9 +93,15 @@ if ($_POST) { break; case 'delete': - foreach ($users as $U) + foreach ($users as $U) { + if (@$_POST['deletetickets']) { + if (!$U->deleteAllTickets()) + // XXX: This message is very unclear + $errors['err'] = __('You do not have permission to delete a user with tickets!'); + } if ($U->delete()) $count++; + } break; case 'reset':