The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script to hide the delete folder option for Xray test repository

akshay_kg
Contributor
February 8, 2021

We are using the xray test repository for managing the manual test in our company, the problem with that is there is onle one role that addressed who can create or delete the repo/ folder tree. This is causing the huge chaos as users are mistakenly deleting the root folder rather than the one child they don't need. Can anyone help me with the script to hide the UI 'delete' option  ? I'm fairly new to script runner it does not seems very easy to do so. 

Any help is very much appreciated.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
akshay_kg
Contributor
August 25, 2022
<script type="text/javascript">
var user = getCurrentUserName();
hideDeleteOption(user)


function getCurrentUserName()
{
var user;
AJS.$.ajax({
type: 'get',
dataType: 'json',
url: "<<Url>>/rest/auth/latest/session",
async: false,
success: function(data) {
user = data.name;
}
});

return user;

}

function getGroups(user)
{
var groups;
AJS.$.ajax({
url: "<<Url>>/rest/api/2/user?username="+user+"&expand=groups",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
groups = data.groups.items;
}
});
return groups;
}

function hideDeleteOption(user){
var groups = getGroups(user);
for (i = 0; i < groups.length; i++){
var group = groups[i].name
var index1 = group.lastIndexOf('_')
var index2 = group.indexOf('_')
var role = group.substring(index1+1)
var project = group.substring(index2+1,index1)

if(role == 'user' || role == 'scrum' || role == 'readonly' || role == 'stakeholder'){


if(window.location.href.indexOf("entityKey="+project) > -1){
setTimeout(() => {

$("#raven-folder-delete").css("pointer-events", "none");
},4000);

}


}
}
}


</script>

Adding above script on announcement banner it'll hide delete button depending on project role. 

0 votes
Daniel Soares
Contributor
February 11, 2022

I strongly recomend this KB https://docs.getxray.app/display/ON/Configuring+Permissions 

Review need to restrict editing at Test Repository 

but it do not remove the delete folder option just retrict to create and edit too.