Skip to end of metadata
Go to start of metadata

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

  • No labels

20 Comments

  1. 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)

    1. Unknown User (tewolff)

      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.

  2. Unknown User (ville.valtasaari@thl.fi)

    Any suggestion on how to check for the existence of a personal space using velocity in a user macro?

    r. Ville

    1. Unknown User (scayla)

      One day I saw this thread (http://forums.atlassian.com/thread.jspa?messageID=257301614ᱮ) 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)

      1. Unknown User (scayla)

        Hmm in fact $action.spaceManager will in most cases give you the same spaceManager as the one above.

      2. Unknown User (ville.valtasaari@thl.fi)

        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

        1. Unknown User (scayla)

          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.

          #if (!$action.isAnonymousUser())## the user cannot be anonymous
          #set ($spaceManager = $action.spaceManager)
          #set ($userSpace = $spaceManager.getPersonalSpace($req.userPrincipal.name))
          #if ($userSpace && $userSpace != "") ##if the user has a personal space
          display personal space for example
          #else
          do something else like create space
          #end
          #end
          
          1. Unknown User (ville.valtasaari@thl.fi)

            Excellent,

            I'll try this out right away...

            r. Ville

  3. 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)

    1. Unknown User (ville.valtasaari@thl.fi)

      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

      1. That depends on how Atlassian defined the web-item ... your best bet is to try it and see what happens (wink)

        1. Unknown User (ville.valtasaari@thl.fi)

          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

          1. Unknown User (scayla)

            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.

            1. 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 (wink)

              1. Unknown User (ville.valtasaari@thl.fi)

                Right you are, Alan,

                I didn't know @creator would work for profile (wink)

                Thanks Steeve.

                r. Ville

                1. Unknown User (scayla)

                  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.

                  1. 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'.

  4. Unknown User (gfraser)

    There's also the userspace location:

    {compound-menuitem:userspace|caption=View/Edit my personal space}
    
    1. Unknown User (ville.valtasaari@thl.fi)

      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

  5. Unknown User (ville.valtasaari@thl.fi)

    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
    #end
    

    I'll use it with Alan's "builder-show" if I put it on the profile pages.

    Thanks everyone,
    Ville