Forum Discussion

tyw's avatar
tyw
Boss
10 years ago

Help understanding Freemarker permissions

Hi! 

 

I was wondering if someone can point me in the right direction as I'm a little confused when it comes to Freemarker.

 

In my community we have a value that a user specifies during registration. Depending on permissions, this value will be displayed next to their name whenever they post. Only thing is, I can't sort out how this 'permission' is allowed? 

 

Pasted below is a snip from the custom componet for this feature, can someone help me better understand how the value in bold gets determined? In other words, how can I ensure a role has the allowed permission? I cant seem to figure out just how I can modify who is allowed to do this, and who isnt. Thanks! 

 

<#assign carrier_allowed = rest("/messages/id/${env.context.message.uniqueId?c}/author/profiles/name/carrier/allowed").value />

  <#if carrier_allowed == "true">

  <#assign carrier = rest("/messages/id/${env.context.message.uniqueId?c}/author/profiles/name/carrier").value />

  • Hey tyw , The rest call breaks down like this:

    /messages/id/${env.context.message.uniqueId?c}/author/profiles/name/carrier/allowed").value

     

    /messages <= look at messages

    /id <= look at a specific message by it's ID

    /${env.context.message.uniqueId?c}  <= look at the message we are currently in (so this component forms part of a post or this will error)

    /author <= Now look at the author of the specific post

    /profiles <= retrieve details from their profile

    /name <= retrieve a specific field by it's name

    /carrier/allowed").value  <= And here we're retrieving a specific group of fields. "Carrier" and an "Allowed" value under it.

     

    I'd assume this is a list of mobile carriers a user can assign themselves to?

     

    The "allowed" option changes the rest call from a value to a boolean, I think it refers to whether a user can access a field or not.

    For one of our random users it returns "true" for a field we have, and "false" for fields we don't have. As an admin you'll see "true" for all fields.

     

    You can retrieve the actual value like this:

    http://CommunityUrl/CommunityName/restapi/vc/users/id/UserID/profiles/name/name_first

    http://CommunityUrl/CommunityName/restapi/vc/users/id/UserID/profiles/name/carrier

     

    We have a custom field to store the users birthday (as a string in EPOCH) format, but we never included the ability to view, customise or edit it in our original spec... Hopefully you've got more than we got :)

     

    That cover what you're looking for?

     

    REST docs on the profile call over here:  http://community.lithium.com/t5/Community-API/bd-p/developers-rest-api?leaf-id=User.profiles#User.profiles

     

    T

     

  • Hey tyw , The rest call breaks down like this:

    /messages/id/${env.context.message.uniqueId?c}/author/profiles/name/carrier/allowed").value

     

    /messages <= look at messages

    /id <= look at a specific message by it's ID

    /${env.context.message.uniqueId?c}  <= look at the message we are currently in (so this component forms part of a post or this will error)

    /author <= Now look at the author of the specific post

    /profiles <= retrieve details from their profile

    /name <= retrieve a specific field by it's name

    /carrier/allowed").value  <= And here we're retrieving a specific group of fields. "Carrier" and an "Allowed" value under it.

     

    I'd assume this is a list of mobile carriers a user can assign themselves to?

     

    The "allowed" option changes the rest call from a value to a boolean, I think it refers to whether a user can access a field or not.

    For one of our random users it returns "true" for a field we have, and "false" for fields we don't have. As an admin you'll see "true" for all fields.

     

    You can retrieve the actual value like this:

    http://CommunityUrl/CommunityName/restapi/vc/users/id/UserID/profiles/name/name_first

    http://CommunityUrl/CommunityName/restapi/vc/users/id/UserID/profiles/name/carrier

     

    We have a custom field to store the users birthday (as a string in EPOCH) format, but we never included the ability to view, customise or edit it in our original spec... Hopefully you've got more than we got :)

     

    That cover what you're looking for?

     

    REST docs on the profile call over here:  http://community.lithium.com/t5/Community-API/bd-p/developers-rest-api?leaf-id=User.profiles#User.profiles

     

    T

     

    • tyw's avatar
      tyw
      Boss
      Holy moly, this is extremely helpful.

      Thank you very much your help explaining the code, I really appreciate this.