Recommend please some way, how to implement preventing downloading files from Partner Portal for particular users?
For these users, files must be VIEW ONLY without any ability to download them
You can take a look at ContentDownloadHandlerFactory and ContentDownloadHandler to implement your own custom solution.
When a download is triggered either from the
UI
,Connect API
, or ansObject
call retrievingContentVersion.VersionData
, implementations of theSfc.ContentDownloadHandlerFactory
are looked up. If no implementation is found, download proceeds. Otherwise, the user is redirected to what has been defined in theContentDownloadHandler#redirectUrl
property. If several implementations are found, they are cascade handled (ordered by name) and the first one for which the download isn’t allowed is considered.
For instance:
public class ContentDownloadHandlerFactoryImpl implements Sfc.ContentDownloadHandlerFactory {
public Sfc.ContentDownloadHandler getContentDownloadHandler(
List<Id> ids, Sfc.ContentDownloadContext context
) {
Sfc.ContentDownloadHandler contentDownloadHandler = new Sfc.ContentDownloadHandler();
if(UserInfo.getProfileId() == '005xx000001SvogAAC') {
contentDownloadHandler.isDownloadAllowed = true;
return contentDownloadHandler;
}
if(context == Sfc.ContentDownloadContext.MOBILE) {
contentDownloadHandler.isDownloadAllowed = false;
contentDownloadHandler.downloadErrorMessage =
'Downloading a file from a mobile device isnt allowed.';
return contentDownloadHandler;
}
contentDownloadHandler.isDownloadAllowed = false;
contentDownloadHandler.downloadErrorMessage =
'This file needs to be IRM controlled. Youre not allowed to download it';
contentDownloadHandler.redirectUrl ='/apex/IRMControl?Id='+ids.get(0);
return contentDownloadHandler;
}
}