Forum Discussion

dhiraj_gophane's avatar
12 years ago

Rest API to get the groups available to current user

Hi all,

How can I get list of groups that are accessible to current logged in user.

Is there any direct API which will give us the groups which user can access.

 

The list should contain:

 

1) all open groups

2) all groups to which a user is already connected.

 

 

Hoping to see the solution asap.

  • AdamN's avatar
    AdamN
    12 years ago

    If you're not seeing any groups, I'd suggest double checking your default permissions for groups to ensure that users have access to see and join groups. You might also want to check to make sure that there isn't any code in your custom component that would be wrapping the REST call and preventing it from occuring (i.e. some other permission/role check you may have added).

     

    One way to do a quick check to see if it's a permission issue vs something with your component would be to create a separate test component and add this snippet:

    <#list rest("/groups/list").groups.group as group>
    ${group.id},
    </#list>

    You could even add it to an announcements section temporarily if you didn't want to create a separate component. If you login as a regular user and view the page this code is on, you should see a list of Group IDs. If you don't, it's likely a permission issue. If you do see it, there's likely an issue with your custom component.

8 Replies

  • Hi Adam,
    Currently I am using this API only.
    It gives me groups in context with the current node.
    I want list of groups in context with the current logged in user.
  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    If you're making the REST API call as the user you're interested in, it should respect the permissions and settings you've configured for each group and only show the user the groups that the user has access to. Is it not behaving as you'd expect?

     

    Perhaps I'm misunderstanding what you're interested in. Would it be possible for you to give an example of what you're trying to accomplish, and the shortcomings of the method I suggested?

  • <#assign groups = restadmin('/groups/list?restapi.response_style=view').groups />

    I tried this but its giving me all the groups in the community.
    The groups to which a particular user should not have access.
    shall i try using rest();
    but that won't give any response to those users who do not have permission to do the rest call.
  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    Ah, yes. I would change that to "rest" instead of "restadmin". The "restadmin" context object executes the call as the user with administrator privileges, so they will always get every group back. They don't need the REST API read/write permissions for the "rest" context object to be used. Those two permissions are primarily for external calls to the REST API.

     

    I would strongly suggest using "restadmin" only where absolutely necessary, in cases where you need to make an exception and allow an API call that would not normally be permitted (i.e. checking roles). You should especially be careful with it when obtaining lists of nodes (boards, blogs, ideas, groups, etc.) since it will always give you the full list, including nodes that the user would not normally have access to.

     

     

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    If you're not seeing any groups, I'd suggest double checking your default permissions for groups to ensure that users have access to see and join groups. You might also want to check to make sure that there isn't any code in your custom component that would be wrapping the REST call and preventing it from occuring (i.e. some other permission/role check you may have added).

     

    One way to do a quick check to see if it's a permission issue vs something with your component would be to create a separate test component and add this snippet:

    <#list rest("/groups/list").groups.group as group>
    ${group.id},
    </#list>

    You could even add it to an announcements section temporarily if you didn't want to create a separate component. If you login as a regular user and view the page this code is on, you should see a list of Group IDs. If you don't, it's likely a permission issue. If you do see it, there's likely an issue with your custom component.

  • Thank you Adam,
    The issue is resolved.
    I really appreciate your help.
    You solution worked for me.