Forum Discussion

Claudius's avatar
13 years ago

Getting details for user viewed on profile page

Now here's a tough one:

I'm currently working on a custom component extending the View User Profile page with links to a few internal tools. (This component of course will only be visible to certain user ranks). Now the challenge is that I need to get hold of the SSO id of the user profile I am currently viewing. The "user" context object obviously only holds the information of the user currently logged in and browsing other user's profiles.

 

Do I really need to somehow pull the SSO id from the XHTML structure of the document?

I see the problem that a "vieweduser" context object only makes sense on this very "View User Profile" page, alas it would allow some nice custom components for this very page, e.g. more visual stats based on viewed user's data etc.

  • Unfortunately not :( That takes me back to the 303 error.

    But reading a bit further into the UserReference class in the REST API JavaDoc I think this should be the way to go

    <#assign viewed_sso_id = restadmin("/users/id/${page.context.user.id}/ref/sso_id").value />

    At least http://community.lithium.com/my-community/restapi/vc/users/id/8/ref/sso_id in the browser shows a more friendlier 303 error then:

    UserRef[id=-1] does not have access to RequiredPermissions[(allow_manage_users)] on CommunityByDisplayIdRef

    But executed as restadmin Freemarker call in my custom component then shows yet another discouraging 303:

    The object 'User ....' inherently does not support the action 'sso.action'

    Guess I need to work on some other component first to get the head free again :(

     

  • I did some further digging for some alternate methods using REST API. According to the REST API Javadocs it should be possible to pull the SSO ID like this:

    http://community.lithium.com/community-name/restapi/vc/users/id/8/profiles/name/sso_id

    Yet I only get a 303 (Can't find this error code documented anywhere. The closest I got was "See other", but the output of the User object did not really help) REST API error that way:

    <response status="error">
    <error code="303">
    <message>
    User [id=-1, loginRef=, emailRef=, registrationTime=0, deletedRef=false, rankingId=-1, lastVisitTime=1330618775254, isLegacy=false, isPartiallyRegistered=false, registrationCompletedTime=0, isAnonymous=true, roleInfoRef=UserRoleInfo[roles=[]], ranking=Ranking [rankId=-1, sortOrder=100, rankName=N/A, rankBold=false, rankColor=, rankIcon=, rankIconRight=, rankIconThread=, grantRoles=, removeRoles=, kudosWeight=-1, registrationAge=0, metricPosts=0, metricPageViews=0, metricLogins=0, metricMinutesOnline=0, metricTags=0, averageMessageRating=0, equalsUserId=-1, equalsRole=, equalsRoleKey=null, rankingFormula=, rankingFormulaEnabled=false, coreNode=CoreNode(class lithium.boards.core.Community)[SQLCoreNodeinfo: owner=-1 metricsId=2 hidden=false hiddenAncestor=false deleted=false nodeId=1 parentNodeId=-1 type=Community displayId='skypec' path=NodePath:/, depth:1], rankTextMsg=LocalizedMessageDescriptor[messageLocator=FallbackSequenceMessageLocator[textKeyIterable=[TextKey[rank.-1.title]]],messageArgs={}]]] cannot get field 'profile.null' on object User [id=8, loginRef=Claudius, emailRef=claudius@anonymous.net, registrationTime=1308763959637, deletedRef=false, rankingId=2, lastVisitTime=1330618488158, isLegacy=true, isPartiallyRegistered=false, registrationCompletedTime=0, isAnonymous=false, roleInfoRef=UserRoleInfo[roles=[RoleKey[nodeId=1,roleIdentifier=RoleIdentifier[Administrator]), RoleKey[nodeId=284,roleIdentifier=RoleIdentifier[BlogAuthor]), RoleKey[nodeId=284,roleIdentifier=RoleIdentifier[BlogModerator])]], ranking=Ranking [rankId=2, sortOrder=1, rankName=Community Manager, rankBold=true, rankColor=FF0000, rankIcon=/html/rank_icons/icon_role_skype_small.gif, rankIconRight=/html/rank_icons/icon_role_new_admin.gif, rankIconThread=, grantRoles=, removeRoles=, kudosWeight=-1, registrationAge=0, metricPosts=0, metricPageViews=0, metricLogins=0, metricMinutesOnline=0, metricTags=0, averageMessageRating=0, equalsUserId=-1, equalsRole=Administrator, equalsRoleKey=RoleKey[nodeId=1,roleIdentifier=RoleIdentifier[Administrator]), rankingFormula=, rankingFormulaEnabled=false, coreNode=CoreNode(class lithium.boards.core.Community)[SQLCoreNodeinfo: owner=-1 metricsId=2 hidden=false hiddenAncestor=false deleted=false nodeId=1 parentNodeId=-1 type=Community displayId='my-community-name' path=NodePath:/, depth:1], rankTextMsg=LocalizedMessageDescriptor[messageLocator=FallbackSequenceMessageLocator[textKeyIterable=[TextKey[rank.2.title]]],messageArgs={}]]]
    </message>
    </error>
    </response>

     I am still open to take suggestions on both routes.

    • AdamN's avatar
      AdamN
      Khoros Oracle

      The error you're seeing means that you aren't properly authenticated to make that particular REST API call. SSO ID is a protected resource, so you'll need to be authenticated as an administrator to see the SSO ID for other users. You definitely have the right idea though...

       

      If your component is on the profile page, you can use the page context object to determine the user whose profile page you're showing. Here's an example of how to get the id for that user:

      ${page.context.user.id}

      Once you have the user id, you can use that in your REST API call to get the SSO ID for the user. Keep in mind that you'll likely need to use restadmin() instead of rest() to make your call for the reason I mentioned previously.

      • Hi Adam,

        thanks for digging into this. I still couldn't make it work though, e.g. the returned SSO Id is empty. Here's the full component code I tried:

        <#if user.registered >
        	<#assign rank = restadmin("/users/id/${user.id?c}/ranking").ranking />
        	<#if rank.name?? && ((rank.name == "Staff Moderator") || (rank.name == "Community Manager")) >
        		<#assign viewed_sso_id = restadmin("/users/id/${page.context.user.id}/profiles/name/sso_id").value />
        		SSO ID: ${viewed_sso_id}
        		<a href="https://secrettool.company.com?user_id=${viewed_sso_id}">User in Backoffice</a>
        	</#if>
        </#if>	

         Any idea?