I would like to create a conditional menu item as follows:
If the user has a personal space then use:
{compound-menuitem:view-my-personal-space|icon=user1_earth|caption=View/edit my _Personal Space}
where view-my-personal-space is an alias for location=system.user/user-preferences and key= personal-space.
However, if the user doesn't have a personal space and is a member of a particular group that I have set up to allow personal spaces, e.g. via {builder-show:group=members}, then I want a link that will send the user to the create personal space page:
{compound-menuitem:custom|link=http://wiki.mysite.com/spaces/createpersonalspace.action|icon=user1_earth|caption=Create Personal Space}
I would like help to (1) use builder-hide with the condition that the user already has a personal space and (2) use an alias or non-link language to point the user to the createpersonalspace.action page.
Many thanks for any help.
Tom
.png)








Comments (20)
Mar 24, 2009
Alain Moran says:
Unfortunatley that isnt currently possible, builder-show does not have an abilit...Unfortunatley that isnt currently possible, builder-show does not have an ability to switch on whether a user has a personal space or not, and there is no link type that can be used for creating a personal space (I suspect that the atlassian link has been coded in such a way as it will only function from the user profile)
Mar 24, 2009
Tom Wolff says:
I was afraid of that. The problem is that without a conditional, the link to the...I was afraid of that. The problem is that without a conditional, the link to the createpersonalspace.action seems to allow the user to create another personal space. While I expect that a user can't have more than one, he wouldn't find out until completing the page. I don't want to subject users to that hassle.
I guess I'll have to come up with some other workaround. Maybe I could put in the caption, "Do not use if you have a personal space." Or preferably something much briefer.
Could you help me with my point (2) on how to use an alias or non-link language to point the user to the createpersonalspace.action page. I'm afraid that isn't obvious either.
Thanks for your quick reply.
Apr 27, 2010
Ville Valtasaari says:
Any suggestion on how to check for the existence of a personal space using veloc...Any suggestion on how to check for the existence of a personal space using velocity in a user macro?
r. Ville
Apr 27, 2010
Steeve Cayla says:
One day I saw this thread on Confluence forum where you can call the pageManager...One day I saw this thread on Confluence forum where you can call the pageManager via a user macro. I don't think this would be very recommended but I did actually use it and everything seems to be working fine.
Instead of calling the pageManager, you can call the spaceManager the same way and then check for the existence of a personal space \$spaceManager.getPersonalSpace(User) for example.
Then display either the link to create a personal space or the space itself if the function returns a space.
hth
(the other way – prettiest way – would be to make a plugin)
Apr 27, 2010
Steeve Cayla says:
Hmm in fact $action.spaceManager will in most cases give you the same spaceManag...Hmm in fact $action.spaceManager will in most cases give you the same spaceManager as the one above.
Apr 28, 2010
Ville Valtasaari says:
Cheers, The thing is I'm not using the usual drop-down menus so I need to resto...Cheers,
The thing is I'm not using the usual drop-down menus so I need to restore the "Create personal space link" in my builder layout quickly. This'll do fine.
I'm not an expert on Velocity/Java programming yet (more copy, alter and pray), so can yu tell me what call you use to get the user? I'll be experimenting, but I'm asking in case I don't nail it quickly.
regards,
Ville
Apr 28, 2010
Steeve Cayla says:
Doc of spaceManager. There are 2 methods to get the personal space. One takes a ...Doc of spaceManager. There are 2 methods to get the personal space. One takes a string (the username), the other one takes an object (User). We'll take the first one.
This checks whether the current connected user has a personal space or not.
Apr 28, 2010
Ville Valtasaari says:
Excellent, I'll try this out right away... r. VilleExcellent,
I'll try this out right away...
r. Ville
Apr 28, 2010
Alain Moran says:
Have you thought of using aliases? 'User Menu Sections' -> 'Create Personal ...Have you thought of using aliases?
'User Menu Sections' -> 'Create Personal Space' is probably the one you are after (Assuming a recent release of confluence & builder - things have moved on in the 12 months since I wrote my initial comment)
Apr 28, 2010
Ville Valtasaari says:
Hi Alan, Steeve's script works, but I'd be willing to use an alias. we're using...Hi Alan,
Steeve's script works, but I'd be willing to use an alias. we're using Confluence 3.0.x and the latest 3.x Builder. Would an alias not appear or be replaced by the appropriate link if the personal space exists?
r. Ville
Apr 28, 2010
Alain Moran says:
That depends on how Atlassian defined the web-item ... your best bet is to try i...That depends on how Atlassian defined the web-item ... your best bet is to try it and see what happens
Apr 28, 2010
Ville Valtasaari says:
Ok, Looks like you have to use "Space Actions Sections > Browse Personal Spa...Ok,
Looks like you have to use "Space Actions Sections > Browse Personal Space Link" and it shows whether you have one or not, but takes you to the recently updated section if the space exists. That setting is off in the installation, so this is an Atlassian bug.
Looks like I better check before displaying the link after all.
Steeve, can you point me to a quick way to check whether the current user = current profile so I can hide the link from users looking at other users' profiles?
regards,
Ville
Apr 28, 2010
Steeve Cayla says:
Viewing a profile leads to this url : http://my-confluence/users/viewuserprofile...Viewing a profile leads to this url : http://my-confluence/users/viewuserprofile.action?username=myusername
As a first quick solution, You may be able to use the $req.getParameter("username") method and then compare usernames between the request and the connected user.
Apr 28, 2010
Alain Moran says:
Personally I would go with {builder-show:user=@creator|decorator=profile}Viewi...Personally I would go with
{builder-show:user=@creator|decorator=profile}Viewing my own profile{builder-show}
But hey, that's just me ... as I said, lots of stuff has changed since my original post
Apr 28, 2010
Ville Valtasaari says:
Right you are, Alan, I didn't know @creator would work for profile Thanks Ste...Right you are, Alan,
I didn't know @creator would work for profile
Thanks Steeve.
r. Ville
Apr 28, 2010
Steeve Cayla says:
What if the space wasn't created by me but by an administrator ? (by java code o...What if the space wasn't created by me but by an administrator ? (by java code or converting space to personal space). I didn't test it but I guess the creator would be the admin, and then @creator wouldn't work.
Apr 28, 2010
Alain Moran says:
Yes, if the site admin created your personal space it would probably show them a...Yes, if the site admin created your personal space it would probably show them as the creator, however if you are viewing a space then it wont be displayed anyway since the decorator will be 'space' not 'profile'.
Apr 28, 2010
Guy Fraser says:
There's also the userspace location: {compound-menuitem:userspace|caption=Vi...There's also the userspace location:
{compound-menuitem:userspace|caption=View/Edit my personal space}Apr 28, 2010
Ville Valtasaari says:
Hi Guy, Yes. I'm using that for the link if the space exists. The problem is ...Hi Guy,
Yes. I'm using that for the link if the space exists.
The problem is getting a link to create one if it doesn't exist. I'm not using the Atlassian dropdowns and I don't seem to be able to create a replacement. I made an alias to "Space Actions Sections > Browse Personal Space Link", there is no link if the space doesn't exist. Ditto for "User Hover Menu Sections > Personal Space".
r. Ville
Apr 28, 2010
Ville Valtasaari says:
Ok, I added an alias directly to Confluence URL for creating a space. That does...Ok,
I added an alias directly to Confluence URL for creating a space. That does it.
## the user cannot be anonymous #if (!$action.isAnonymousUser()) #set ($spaceManager = $action.spaceManager) #set ($userSpace = $spaceManager.getPersonalSpace($req.userPrincipal.name)) ##if the user has a personal space #if ($userSpace && $userSpace != "") {menulink:userspace|icon=user1_earth} Personal Space{menulink} #else {menulink:create-personalspace|icon=user1_earth} Create Personal Space{menulink} #end #endI'll use it with Alan's "builder-show" if I put it on the profile pages.
Thanks everyone,
Ville