Set confluence home page specific to user groups

I am trying to write a customer specific plugin to set home pages for users depending on the groups they are in. My approach is that

1 - Get list of groups

2 - Get list of users in each group

3 - Set home page for each user of every group.

I have been successful step 1 and 2 but not able to acheieve thrid. This is what I am doing for it

UserAccessor userAccessor = (UserAccessor)ContainerManager.getInstance().getContainerContext().getComponent("userAccessor");

private UserSettingsServiceuserSettingsService = new ConfluenceUserSettingsService(userAccessor);

But I get an exection that no class defenition was found for ConfluenceUserSettingsService. Whereas the class is very much in the buildpath of the project and cimpiles fine

If Has anyone done anything such please let me know. Any approach is fine, be it a plugin or code change.

5 answers

Hi SimratPal,

If you want to get all groups and the users in each group, you can inject in your class the groupManager:

public YourClass(GroupManager groupManager){
		this.groupManager = groupManager; 
	}

Then, retrieve all groups

Pager<Group> groups = groupManager.getGroups();

And finally, get the members of each group

for(Group group: groups){				
Pager<String> membersOfGroup = groupManager.getMemberNames(group); }

Hope this helps,

Gorka

Thanks Gorkha, getting groups and its memebrs was never a problem, the issue how to set home page specific to each member. Which property of each user has to be set with home pahe url and how to do it?

Hi SimratPal,

I've not done it ever, but it seems that you need the method UserProfile.setHomepage(java.lang.String homepage);

https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/it/user/UserProfile.html

And the UserProfile maybe with ConfluenceUserManager

https://docs.atlassian.com/atlassian-confluence/5.4.4/com/atlassian/sal/confluence/user/ConfluenceUserManager.html

Give it a try!

Gorka

I am new to confluence development so found its constructor arguments too unfamiliar.
That looks like a very promising solution Girls. But any idea how do I get instance of ConfluenceUserManager
hat looks like a very promising solution Gorka. But any idea how do I get instance of ConfluenceUserManager

Hi,

I've seen that you can also use UserManager for doing so...

Pom.xml

&lt;dependency&gt;
            &lt;groupId&gt;com.atlassian.sal&lt;/groupId&gt;
            &lt;artifactId&gt;sal-api&lt;/artifactId&gt;
            &lt;version&gt;${sal.api.version}&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;

I'm using version 2.8.0

In your atlassian-plugin.xml

&lt;component-import key="userManager" interface="com.atlassian.sal.api.user.UserManager" /&gt;

And finally, inject the component in your java class

public YourClass(UserManager userManager){
	    this.userManager= userManager;	    
	}
void method(){
	   profile =  userManager.getUserProfile(username);
profile.setHomepage(homepage);
}

Gorka

Thanksa ton for all your help so far Gorka, but I am not able to use the <component-import> statement. I have some errors in my pom.xml and they very original problem of "no class def found" also seems be due the same issue that dependecies. I have 17 erros on my pom.xml and they say this:-

Plugin execution not covered by lifecycle configuration:com.atlassian.maven.plugins:maven-confluence-plugin:5.0.4:compress resources(execution:default-compress-resources, phase process-resources)

I did some research on it and someone was talking abt a file "lifecycle-mapping-metadata.xml". I wasnt able to find any such file at the specified place. Is it possible that my atlassian sdk is not properly installed.

Please advise if you can. And Apologies for too much bugging.

Could you upload both, pom.xml and atlassian-plugin.xml to see what's going on.

Regards,

Gorka

Gorka Puente Apologies for not eplying to you sooner, this site was down for maintenance. I dont see any provision to upload the files. Can you please send me a test mail on simratpal.singh@glintech.com. I shall email you the files. Any help is greatly appreciated as I am very close to my delivery.

Hi, Why don't you upload those files to a public repository (e.g., http://www.filesnack.com/ or any other) and post the links here? So anyone in the forum can have a look! Regards, Gorka

Gorka, I am able to get an object of UserManager after injecting it the way you advised above/ However userManager.getUserProfile(username); This gets me an object of Userprofile but it does not have any provision to get or set the home page. In fact it does not have any setter method. The UserProfile you pointed me in your response above seems to be from a different API. Do I need ot use some other api instead of sal-api?

Hi SimratPal, If you are using confluence 5.x+ , I dont think you need to put anything in the pom for UserManager. Simple inject it via the constructor and your IDE will take care of the imports.

public YourClass {
private UserManager userManager;
public YourClass(UserManager userManager){
        this.userManager= userManager;      
    }
//other methods ...
}

Try doing this before going into other complexities.

@Gorka Puente [Comalatech] please see my comment above.

@Gorka Puente [Comalatech] - I'm posting on Simrat's behalf as he is having technical difficulties.

Here's what he has to say:

I am able to get an object of UserManager after injecting it the way you advised above/ However userManager.getUserProfile(username); This gets me an object of Userprofile but it does not have any provision to get or set the home page. In fact it does not have any setter method. The UserProfile you pointed me in your response above seems to be from a different API. Do I need ot use some other api instead of sal-api?

There seems to be two UserProfile classes from different APIs

1- com.atlassian.sal.api.user.UserProfile
2 - com.atlassian.confluence.it.user.UserProfile

Number 2 has setHomePage option but i have no way to get object of this userprofile class

Gorka and Simrat also uploaded files for you to have a look atlassian-plugin.xml -> http://snk.to/f-cdxpy9px pom.xml-> http://snk.to/f-ctc3g83c

Hi, Sorry for that, my mistake. You are right, it's a different class. I've been looking for a setHomepage and I've only found it in the API for spaces. For users, It's not in the public API. Maybe someone from Atlassian can help. Gorka

Thanks Gorka, now getting back to the very original question, did you get a chance to look into my pom.xml. I am having build errors and getting No class def found for ConfluenceUserSettingsService. This class has a method "updateusersettings". I want to try that as well.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

377 views 20 10
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