Is it possible to get the groups the currently logged in user belongs to in Atlasian Confluence using Javasrcipt stored in the "Custom HTML"?
I can get the currently logged in user as follows but cant find an example for getting the user's groups:
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;
}
(EDIT:)
All I really need to do is:
Im really considering just writing a html "shell" page that handles user management and showing Confluence in an iFrame.
That, or maybe just store the usernames I want to match in a javascript array or JSON object there in the `custom HTML` and just match the user name that I can already get directly, foregoing groups all together.
Neither are ideal but wouldnt require the learning curve of throwing in Java for such a small need. Any issues I might run into with those ideas?
Community moderators have prevented the ability to post new answers.
Your easiest bet would be to use a simple user macro, something similar to as follows:
## @param group:title=Group|type=string|desc=Enter group name #if ($userAccessor.hasMembership($paramgroup, $req.getRemoteUser())) <script> ## Your jQuery here </script> #end
Replace "## Your jQuery here" with the required javascript, save it under a particular name (like "bindlinks"), and make sure that it is set to "Visible only to system administrators in the Macro Browser".
If you're using the documentation theme, then embedding it in every page is easy. Just go to the admin section, themes, configure theme, and add the following line in the header section: {bindlinks:group=groupname}, where groupname is the name of the group that you want.
If you're using the default theme, then you need to go to Layouts, find "Page Layout", and click on "Create Custom". At the end of the text put the following line and save:
$action.getHelper().renderConfluenceMacro("{bindlinks:group=groupname}")
I think that's the easiest way to solve your problem. If you have any other questions, let me know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using the json-rpc API you can get this.
http://wiki/rpc/json-rpc/confluenceservice-v2/getUserGroups
Pass it ["username"].
AJS.$.ajax({ dataType: 'json', contentType: 'application/json', type: 'POST', url: 'http://wiki/rpc/json-rpc/confluenceservice-v2/getUserGroups', data: '["' + {username} + '"]', async: false, success: function(data){ for(var group in data) { } } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does this work for your needs?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, this works but only if the crrent user is a Confluence Admin. If I run this while logged in as a non-admin, I get the below error returned:
The application was unable to serve your request: com.atlassian.confluence.rpc.NotPermittedException: You don't have the 'Confluence Administrator' permission.
Any way to make this work as a non-admin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On the confluence admin under general configuration do you have "Remote API" checked?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did not, so I checked it. Same result though, same error if not logged in as an admin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You will have access to the userAccessor in your velocity file where you might be entering your javascript. Take a look at the objects accessible in velocity.
https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity
Then using $userAccessor.getGroupNamesForUsername method, you can get groups.
https://docs.atlassian.com/com/atlassian/confluence/atlassian-confluence/latest/index.html?com/atlassian/confluence/user/UserAccessor.html
If you are working on a custom plugin that requires javascript manipulation before serving content, you might find this tutorial helpful.
http://blog.jiradev.com/2014/07/web-resource-transformer-plugin-module.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi thank you for your time,
Yeah, I was afraid of that. I know nothing about Velocity / Java. I was hoping to be able to do this without having to write a plugin, just by using Javascript loaded in the `Custom HTML`( so it loads in the head of every page on the site). You can get the username easily this way, it's a shame you cant also get the user's groups.
Are there any easy to follow tutorials for writing a simple plugin? I read through the one you posted and it looks like just what I would need. But now I m looking for something to spell out the basic plugin writing/installing process for me.
All I really need to do is:
Im really considering just writing a html "shell" page that handles user management and showing Confluence in an iFrame.
That, or maybe just store the usernames I want to match in a javascript array or JSON object there in the `custom HTML` and just match the user name that I can already get directly, foregoing groups all together.
Neither are ideal but wouldnt require the learning curve of throwing in Java for such a small need.
(editing my question to include that)
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.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.