Commit 23d619cf authored by Peter Walter's avatar Peter Walter
Browse files

change admin page code to scan all queues user has access to, then all users...

change admin page code to scan all queues user has access to, then all users in those queues. remove compatibility with extserv url as no longer in use
parent 8c193afe
// ==UserScript==
// @name RT Helpers
// @namespace https://rt.ebi.ac.uk/
// @namespace https://helpdesk.ebi.ac.uk/
// @description Add some shortcut links to RT
// @match https://*.ebi.ac.uk/*
// @include https://rt.ebi.ac.uk/extserv/*
// @include https://helpdesk.ebi.ac.uk/*
// @grant GM_xmlhttpRequest
// @version 2.3
// @version 2.4
// @updateURL https://gitlab.ebi.ac.uk/ebiwd/rthelper/raw/stable/rthelper.user.js
// @run-at document-end
// ==/UserScript==
var info = {};
info.version = '2.3';
if (document.location.pathname.indexOf('extserv') !== -1) {
info.path = '/extserv';
info.domain = 'https://rt.ebi.ac.uk';
info.ticket = '227';
info.nobody = '10';
} else {
info.path = '';
info.domain = 'https://helpdesk.ebi.ac.uk';
info.ticket = '38442';
info.nobody = '6';
}
info.version = '2.4';
info.domain = 'https://helpdesk.ebi.ac.uk';
info.path = '';
// get 'nobody' id from https://helpdesk.ebi.ac.uk/REST/1.0/user/nobody
info.nobody = '6';
/*jshint scripturl:true, strict:false, jquery:true */
......@@ -888,6 +880,8 @@ function init() {
return;
}
var owners = {}, statuses = {}, queues = {};
// remove page not found rubbish, replace title
removeElement(document.querySelector('#body h1').nextSibling);
removeElement(document.querySelector('#body h1'));
......@@ -903,51 +897,10 @@ function init() {
// put into dom temporarily
var temp = document.createElement('div');
temp.innerHTML = response.responseText;
setValue('name', temp.querySelector('div.RealName span.value').innerHTML);
removeElement(temp);
}
});
// get list of users
GM_xmlhttpRequest({
method: "GET",
url: info.path + '/Ticket/Modify.html?id=' + info.ticket,
onload: function(response) {
// put into dom temporarily
var temp = document.createElement('div');
temp.innerHTML = response.responseText;
var ownerOptions = temp.querySelectorAll('select[name="Owner"] option');
if (ownerOptions.length === 0) {
ownerOptions = [
{ 'value': info.nobody, 'text': 'Nobody in particular' },
{ 'value': getUserId(), 'text': getName(true) }
];
}
// provide static list for statusOptions, as order is inconsistent and data will not change
var statusOptions = [
{ 'value': 'new', 'text': 'New' },
{ 'value': 'open', 'text': 'Open' },
{ 'value': 'stalled', 'text': 'Stalled' },
{ 'value': 'rejected', 'text': 'Rejected' },
{ 'value': 'deleted', 'text': 'Deleted' },
{ 'value': 'resolved', 'text': 'Resolved' }
];
var queueOptions = temp.querySelectorAll('select[name="Queue"] option');
var owners = {}, statuses = {}, queues = {};
for (var ownerOption in ownerOptions) {
if (ownerOptions[ownerOption].value && ownerOptions[ownerOption].text) {
if (ownerOptions[ownerOption].text.indexOf('(') !== -1 && ownerOptions[ownerOption].text.indexOf(')') !== -1) {
owners[/\((.*)\)/gi.exec(ownerOptions[ownerOption].text)[1]] = ownerOptions[ownerOption].value;
}
else {
owners[ownerOptions[ownerOption].text] = ownerOptions[ownerOption].value;
}
}
}
for (var statusOption in statusOptions) {
if (statusOptions[statusOption].value && statusOptions[statusOption].text) {
statuses[statusOptions[statusOption].text] = statusOptions[statusOption].value;
}
}
for (var queueOption in queueOptions) {
if (queueOptions[queueOption].value && queueOptions[queueOption].text) {
queues[queueOptions[queueOption].text] = queueOptions[queueOption].value;
......@@ -955,126 +908,7 @@ function init() {
}
removeElement(temp);
// create option form
var form = document.createElement('form');
form.action = info.path + '/rthelper';
form.method = 'put';
document.getElementById('body').appendChild(form);
// store the form results
form.onsubmit = function() {
// var loginUsername = this.querySelector('input[name="username"]');
// setValue('loginUsername', loginUsername.value);
var loginPassword = this.querySelector('input[name="password"]');
setValue('loginPassword', loginPassword.value.encode());
var showOwners = this.querySelectorAll('input[name="showOwners"]');
var showOwnersString = '';
for (var showOwner in showOwners) {
if (showOwners[showOwner].checked) {
showOwnersString += showOwners[showOwner].value + ';';
}
}
setValue('showOwners', showOwnersString);
var showStatuses = this.querySelectorAll('input[name="showStatuses"]');
var showStatusesString = '';
for (var showStatus in showStatuses) {
if (showStatuses[showStatus].checked) {
showStatusesString += showStatuses[showStatus].value + ';';
}
}
setValue('showStatuses', showStatusesString);
var showQueues = this.querySelectorAll('input[name="showQueues"]');
var showQueuesString = '';
for (var showQueue in showQueues) {
if (showQueues[showQueue].checked) {
showQueuesString += showQueues[showQueue].value + ';';
}
}
setValue('showQueues', showQueuesString);
alert('Settings saved');
return false;
};
// populate the form
var loginFieldset = document.createElement('fieldset');
form.appendChild(loginFieldset);
var loginLegend = document.createElement('legend');
loginFieldset.appendChild(loginLegend);
loginLegend.innerHTML = 'Automatic login [OPTIONAL]';
var loginIntro = document.createElement('p');
loginFieldset.appendChild(loginIntro);
loginIntro.innerHTML = 'Enter your RT password to enable automatic login.';
setValue('loginUsername', getElementText('span.current-user'));
// var usernameDefault = getValue('loginUsername', '');
// var usernameInput = document.createElement('input');
// var usernameLabel = document.createElement('label');
// usernameInput.type = 'text';
// usernameInput.name = 'username';
// usernameInput.value = usernameDefault;
// usernameLabel.appendChild(document.createTextNode('Username: '));
// usernameLabel.appendChild(usernameInput);
// loginFieldset.appendChild(usernameLabel);
// loginFieldset.appendChild(document.createElement('br'));
var passwordDefault = getValue('loginPassword', '').decode();
var passwordInput = document.createElement('input');
var passwordLabel = document.createElement('label');
passwordInput.type = 'password';
passwordInput.name = 'password';
passwordInput.value = passwordDefault;
passwordLabel.appendChild(document.createTextNode('Password: '));
passwordLabel.appendChild(passwordInput);
loginFieldset.appendChild(passwordLabel);
loginFieldset.appendChild(document.createElement('br'));
var loginOuttro = document.createElement('p');
loginFieldset.appendChild(loginOuttro);
loginOuttro.innerHTML = 'NB: Your password will be encoded and stored in <a href="http://www.w3schools.com/html/html5_webstorage.asp">localstorage</a> on your computer. This username/password will only accessible within the ' + info.domain + ' domain.';
var ownerFieldset = document.createElement('fieldset');
form.appendChild(ownerFieldset);
var ownerLegend = document.createElement('legend');
ownerFieldset.appendChild(ownerLegend);
ownerLegend.innerHTML = 'Owner selection';
var ownerIntro = document.createElement('p');
ownerFieldset.appendChild(ownerIntro);
ownerIntro.innerHTML = 'Select the users you wish to switch between - typically the users in your team.';
var ownerDefault = getValue('showOwners', '');
for (var owner in owners) {
var ownerInput = document.createElement('input');
var ownerLabel = document.createElement('label');
ownerInput.type = 'checkbox';
ownerInput.name = 'showOwners';
ownerInput.value = owner + ':' + owners[owner];
if (ownerDefault.indexOf(ownerInput.value) !== -1) {
ownerInput.checked = true;
}
if (owner === 'Nobody in particular' || owner === getName(true)) {
ownerInput.disabled = true;
ownerInput.checked = true;
}
ownerLabel.appendChild(ownerInput);
ownerLabel.appendChild(document.createTextNode(owner));
ownerFieldset.appendChild(ownerLabel);
ownerFieldset.appendChild(document.createElement('br'));
}
var queueFieldset = document.createElement('fieldset');
form.appendChild(queueFieldset);
var queueLegend = document.createElement('legend');
queueFieldset.appendChild(queueLegend);
queueLegend.innerHTML = 'Queue selection';
var queueIntro = document.createElement('p');
queueFieldset.appendChild(queueIntro);
queueIntro.innerHTML = 'Select the queues you wish to switch between - typically the queues your team is responsible for.';
var queueDefault = getValue('showQueues', '');
// insert queue options in form
for (var queue in queues) {
var queueInput = document.createElement('input');
var queueLabel = document.createElement('label');
......@@ -1094,43 +928,206 @@ function init() {
queueFieldset.appendChild(document.createElement('br'));
}
var statusFieldset = document.createElement('fieldset');
form.appendChild(statusFieldset);
var statusLegend = document.createElement('legend');
statusFieldset.appendChild(statusLegend);
statusLegend.innerHTML = 'Status selection';
var statusIntro = document.createElement('p');
statusFieldset.appendChild(statusIntro);
statusIntro.innerHTML = 'Select the statuses you wish to switch between.';
var statusDefault = getValue('showStatuses', '');
for (var status in statuses) {
var statusInput = document.createElement('input');
var statusLabel = document.createElement('label');
statusInput.type = 'checkbox';
statusInput.name = 'showStatuses';
statusInput.value = status + ':' + statuses[status];
if (statusDefault.indexOf(statusInput.value) !== -1) {
statusInput.checked = true;
}
if (status === 'New' || status === 'Open' || status === 'Resolved') {
statusInput.disabled = true;
statusInput.checked = true;
}
statusLabel.appendChild(statusInput);
statusLabel.appendChild(document.createTextNode(status));
statusFieldset.appendChild(statusLabel);
statusFieldset.appendChild(document.createElement('br'));
}
// submit button
formSubmit = document.createElement('input');
form.appendChild(formSubmit);
formSubmit.type = 'submit';
// get list of users, iterate over each queue
for (var queue in queues) {
GM_xmlhttpRequest({
method: "GET",
url: info.path + '/Ticket/Create.html?Queue=' + queues[queue],
headers: {
'Referer': info.domain + info.path
},
onload: function(response) {
// put into dom temporarily
var temp = document.createElement('div');
temp.innerHTML = response.responseText;
var ownerOptions = temp.querySelectorAll('select[name="Owner"] option');
for (var ownerOption in ownerOptions) {
if (ownerOptions[ownerOption].value && ownerOptions[ownerOption].text) {
if (ownerOptions[ownerOption].text.indexOf('(') !== -1 && ownerOptions[ownerOption].text.indexOf(')') !== -1) {
owners[/\((.*)\)/gi.exec(ownerOptions[ownerOption].text)[1]] = ownerOptions[ownerOption].value;
}
else {
owners[ownerOptions[ownerOption].text] = ownerOptions[ownerOption].value;
}
}
}
removeElement(temp);
// insert user options in form
for (var owner in owners) {
var ownerInput = document.createElement('input');
var ownerLabel = document.createElement('label');
ownerInput.type = 'checkbox';
ownerInput.name = 'showOwners';
ownerInput.value = owner + ':' + owners[owner];
if (ownerDefault.indexOf(ownerInput.value) !== -1) {
ownerInput.checked = true;
}
if (owner === 'Nobody in particular' || owner === getName(true)) {
ownerInput.disabled = true;
ownerInput.checked = true;
}
if (document.querySelectorAll('input[value="' + owner + ':' + owners[owner] + '"]').length < 1) {
ownerLabel.appendChild(ownerInput);
ownerLabel.appendChild(document.createTextNode(owner));
ownerFieldset.appendChild(ownerLabel);
ownerFieldset.appendChild(document.createElement('br'));
}
}
}
});
}
}
});
})();
// provide static list for statusOptions, as order is inconsistent and data will not change
var statusOptions = [
{ 'value': 'new', 'text': 'New' },
{ 'value': 'open', 'text': 'Open' },
{ 'value': 'stalled', 'text': 'Stalled' },
{ 'value': 'rejected', 'text': 'Rejected' },
{ 'value': 'deleted', 'text': 'Deleted' },
{ 'value': 'resolved', 'text': 'Resolved' }
];
for (var statusOption in statusOptions) {
if (statusOptions[statusOption].value && statusOptions[statusOption].text) {
statuses[statusOptions[statusOption].text] = statusOptions[statusOption].value;
}
}
// create option form
var form = document.createElement('form');
form.action = info.path + '/rthelper';
form.method = 'put';
document.getElementById('body').appendChild(form);
// store the form results
form.onsubmit = function() {
var loginPassword = this.querySelector('input[name="password"]');
setValue('loginPassword', loginPassword.value.encode());
var showOwners = this.querySelectorAll('input[name="showOwners"]');
var showOwnersString = '';
for (var showOwner in showOwners) {
if (showOwners[showOwner].checked) {
showOwnersString += showOwners[showOwner].value + ';';
}
}
setValue('showOwners', showOwnersString);
var showStatuses = this.querySelectorAll('input[name="showStatuses"]');
var showStatusesString = '';
for (var showStatus in showStatuses) {
if (showStatuses[showStatus].checked) {
showStatusesString += showStatuses[showStatus].value + ';';
}
}
setValue('showStatuses', showStatusesString);
var showQueues = this.querySelectorAll('input[name="showQueues"]');
var showQueuesString = '';
for (var showQueue in showQueues) {
if (showQueues[showQueue].checked) {
showQueuesString += showQueues[showQueue].value + ';';
}
}
setValue('showQueues', showQueuesString);
alert('Settings saved');
return false;
};
// populate the form
var loginFieldset = document.createElement('fieldset');
form.appendChild(loginFieldset);
var loginLegend = document.createElement('legend');
loginFieldset.appendChild(loginLegend);
loginLegend.innerHTML = 'Automatic login [OPTIONAL]';
var loginIntro = document.createElement('p');
loginFieldset.appendChild(loginIntro);
loginIntro.innerHTML = 'Enter your RT password to enable automatic login.';
setValue('loginUsername', getElementText('span.current-user'));
var passwordDefault = getValue('loginPassword', '').decode();
var passwordInput = document.createElement('input');
var passwordLabel = document.createElement('label');
passwordInput.type = 'password';
passwordInput.name = 'password';
passwordInput.value = passwordDefault;
passwordLabel.appendChild(document.createTextNode('Password: '));
passwordLabel.appendChild(passwordInput);
loginFieldset.appendChild(passwordLabel);
loginFieldset.appendChild(document.createElement('br'));
var loginOuttro = document.createElement('p');
loginFieldset.appendChild(loginOuttro);
loginOuttro.innerHTML = 'NB: Your password will be encoded and stored in <a href="http://www.w3schools.com/html/html5_webstorage.asp">localstorage</a> on your computer. This username/password will only accessible within the ' + info.domain + ' domain.';
var statusFieldset = document.createElement('fieldset');
form.appendChild(statusFieldset);
var statusLegend = document.createElement('legend');
statusFieldset.appendChild(statusLegend);
statusLegend.innerHTML = 'Status selection';
var statusIntro = document.createElement('p');
statusFieldset.appendChild(statusIntro);
statusIntro.innerHTML = 'Select the statuses you wish to switch between.';
var statusDefault = getValue('showStatuses', '');
var queueFieldset = document.createElement('fieldset');
form.appendChild(queueFieldset);
var queueLegend = document.createElement('legend');
queueFieldset.appendChild(queueLegend);
queueLegend.innerHTML = 'Queue selection';
var queueIntro = document.createElement('p');
queueFieldset.appendChild(queueIntro);
queueIntro.innerHTML = 'Select the queues you wish to switch between - typically the queues your team is responsible for.';
var queueDefault = getValue('showQueues', '');
var ownerFieldset = document.createElement('fieldset');
form.appendChild(ownerFieldset);
var ownerLegend = document.createElement('legend');
ownerFieldset.appendChild(ownerLegend);
ownerLegend.innerHTML = 'Owner selection';
var ownerIntro = document.createElement('p');
ownerFieldset.appendChild(ownerIntro);
ownerIntro.innerHTML = 'Select the users you wish to switch between - typically the users in your team.';
var ownerDefault = getValue('showOwners', '');
for (var status in statuses) {
var statusInput = document.createElement('input');
var statusLabel = document.createElement('label');
statusInput.type = 'checkbox';
statusInput.name = 'showStatuses';
statusInput.value = status + ':' + statuses[status];
if (statusDefault.indexOf(statusInput.value) !== -1) {
statusInput.checked = true;
}
if (status === 'New' || status === 'Open' || status === 'Resolved') {
statusInput.disabled = true;
statusInput.checked = true;
}
statusLabel.appendChild(statusInput);
statusLabel.appendChild(document.createTextNode(status));
statusFieldset.appendChild(statusLabel);
statusFieldset.appendChild(document.createElement('br'));
}
// submit button
formSubmit = document.createElement('input');
form.appendChild(formSubmit);
formSubmit.type = 'submit';
})();
}
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment