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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

102 views 0 2
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