Forum Discussion

sullysnack's avatar
sullysnack
Khoros Alumni (Retired)
12 years ago

REST call for "Is the accepted-solutions feature enabled?"

Can Freemarker in a custom component check whether the board of the topic page has the accepted-solution feature enabled or not?

 

Say some boards in my community have the accepted-solutions feature enabled. Some boards have it disabled. I want to add a component to the topic-page quilt for all topic pages. In this component I want to query the number of solutions for the board of the current topic.
 
In REST calls for board information which contain /solutions in the path, when the accepted-solution feature is disabled I see server parse error:
"A required feature is not enabled: accepted-solutions."
 
Example code... Board AAA has the Aceepted Solutions feature enabled but BBB does not...
 
<#assign foo = -1 />
<#assign foo = rest("/boards/id/AAA/solutions/count").value />
 
<#assign foo2 = -1 />

<#attempt>

<#assign foo2 = rest("/boards/id/BBB/solutions/count").value />
<#recover>
</#attempt>
 
The foo2 call bombs the page even like this inside an attempt block.
 
To avoid the parser error I'd rather not hardcode the ids of the boards which have the AS feature disabled. Admins can change this setting at any time for any board.
 
Any ideas?
 
Thanks,
Dave

 

  • Hi Dave,

     

    We store things like that as a "setting" for the node. This particular setting is called config.enable_accepted_solutions. There are REST API calls to get settings for a node (community, category, board/blog/idea/etc). 

     

    Give this a try:

    /boards/id/AAA/settings/name/config.enable_accepted_solutions

     I hope this helps!

  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi Dave,

     

    We store things like that as a "setting" for the node. This particular setting is called config.enable_accepted_solutions. There are REST API calls to get settings for a node (community, category, board/blog/idea/etc). 

     

    Give this a try:

    /boards/id/AAA/settings/name/config.enable_accepted_solutions

     I hope this helps!

    • sullysnack's avatar
      sullysnack
      Khoros Alumni (Retired)

      Thanks, it works great. One more note:

      It looks like querying settings requires the restadmin call. I see the rest function alone does not have enough permissions in this case.

      • AdamN's avatar
        AdamN
        Khoros Oracle

        That's a great point. Settings calls will typically require admin access (or at least permission to manage that node), so when trying to access it through freemarker, you likely will need to use restadmin. Thanks for pointing that out.