Forum Discussion

StanGromer's avatar
7 years ago

Possible to lock a TKB down to only closed group membership?

Hey all,

 

I'm far from a dev but been pretending to be one while we are hiring ours, so mostly surviving off the advice/hints I can find on here.  Question if anyone knows if this is possible and/or could help me out with how I could use freemarker to maybe accomplish this?

 

Ultimately we want to have a closed group, but also have a TKB that only the same closed group members should have access for.  As I understand it, group membership roles only exist at the node level though, so doing anything unique/interesting such as assigning a badge/role when they join said group, and thus granting permission that way doesn't seem possible.  Is it possible in any way to still be able to lock down the TKB so only those members who belong to XYZ closed group can access TKB ZYX, maybe using freemarker?

 

Structure of this category:

- Category (public)

   - TKB (Public)

   - Group (Closed)

   - TKB (That I want to be closed to above group)

 

I was able to use the following code I found on here to do something similar for user roles, but after looking through the API doc, I haven't found a good way to accomplish this for a specific closed group (but again, not a developer, but enough to get by... until now!).  Tremendously appreciate any advice.

 

<#attempt>
                <#assign user_has_role = false />
                <#if user.registered >
                                <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
                                <#if role.name?? && (role.name == "Partner" || role.name == "Employee" || role.name == "Administrator")>
                                                                <#assign user_has_role = true />
                                                </#if>
                                </#list>
                </#if>
                <#if user_has_role >
<@component id="accesstest_yes" />
<#else>
<@component id="accesstest_no" />
      </#if>
<#recover>          
                <!-- Something bad happened -->
</#attempt> 

 

  • StanGromer

    Yes, it can be done using custom code snippet.  

    Here are two options

    a) You can also check if a user joined to that group or not. 

    <#if Not_Joined >

    Content goes here to make TKB close. i.e. you can set redirection here and put it in page initialization script. 

    </#if>

    b) Whenever a user joins the group, you just need to trigger the ADD role API.  After that, you just need to put the condition same in your mentioned code.