File whitelisting / blacklisting with ndrive

Hi,

I know that the nuxeo sync client ndrive is a relatively new thing. Is there a possibillity to limit the file types thet are synced from the folder? So that I can keep e.g. the pdf's in the same folder as the Office documents but only the Office documents are synced. Would be also useful to keep raw and jpeg images in the same folder but only sync the smaller jpgs.

Is there any type of file sync filtering?

Thanks in advance.

0 votes

1 answers

1151 views

ANSWER



Hi,

Server-side you can override the defaultFileSystemItemFactory contribution to the fileSystemItemFactory extension point with a Java class extending DefaultFileSystemItemFactory and overriding isFileSystemItem(DocumentModel doc, boolean includeDeleted, boolean relaxSyncRootConstraint).

By default we only check if the document is folderish or holds a blob. You could add a filter on the mime-type to return false (meaning the file won't be synchronized) in the case of a .pdf file for example.

// Check Folderish or BlobHolder with a blob
if (!doc.isFolder() && !hasBlob(doc)) {
   log.debug(String.format(
       "Document %s is not Folderish nor a BlobHolder with a blob, it cannot be adapted as a FileSystemItem.", doc.getId()));
    return false;
}

Client-side, unfortunately for now the blacklisted extensions are hardcoded in nuxeo-drive-client/nxdrive/client/common.py:

DEFAULT_IGNORED_SUFFIXES = [
    '~',  # editor buffers
    '.swp',  # vim swap files
    '.lock',  # some process use file locks
    '.LOCK',  # other locks
    '.part',  # partially downloaded files
]

So if you want to always blacklist .pdf files for example you will need to add this extension to the ignored suffixes and build the client, see contributor guide for instructions.

We are planning to allow customization of the file suffixes to ignore in a local configuration file, see related JIRA issue NXP-13219.

Hope this helps.

0 votes



Hi,

thanks for the Answer. How I understand it the client-side implementation would only have blacklisting? So I would like to have it server-side implemented whitelisting. Pulling git of nuxeo-drive-core I could change the sources accordingly but I think using the extension points (as you suggested) would be better. I'm new to nuxeo studio. Reading the documentation I'm confused about where to start. Do I have to write a XML extension, in nuxeo studio?

studio XML Extension

I need to give a component name, extension target and point.

Can I choose th component name freely?

<component name="SyncWhitelisting">

How to declare the extension target and point?

<extension target="target.component.identifier" point="extensionPointName">

When I input the extension to DefaultFileSystemItemFactory, do I need to redeclare the whole public function isFileSystemItem(..)? How does it get overwritten?

  public boolean isFileSystemItem(DocumentModel doc, boolean includeDeleted,
                boolean relaxSyncRootConstraint) throws ClientException {
      //include everything from original function here
      [ .. ]
      String blobFileName = blob.getFilename();
      String[] tokens = blobFileName.split("\\.(?=[^\\.]+$)");
      if (!tokens[2].equals("doc") || !tokens[2].equals("odt")) {
        log.debug(String.format(
          "Document %s is not MS Word or OpenOffice Text Document, it is banned from upload in FileSystemItem.", doc.getId()));
       return false;
      }
  return true;
  }

Does this example also prevent other files than .doc and .odt from upload via the web frontend?

01/08/2014

Yes blacklisting only client-side.

You need to write an XML extension, not necessarily in Studio. I encourage you to read the appropriate documentation starting from here: http://doc.nuxeo.com/x/VYAIAQ.

About overriding isFileSystemItem it depends on your needs, if you only want to add some behaviour you can extend it and add your clauses in the new method.

Your example will not prevent uploading other files than .doc and .odt via the web frontend, for this you need to customize the UI, you should find some related topics in the documentation.

01/13/2014