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
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

169 views 1 3
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