Show/Hide Queues based on user group Edited

I try to hide queues using script fragments in jira service desk, but I have a problem with continuous refresh jira service desk queues list page because I can hide some queue but as the page refreshes continuously, the script's function goes into an infinite loop. I want to know if someone know alternative solution to hide queues based on user permission.

Now, my script is :

(function ($) {
var elementFound = false;
var userName = JIRA.Users.LoggedInUser.userName();
var queuesId = [];
//Call endpoint to get queues to hide
$.ajax({
url: AJS.contextPath() + "/rest/scriptrunner/latest/custom/getQueuesToHide?username=" +
userName,
type: "GET",
beforeSend: function (request) {
request.setRequestHeader("X-Atlassian-token", "no-check");
}
}).fail(function (XMLHttpRequest, textStatus, errorThrown) {
console.log("failed... look at server logs for why");
}).done(function (data) {
if(data) {
queuesId = data;
}
});
$(document).bind("DOMSubtreeModified", function(evt) {
if (elementFound)
return;
//Waiting changes in Left Grid of Queue List
if ($("#pinnednav-opts-sd-queues-nav").length > 0) {
console.log("Entramos en QUEUE grid");
var queueListObserver = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (!mutation.addedNodes) return;
var element;
for (var i in queuesId) {
element = AJS.$("[data-item-id='" + queuesId[i] + "']");
element.remove();
}

})
});

elementFound = true;

var targetQueueList;

if ($("#pinnednav-opts-sd-queues-nav").length > 0)
targetQueueList = document.getElementById("pinnednav-opts-sd-queues-nav");

queueListObserver.observe(targetQueueList, {
childList: true
, subtree: true
, attributes: false
, characterData: false
});
}
//Waiting changes in table of queue issues list
if ($("#issuetable").length > 0 ) {

var tableObserver = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (!mutation.addedNodes) {
return;
}
var element;
for (var i in queuesId) {
element = AJS.$("[data-item-id='" + queuesId[i] + "']");
element.remove();
}
})
});

var tableTarget;

if ($("#issuetable").length > 0)
tableTarget = document.getElementById("issuetable");

tableObserver.observe(tableTarget, {
childList: true
, subtree: true
, attributes: false
, characterData: false
});
}
});

})(AJS.$);

Thank's!

Ricard

 

0 answers

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

243 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you