-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@W-15946941: New task added to display files in the salesforce org (#…
…3799) Files uploaded via the app launcher in the orgs are currently not included in the metadata listings. To address this, the "display_files" task has been introduced to list these files efficiently. - This task gives the list of files in a tabular format querying the `ContentDocument`, fetching the fields Id, Filetype, and Filename, as filenames alone are not unique identifiers. - Upon uploading a new file, a fresh entry is generated in the `ContentDocument` entity, establishing it as the latest version in the `ContentVersion` entity. Subsequent uploads of new versions of already tracked documents are noted in the ContentVersion entity, without creating additional ContentDocument records. - Retrieving the latest version involves filtering the ContentVersion entity by setting IsLatest to true and employing the file's ContentDocumentId as the filter criterion.
- Loading branch information
1 parent
29853a8
commit 2f8a94e
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from cumulusci.tasks.salesforce import BaseSalesforceApiTask | ||
|
||
|
||
class ListFiles(BaseSalesforceApiTask): | ||
task_docs = """ | ||
Lists the available documents that has been uploaded to a library in Salesforce CRM Content or Salesforce Files | ||
""" | ||
|
||
def _run_task(self): | ||
self.return_values = [ | ||
{ | ||
"Id": result["Id"], | ||
"FileName": result["Title"], | ||
"FileType": result["FileType"], | ||
} | ||
for result in self.sf.query( | ||
"SELECT Title, Id, FileType FROM ContentDocument" | ||
)["records"] | ||
] | ||
self.logger.info(f"Found {len(self.return_values)} files") | ||
if len(self.return_values) > 0: | ||
self.logger.info(f"{'Id':<20} {'FileName':<50} {'FileType':<10}") | ||
|
||
# Print each row of the table | ||
for file_desc in self.return_values: | ||
self.logger.info( | ||
f"{file_desc['Id']:<20} {file_desc['FileName']:<50} {file_desc['FileType']:<10}" | ||
) | ||
|
||
return self.return_values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from unittest.mock import Mock | ||
|
||
from cumulusci.tasks.salesforce.salesforce_files import ListFiles | ||
from cumulusci.tasks.salesforce.tests.util import create_task | ||
|
||
|
||
class TestDisplayFiles: | ||
def test_display_files(self): | ||
task = create_task(ListFiles, {}) | ||
task._init_api = Mock() | ||
task._init_api.return_value.query.return_value = { | ||
"totalSize": 2, | ||
"records": [ | ||
{"Title": "TEST1", "Id": "0PS000000000000", "FileType": "TXT"}, | ||
{"Title": "TEST2", "Id": "0PS000000000001", "FileType": "TXT"}, | ||
], | ||
} | ||
task() | ||
|
||
task._init_api.return_value.query.assert_called_once_with( | ||
"SELECT Title, Id, FileType FROM ContentDocument" | ||
) | ||
assert task.return_values == [ | ||
{"Id": "0PS000000000000", "FileName": "TEST1", "FileType": "TXT"}, | ||
{"Id": "0PS000000000001", "FileName": "TEST2", "FileType": "TXT"}, | ||
] |