Forum Discussion

elopez's avatar
elopez
Contributor
13 years ago

trying to apply roles in customer component

I have the following custom component that I am trying to run but unfortunately the rest api is not returning a value. I am simply trying to add the administrator role to a specific user in our community.

 

<#if activity.results.name.UserSignedOn??>
 <#if user.login == "jvcd">
   <#assign status=rest("/roles/name/Administrator/users/add/id/${user.id?c}").value />
   <span>Status:${status?string}</span>
 </#if>

 

 

1 Reply

  • AdamN's avatar
    AdamN
    Khoros Oracle
    13 years ago

    When you use the "rest" context object, the call is made as the user viewing the page. So when "jvcd" hits the page as a regular user, it's making a REST API call as "jvcd" to add the "Administrator" role to himself. Only administrators can grant the administrator role, so the request is getting rejected because "jvcd" doesn't have sufficient permission.

     

    I'm curious why this approach is necessary. Why not just grant the role via the community admin? I'd advise against trying to assign the Administrator role via Freemarker components due to the security implications it has. What happens if one day you no longer want "jvcd" to be an Administrator? Removing the role via the admin panel isn't enough, because "jvcd" can just login again to get the "Administrator" role again. You'd have to go through the entire process of making and deploying Studio changes in order to effectively remove the role from this user.