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
ywamtsvywamtsv 

Show Related List in Lightning component

I have an aura:component that utilises the lighting:fileUpload input. Which works great. 

Due to not being able to use OWD sharing settings, I want to show a related list of files on a record that only that (Community) User owns.
This is done in a community, and we've had to open our OWD for our partner users, but don't want our Customer users to see files not owned by them.
All I have is the {!v.recordId} to work with. 

Best Answer chosen by ywamtsv
ywamtsvywamtsv
Apex Class

public class Listattachments {
@AuraEnabled
      public static List <ContentDocument> getAttachments() {
        return [SELECT Id, Title, OwnerId FROM ContentDocument WHERE OwnerId =: UserInfo.getUserId()];
      }
}
Component
<aura:component controller="ListAttachments" implements=",force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
        <aura:attribute name="attachments" type="List" />
        <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
        <aura:iteration items="{!v.attachments}" var="files">
            {!files.Id}
    
    </aura:iteration>
    
</aura:component>

Controller
doInit: function(component, event, helper) {
        // Fetch the attachment list from the Apex controller
        helper.getAttachmentList(component);
      },

Helper
({
      // Fetch the attachments from the Apex controller
      getAttachmentList: function(component) {
        var action = component.get('c.getAttachments');
        // Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
         component.set('v.attachments', actionResult.getReturnValue());
        });
        $A.enqueueAction(action);
      }
    })