From 37a0676b0a6b2d4f94b1cc74276bfe54b5445030 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 6 Aug 2015 05:33:49 -0500 Subject: [PATCH] lock: Fix permanent error banner if locks are disabled Also, fix submission without a lock and locks are disabled --- include/ajax.tickets.php | 5 ++++- include/class.http.php | 1 + scp/js/ticket.js | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 8685edf57..cb988f8a5 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -103,7 +103,10 @@ class TicketsAjaxAPI extends AjaxController { function acquireLock($tid) { global $cfg, $thisstaff; - if(!$tid || !is_numeric($tid) || !$thisstaff || !$cfg || !$cfg->getLockTime()) + if(!$cfg || !$cfg->getLockTime()) + Http::response(418, $this->encode(array('id'=>0, 'retry'=>false))); + + if(!$tid || !is_numeric($tid) || !$thisstaff) return 0; if (!($ticket = Ticket::lookup($tid)) || !$ticket->checkStaffPerm($thisstaff)) diff --git a/include/class.http.php b/include/class.http.php index b2a9738e0..e17839d5b 100644 --- a/include/class.http.php +++ b/include/class.http.php @@ -27,6 +27,7 @@ class Http { case 404: return '404 Not Found'; case 405: return '405 Method Not Allowed'; case 416: return '416 Requested Range Not Satisfiable'; + case 418: return "418 I'm a teapot"; case 422: return '422 Unprocessable Entity'; default: return '500 Internal Server Error'; endswitch; diff --git a/scp/js/ticket.js b/scp/js/ticket.js index 897fafa8e..21ed2f415 100644 --- a/scp/js/ticket.js +++ b/scp/js/ticket.js @@ -22,7 +22,11 @@ this.objectId = this.$element.data('lockObjectId'); this.lockId = options.lockId || this.$element.data('lockId') || undefined; this.fails = 0; - this.setup(); + this.disabled = false; + getConfig().then(function(c) { + if (c.lock_time) + this.setup(); + }.bind(this)); } Lock.prototype = { @@ -49,7 +53,7 @@ return this.renew(); if (this.nextRenew && new Date().getTime() < this.nextRenew) return this.locked; - if (this.ajaxActive) + if (this.disabled || this.ajaxActive) return this.locked; this.ajaxActive = $.ajax({ @@ -69,7 +73,7 @@ return; if (this.nextRenew && new Date().getTime() < this.nextRenew) return this.locked; - if (this.ajaxActive) + if (this.disabled || this.ajaxActive) return this.locked; this.ajaxActive = $.ajax({ @@ -94,6 +98,11 @@ retry: function(func, xhr, textStatus, response) { var json = xhr ? xhr.responseJSON : response; + if (xhr.status == 418) { + this.disabled = true; + return this.destroy(); + } + if ((typeof json == 'object' && !json.retry) || !this.options.retry) return this.fail(json.msg); if (typeof json == 'object' && json.retry == 'acquire') { @@ -133,6 +142,8 @@ this.shutdown(); delete this.lockId; $(this.options.lockInput, this.$element).val(''); + if (this.locked) + this.locked.reject(); }, update: function(lock) { -- GitLab