Hi,
I made this Web Resource plugin that consist in hide issue type 'Query' to group of users 'client-users'.
First, I test to hide issue type 'Query' to all group of users and works fine, but when I was to hide to 'clients-users' group it doesn't works...
I use Jira 5.2.11 and I don't have context to jira, if I test REST API ("/rest/auth/1/session/") works and show information.
Any suggestion about my error on my code?
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { hideIssueType(); }); hideIssueType(); function hideIssueType(){ hide(); $("#project-field").change(function(){ hide(); }); } function hide(){ AJS.$.get("/rest/auth/1/session", function (data) { userName = data.name; // check groups AJS.$.get("/rest/api/2/user", {username: userName, expand: "groups"}, function (data) { var groups = data.groups; var groupItems = jQuery.map(groups.items, function (val, j) {return val.name}); if (jQuery.inArray("client-users", groups.items)) { //check issue type $("#issuetype option").each(function() { if($.trim($(this).text()) == 'Query'){ $(this).remove(); } }); } }); }); } });
Thanks in advance,
Daniel
Community moderators have prevented the ability to post new answers.
I'm not familiar with JavaScript but the code may give clue
jQuery(document).ready( function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { hideIssueType(); }); hideIssueType(); function hideIssueType(){ var user=getCurrentUserName(); if(isUserInGroup(user,'Developers')){ //add code here to hide issuetype } } function getCurrentUserName() { var user; AJS.$.ajax({ url: "/rest/gadget/1.0/currentUser", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.username; } }); return user; } function getGroups(user) { var groups; AJS.$.ajax({ 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 isUserInGroup(user, group){ var groups = getGroups(user); for (i = 0; i < groups.length; i++){ if (groups[i].name == group){ return true; } } return false; } });
taken Prasad's answer from https://answers.atlassian.com/questions/211230/how-to-hide-issue-type-to-few-user-groups-in-jira5
I do these changes and finally these is my code:
jQuery(document).ready( function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { hideIssueType(); }); hideIssueType(); function hideIssueType(){ var user=getCurrentUserName(); if(isUserInGroup(user,'client-users')){ //code for hide issuetype hide(); $("#project-field").change(function(){ hide(); }); } } function hide(){ $("#issuetype option").each(function() { if($.trim($(this).text()) == 'Query'){ $(this).remove(); } }); } //code to get current username logged in jira system function getCurrentUserName() { var user; AJS.$.ajax({ url: "/rest/gadget/1.0/currentUser", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.username; } }); return user; } //code for get groups of username parameter function getGroups(user) { var groups; AJS.$.ajax({ url: "/rest/api/2/user?username="+user+"&expand=groups", type: 'get', dataType: 'json', async: false, success: function(data) { groups = data.groups.items; } }); return groups; } //code for check that username is in group function isUserInGroup(user, group){ var groups = getGroups(user); for (i = 0; i < groups.length; i++){ if (groups[i].name == group){ return true; } } return false; } });
But it doesn't works... I don't know why because I do GET request for REST '/rest/api/2/user?username=support&expand=groups' and I get group 'client-users' but it still appears issue type 'Query' in create issue screen ! I don't know why I'm doing wrong...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It was (I think) a cache problem... I test in Chrome (I was using Firefox) and works fine!.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.