Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get groups for current login user via Rest (javascript) in Confluence ?

Mik December 20, 2012

Hi Guys

How I can get groups for current login user via Rest (javascript) in Confluence ?

Thanks

Mik

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Ramesh Udari1 September 11, 2013

Hi Mizan,

Is above script works in createissue-start.jsp file ?

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2013

IF the script is stored in the announcement banner it will run on every page in JIRA

I am not sure if it works on the create issue pop up but there are ways you can make it work on the create issue screen .

refer this post , people have encountered this issue and there are a few workarounds/solution available for this on Answers forum .

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2012

It should be /rest/prototype/1/session, but the groups information is not in there.

Perhaps you can get it from the SOAP API, if confluence has the json/soap bridge.

It was enough for me to check whether the user was a confluence admin, which I did via (bit hacky):

if (AJS.$("#administration-link").length > 0) {...

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2012

I have a Javascript taken from JTRICKS tutorials , its for JIRA maybe you can modify it according to Confluence REST APi and make it work .

<script type="text/javascript">

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;
}

var user = getCurrentUserName();
if (isUserInGroup(user, 'jira-administrators')){
AJS.$(function(){
alert("i am an administrator"))

});

}
</script>

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events