function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aryan_SFDCAryan_SFDC 

Make lightning quick action accessible by custom permissions of users

Hi,

I have a aura component and added it ti quick action button.
I want it to be accessible only to users having certain permission set or custom permission.
else when user click on it it should throw an error saying "you are not authorized".
I have written logic in apex class "createQuickContactController" method checkCustomPermission.
but not sure how to add this logic in aura component and controller.
any suggestions will be much appreciated.

component:
<aura:component controller="createQuickContactController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" 
                access="global">

    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="Name" type="String"/>
    <aura:attribute name="account" type="Account"/>
    <aura:attribute name="contact" type="Contact" 
   default="{ 'sobjectType': 'Contact','MailingCountry':'Brazil'}"/>
  
   <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:recordEditForm aura:id="recordEditForm"
                              objectApiName="Contact"
                             >
    <lightning:messages /> 
        <div class="slds-grid">
        <div class="slds-col slds-size_1-of-2">
        <lightning:inputField fieldName="LastName" value="{!v.contact.LastName}"/>
        <lightning:inputField fieldName="AccountId" value="{!v.recordId}"/>
        <lightning:inputField fieldName="MailingCountry" value="{!v.contact.MailingCountry}"/>
        <lightning:inputField fieldName="MailingState" value="{!v.contact.MailingState}"/>
        <lightning:inputField fieldName="MailingCity" value="{!v.contact.MailingCity}"/>
        <lightning:inputField fieldName="MailingStreet" value="{!v.contact.MailingStreet}"/>
        <lightning:inputField fieldName="MailingPostalCode" value="{!v.contact.MailingPostalCode}"/>
          </div>
        </div>
        </lightning:recordEditForm>
    
        
    <lightning:button class="slds-m-top_small" type="cancel" label="Cancel" onclick="{!c.handleCancel}"/> 
    <lightning:button aura:id="insert" label="Save" class="slds-m-top_small" onclick="{!c.InsertCont}"/>
</aura:component>


Controller:
({    
        doInit : function(component, event, helper) {
        var accid = component.get("v.recordId");
        component.set("v.contact.AccountId",component.get("v.recordId"));
        var action=component.get("c.getAccount");
        action.setParams({
            acid : component.get("v.recordId")            
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS"){
                component.set("v.account",response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
        
    },
    
    
    InsertCont: function(component) {
        var action=component.get("c.insertCon");
        action.setParams({ newcon: component.get("v.contact") });  
        action.setCallback(this, function(response) {
            
            let state = response.getState(); 
            console.log(response.getReturnValue());
            if ( state === "SUCCESS" ) {  
                
                $A.get("e.force:closeQuickAction").fire();  
                $A.get('e.force:refreshView').fire();   
                
            }  else {
                
                let showToast = $A.get( "e.force:showToast" );
                showToast.setParams({
                    title : 'Testing Toast!!!',
                    message : 'Record Not Saved due to error.' ,
                    type : 'error',
                    mode : 'sticky',
                    message : 'Some error occured'
                });
                showToast.fire();
                
            }
        });  
        $A.enqueueAction( action );         
        
    },
    handleCancel: function(cmp, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }

})


Apex class:

public class createQuickContactController
{
@AuraEnabled
    public static contact insertCon(Contact newcon)
    {
        System.debug(newcon);
        insert newcon;
        return newcon;        
    }
    @AuraEnabled
    public static Account getAccount(string acid)
    {
        Account acc = [select id,BillingCity,BillingCountry,BillingStreet,BillingState,BillingPostalCode,name from Account where Id =:acid];
        return acc;
    }
    @AuraEnabled
    public static Boolean checkCustomPermission(Boolean custpermission){
    Boolean hasCustomPermission = FeatureManagement.checkPermission('Create_Quick_Contact');
    return hasCustomPermission;
    }