Render component based on users access to a field

Anyone have a good way to conditionally render a component based on whether the user has access to edit a particular field?
I have buttons in a button set that edit a field, but if the user doesn't have permission to edit that field, they don't need the buttons...
I have buttons in a button set that edit a field, but if the user doesn't have permission to edit that field, they don't need the buttons...
Tagged:
1
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
The other benefit of this approach is that you don't need knowledge of the specific skuid Model name. With page includes, you have to maintain uniqueness of model names so you don't run into conflicts with your models, which implies a lot of model names to keep track of in snippets. Moving the snippet logic to the general sObject means only one snippet per object. Ideally It would be nice to pass the SObject name as a parameter into the snippet from the pagebuilder so there's only one snippet, but we're not there yet with snippet parameters.
if(skuid.utils.getAPIDescribeSObject('Account') !== null)
{
if( skuid.utils.getAPIDescribeSObject('Account').queryable == 'true' )
{
return true;
}
}
else{
return false;
}
Likewise, you could disable a new record button if the user doesn't have permission to crate a target object record:
if(skuid.utils.getAPIDescribeSObject('Account') !== null)
{
if( skuid.utils.getAPIDescribeSObject('Account').createable == 'true' )
{
return true;
}
}
else{
return false;
}
A couple details of interest. Unlike the skuid.model API, the values in skuid.utils.getAPIDescribeSObject return as a string, which is why the return is wrapped in the if statement. Also, there's a null check, which handles script errors if the user has no access to the object.
Is there a way to extend your logic to a specific field? What if the user has access to edit an object but not a specific field?
SObj = skuid.utils.getAPIDescribeSObject('Account');
if(SObj !== null)
{
var fields = SObj.fields;
$.each(fields,function(e,field){
if(field.name == 'LastName' && field.updateable == 'true'){
result = true ;
}
});
}
return result;
https://community.skuid.com/skuid/topics/provide-context-parameter-to-conditional-rendering-snippet-...