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

Set confluence home page specific to user groups

SimratPal Singh September 2, 2014

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

2 votes
Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 3, 2014

Hi,

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

Pom.xml

<dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <version>${sal.api.version}</version>
            <scope>provided</scope>
        </dependency>

I'm using version 2.8.0

In your atlassian-plugin.xml

<component-import key="userManager" interface="com.atlassian.sal.api.user.UserManager" />

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

SimratPal Singh September 3, 2014

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.

Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 3, 2014

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

Regards,

Gorka

SimratPal Singh September 7, 2014

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.

Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 7, 2014

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

SimratPal Singh September 8, 2014

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?

2 votes
Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 2, 2014

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&lt;Group&gt; 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

SimratPal Singh September 3, 2014

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?

Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 3, 2014

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

SimratPal Singh September 3, 2014
I am new to confluence development so found its constructor arguments too unfamiliar.
SimratPal Singh September 3, 2014
That looks like a very promising solution Girls. But any idea how do I get instance of ConfluenceUserManager
SimratPal Singh September 3, 2014
hat looks like a very promising solution Gorka. But any idea how do I get instance of ConfluenceUserManager
1 vote
Yagnesh Bhat
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 3, 2014

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.

0 votes
Theophil Xavier September 8, 2014

@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

Theophil Xavier September 8, 2014

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

Gorka Puente _Appfire_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 8, 2014

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

SimratPal Singh September 9, 2014

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.

0 votes
SimratPal Singh September 7, 2014

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events