public override void AlterGridTitle(string gridTitle, PathIdentifier identifier) { if (EDiscoveryUtility.IsEDiscoveryPath(identifier)) { gridTitle = identifier.FullName; } }
public override void AlterSubPathOperations(PathIdentifier pathIdentifier, List <AllowedOperation> subPathDefaultOperations) { if (EDiscoveryUtility.IsEDiscoveryPath(pathIdentifier)) { // If it's an eDiscovery path, we're going to clear out the allowed operations. subPathDefaultOperations.Clear(); } else { subPathDefaultOperations.Add(AllowedOperation.GetAllowedOperationShare(pathIdentifier, true)); subPathDefaultOperations.Add(AllowedOperation.GetAllowedOperationShare(pathIdentifier, false)); } }
public override void OverrideAllowedOperations(FileModel fileModel, List <AllowedOperation> allowed, PathIdentifier virtualPathIdentifier) { if (EDiscoveryUtility.IsEDiscoveryPath(virtualPathIdentifier)) { allowed.Clear(); allowed.Add( AllowedOperation.GetAllowedOperationDownload(fileModel.Identifier, false) ); allowed.Add( AllowedOperation.GetAllowedOperationDownloadZip(fileModel.Identifier) ); } // The allowed operations depend on what state the file is in. switch (EDiscoveryUtility.GetCurrentShareState(fileModel)) { case EDiscoveryShareState.NotShared: // If the file hasn't been shared yet, we can "Share" it. allowed.Add(AllowedOperation.GetAllowedOperationShare(fileModel.Identifier, true)); break; case EDiscoveryShareState.Staged: // If the file has only been staged, the we can "unshare" it. allowed.Add(AllowedOperation.GetAllowedOperationShare(fileModel.Identifier, false)); break; case EDiscoveryShareState.Published: // If it's been published there isn't anything related to sharing that you can do on the file. // However if it's published we're not going to allow you to delete the file. allowed.RemoveAll(action => action.BatchOperation is DeleteRequest); allowed.RemoveAll(action => action.BatchOperation is RenameRequest); break; default: break; } }
public async Task Post( [FromForm] string payloadJSON, CancellationToken cancellationToken ) { // don't write the extra json around our response, because our response is a file not json SuppressWrapper = true; var request = JsonConvert.DeserializeObject <BatchRequest>(payloadJSON); var setOperations = request.Operations.Select(o => o.Type).ToHashSet(); // if all operations are in this set of types if (setOperations.All(o => new string[] { typeof(DownloadZipFileRequest).Name, }.Any(s => s == o))) { var allFileIdentifiers = new List <FileIdentifier>(); // add all FileIdentifiers in the request allFileIdentifiers.AddRange(request.Operations .OfType <DownloadZipFileRequest>() .Where(r => r.FileIdentifier != null) .Select(d => d.FileIdentifier)); // for each path in the request, load the recursive set of var pathIdentifiers = request.Operations .OfType <DownloadZipFileRequest>() .Where(r => r.PathIdentifier != null) .Select(d => d.PathIdentifier); var zipName = "File.zip"; var firstPath = pathIdentifiers?.FirstOrDefault(); var isEDiscoveryPath = EDiscoveryUtility.IsEDiscoveryPath(firstPath); var firstFile = allFileIdentifiers.Any() ? await api.File.GetAsync(allFileIdentifiers.First()) : null; if (firstFile != null) { var packageName = firstFile.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE); if (packageName != null) { zipName = PathService.MakeFilenameSafe($"{packageName}.zip"); isEDiscoveryPath = true; } } if (pathIdentifiers.Any()) { // we're going to assume that all the paths are in the same folder. if not, this // isn't going to work. var state = await PathService.OpenFolder( firstPath as FolderIdentifier, isEDiscoveryPath, cancellationToken ); var packageIdentifier = EDiscoveryUtility.GetPackageIdentifier(firstPath); if (packageIdentifier != null) { foreach (var pathIdentifier in pathIdentifiers) { var relativePath = pathIdentifier.RelativeTo(packageIdentifier); allFileIdentifiers.AddRange(state.Folder.Files.Rows .Where(f => { var filePath = f.MetaEDiscoveryPathIdentifierRead(); if (filePath == null) { return(relativePath.IsRoot); } else { return(filePath.IsChildOf(relativePath)); } }) .Where(f => !f.Read <bool>(MetadataKeyConstants.HIDDEN)) .Select(f => f.Identifier) ); } } else { foreach (var pathIdentifier in pathIdentifiers) { allFileIdentifiers.AddRange( PathService.GetPathDescendants(state.Folder, pathIdentifier) .Select(f => f.Identifier) ); } } } await PathService.DownloadZip(zipName, allFileIdentifiers, Response, pathGenerator : f => isEDiscoveryPath ?EDiscoveryUtility.MetaEDiscoveryPathIdentifierRead(f) : APIModelExtensions.MetaPathIdentifierRead(f), cancellationToken : cancellationToken); } }