Beispiel #1
0
        internal static AllowedOperation GetAllowedOperationAddRecipient(FolderIdentifier folderIdentifier, FolderModel folder)
        {
            var recipients = folder.MetaEDiscoveryRecipientListRead();

            var defenseEmail = folder.Read <string>("attribute.defense.email");

            AddRecipientRequest.AddRecipientDefaults defaults =
                defenseEmail == null || recipients.Any(r => r.Email == defenseEmail)
                ? new AddRecipientRequest.AddRecipientDefaults()
                : new AddRecipientRequest.AddRecipientDefaults
            {
                FirstName = folder.Read <string>("attribute.defense.first"),
                LastName  = folder.Read <string>("attribute.defense.last"),
                Email     = folder.Read <string>("attribute.defense.email")
            };

            return(new AllowedOperation
            {
                DisplayName = "Add Recipient",
                IsSingleton = true,
                BatchOperation = new AddRecipientRequest
                {
                    FolderIdentifier = folderIdentifier,
                    Defaults = defaults
                }
            });
        }
Beispiel #2
0
        private Dictionary <string, string> FieldsFromMetadata(FolderModel folderModel, FileModel fileModel)
        {
            var fields            = new Dictionary <string, string>();
            var attributeLocators = folderModel.Read <List <AttributeLocator> >(MetadataKeyConstants.ATTRIBUTE_LOCATORS);

            if (attributeLocators != null)
            {
                foreach (var locator in attributeLocators)
                {
                    if (locator.IsIndexed)
                    {
                        try
                        {
                            var value = fileModel.Read <string>(locator.Key)
                                        ?? folderModel.Read <string>(locator.Key);

                            fields.Add(locator.Key, value);
                        }
                        catch (Exception)
                        {
                            // well... we tried
                        }
                    }
                }
            }

            return(fields);
        }
Beispiel #3
0
        public void Read(FolderModel folder, bool skipFiles = false, bool skipFolderPaths = false, Func <FileModel, PathIdentifier> pathReader = null)
        {
            if (pathReader == null)
            {
                pathReader = APIModelExtensions.MetaPathIdentifierRead;
            }

            if (!skipFolderPaths)
            {
                Add(folder.Read("_paths", defaultValue: new List <string>())
                    .Select(p => new PathIdentifier(this.FolderIdentifier, p))
                    .ToList());
            }

            if (!skipFiles)
            {
                // find any paths mentioned on folders
                foreach (var file in folder.Files.Rows)
                {
                    var pathIdentifier = pathReader(file);
                    if (pathIdentifier != null)
                    {
                        Add(pathIdentifier);
                    }
                }
            }

            Process();
        }
Beispiel #4
0
        private async Task <long> MovePathToPath(
            FolderModel folder,
            PathIdentifier destinationPathIdentifier,
            PathIdentifier sourcePathIdentifier
            )
        {
            // if we're moving
            // z of x/y/z to a/b/c
            // then pathDestination will be a/b/c/z
            var pathDestination = destinationPathIdentifier.CreateChild(sourcePathIdentifier.LeafName);

            long affectedCount = 0;

            // find files in contained by our source path, or a child of it
            var descendants = GetPathDescendants(folder, sourcePathIdentifier);

            foreach (var file in descendants)
            {
                var path = file.MetaPathIdentifierRead();

                // todo: move this logic to PathProcessor
                // replace the old key with the new key
                path.PathKey = Regex.Replace
                               (
                    path?.PathKey,
                    $"^{Regex.Escape(sourcePathIdentifier.PathKey)}",
                    pathDestination.PathKey
                               );

                file.MetaPathIdentifierWrite(path);
                await Connection.File.PutAsync(file);

                affectedCount++;
            }

            // update the folder's path reservations
            var paths = folder.Read <List <string> >("_paths");

            if (paths != null)
            {
                var pathsAffected = 0;
                for (int i = 0; i < paths.Count; i++)
                {
                    if (paths[i].StartsWith(sourcePathIdentifier.PathKey))
                    {
                        pathsAffected++;
                        paths[i] = paths[i].Replace(
                            sourcePathIdentifier.PathKey,
                            pathDestination.PathKey
                            );
                    }
                }
                if (pathsAffected > 0)
                {
                    folder.Write("_paths", paths);
                    await Connection.Folder.PutAsync(folder);
                }
            }
            return(affectedCount);
        }
Beispiel #5
0
        public static PasswordTouple GeneratePassword(FolderModel folder, string randomPasswordLengthLocation, string defaultPasswordLength, string passwordCharacterSetLocation)
        {
            var lengthValue = folder.Read <string>(randomPasswordLengthLocation) ?? defaultPasswordLength;
            var length      = Int32.Parse(lengthValue);

            var charSet = folder.Read <string>(passwordCharacterSetLocation);

            // first generate a password
            var plainPassword = PasswordGenerator.GetRandomString(length, charSet);

            // Now generate a hash
            var hashedPassword = BCrypt.HashPassword(plainPassword);

            return(new PasswordTouple()
            {
                Plain = plainPassword, Hashed = hashedPassword
            });
        }
Beispiel #6
0
        public List <EDiscoveryManagerPathModel> BuildDatedPackagesDynamicFolder(FolderModel folder)
        {
            var managerPaths = new List <EDiscoveryManagerPathModel>();

            var packageMap = folder.Read <EDiscoveryPackageMap>(MetadataKeyConstants.E_DISCOVERY_PACKAGE_MAP_METAKEY);

            if (this.IsModuleActive(folder))
            {
                // go through all the folders, and find all the
                foreach (var file in folder.Files.Rows
                         .Where(f => f.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE) != null)
                         )
                {
                    var sharePackageName       = file.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE);
                    var sharePackageIdentifier = new PathIdentifier(file.Identifier as FolderIdentifier, "eDiscovery/" + sharePackageName);

                    // Here we're checking to make sure we haven't already added this 'dated share folder'
                    if (!managerPaths.Any(mp => mp.Identifier.Equals(sharePackageIdentifier)))
                    {
                        var processor = new PathProcessor(folder.Identifier);
                        processor.Read(folder, skipFolderPaths: true, pathReader: f => {
                            var sharePath = f.MetaEDiscoveryPathIdentifierRead();
                            if (sharePackageName != null &&
                                f.Read <string>(MetadataKeyConstants.E_DISCOVERY_SHARE_PACKGAGE) != sharePackageName)
                            {
                                return(null);
                            }

                            if (sharePath != null)
                            {
                                return(sharePackageIdentifier.CreateChild(sharePath.PathKey));
                            }
                            else
                            {
                                return(sharePath);
                            }
                        });

                        var packagePath = new EDiscoveryManagerPathModel()
                        {
                            Identifier        = sharePackageIdentifier,
                            Icons             = new string[] { EDiscoveryUtility.EDISCOVERY_FOLDER_COLOR_STYLE },
                            Name              = sharePackageName,
                            FullPath          = sharePackageIdentifier.FullName,
                            Paths             = processor[sharePackageIdentifier]?.Paths,
                            CustomName        = EDiscoveryUtility.GetCustomName(packageMap, sharePackageName),
                            AllowedOperations = EDiscoveryUtility.IsUserEDiscovery(connection.UserAccessIdentifiers) ? new AllowedOperation[] { } : new AllowedOperation[] { AllowedOperation.GetAllowedOperationEditPackageName(folder.Identifier, sharePackageName) },
                        };
                        managerPaths.Add(packagePath);
                    }
                }
            }

            return(managerPaths);
        }
Beispiel #7
0
        public static List <ExternalUser> MetaExternalUserListRead(this FolderModel folder, string metadataKeyLocation, bool includeHash = true)
        {
            var externalUsers = folder.Read <List <ExternalUser> >(metadataKeyLocation, defaultValue: new List <ExternalUser>());

            if (!includeHash)
            {
                foreach (var externalUser in externalUsers)
                {
                    externalUser.PasswordHash = null;
                }
            }

            return(externalUsers);
        }
Beispiel #8
0
        private List <FacetString> FacetsFromMetadata(FolderModel folderModel, FileModel fileModel)
        {
            var facets            = new List <FacetString>();
            var attributeLocators = folderModel.Read <List <AttributeLocator> >(MetadataKeyConstants.ATTRIBUTE_LOCATORS);

            if (attributeLocators != null)
            {
                foreach (var locator in attributeLocators)
                {
                    if (locator.IsFacet)
                    {
                        var value = fileModel.Read <string>(locator.Key)
                                    ?? folderModel.Read <string>(locator.Key);

                        facets.Add(new FacetString
                        {
                            Name  = locator.Key,
                            Value = value
                        });
                    }
                }
            }

            var extension = fileModel.Extension;

            if (extension != null && extension.Length > 4)
            {
                extension = null;
            }

            facets.Add(new FacetString {
                Name = "extension", Value = extension
            });

            return(facets);
        }
Beispiel #9
0
        private async Task <ModelBase> RemoveOfficerAsync(RemoveOfficerRequest removeRequest)
        {
            FolderModel folder = null;

            await connection.ConcurrencyRetryBlock(async() =>
            {
                folder         = await connection.Folder.GetAsync(removeRequest.FolderIdentifier);
                var recipients = folder.MetaLEOUploadOfficerListRead();

                var recipient = recipients.FirstOrDefault(f => f.Email == removeRequest.RecipientEmail);

                folder.MetaLEOUploadOfficerListRemove(removeRequest.RecipientEmail);

                var paths = folder.Read <List <string> >("_paths");
                if (paths != null && recipient != null)
                {
                    var officerPath = GetOfficerPath(folder.Identifier, recipient.FirstName, recipient.LastName);
                    if (paths.Contains(officerPath.PathKey))
                    {
                        paths = paths.Where(p => !p.StartsWith(officerPath.PathKey)).ToList();
                    }

                    folder.Write("_paths", paths);
                }

                await connection.Folder.PutAsync(folder);
            });

            await InitializePrivilegedConnectionAsync();

            // Using the special connection here to delete the user.
            await privilegedConnection.User.DeleteAsync(ModuleUtility.GetFolderScopedUserIdentifier(folder.Identifier, removeRequest.RecipientEmail, "leo"));

            await this.auditLogStore.AddEntry(
                new AuditLogEntry()
            {
                EntryType  = AuditLogEntryType.LEOUploadOfficerDeleted,
                Message    = $"An officer has been removed {removeRequest.RecipientEmail}",
                ModuleType = Modules.ModuleType.LEOUpload
            },
                folder.Identifier
                );

            return(new RecipientResponse()
            {
                Email = removeRequest.RecipientEmail,
            });
        }
Beispiel #10
0
        public static DateTime?GetLinkExpirationDate(FolderModel folder, string ExpirationSecondsMetadataKeyLocation)
        {
            int?expirationSeconds         = 2592000; // This is 30 days as a default if there's no settings in the databse.
            var expirationSecondsMetadata = folder.Read <int>(ExpirationSecondsMetadataKeyLocation);

            if (expirationSecondsMetadata > 0)
            {
                expirationSeconds = expirationSecondsMetadata;
            }

            DateTime?expirationDate = null;

            if (expirationSeconds != null)
            {
                expirationDate = DateTime.UtcNow.AddSeconds(expirationSeconds.Value);
            }

            return(expirationDate);
        }
Beispiel #11
0
        private async Task UpsertPackageMap(FolderModel folder, string packageName, string customName)
        {
            // Here we're going to create a package map if one doesn't exist.
            var packageMap = folder.Read <EDiscoveryPackageMap>(MetadataKeyConstants.E_DISCOVERY_PACKAGE_MAP_METAKEY);

            // If this is the first package, we're going to create a package map.
            if (packageMap == null)
            {
                packageMap = new EDiscoveryPackageMap
                {
                    Map = new Dictionary <string, PackageAttributes>()
                };
            }
            packageMap.Map.Add(packageName, new PackageAttributes()
            {
                CustomName = customName
            });

            folder.Write <EDiscoveryPackageMap>(MetadataKeyConstants.E_DISCOVERY_PACKAGE_MAP_METAKEY, packageMap);
            await connection.Folder.PutAsync(folder);
        }
Beispiel #12
0
        public ManagerFolderModel ModelConvert(FolderModel folderModel)
        {
            var managerModel = new ManagerFolderModel
            {
                Identifier = folderModel.Identifier
            };

            managerModel.Fields = new Dictionary <string, object>();

            var fields = ReadMetadataFields(folderModel);

            if (fields != null)
            {
                foreach (var field in fields)
                {
                    managerModel.Fields.Add(
                        field.Identifier,
                        folderModel.Read <string>(field.Key)
                        );
                }
            }

            return(managerModel);
        }
Beispiel #13
0
 private static ManagerFieldBaseSchema GetFieldSchema(FolderModel folder)
 {
     return(folder.Read <ManagerFieldBaseSchema>(MetadataKeyConstants.SCHEMA_DEFINITION));
 }
Beispiel #14
0
        public static DataViewModel BuildDataViewModel(FolderModel folder)
        {
            // First we grab the schema.
            var schema    = GetFieldSchema(folder);
            var dataModel = new Dictionary <string, object>();

            // Now we have the schema we also need to build up the data model as well.
            if (schema != null && schema is ManagerFieldObject)
            {
                var managerFieldObject = schema as ManagerFieldObject;

                foreach (var property in managerFieldObject.Properties)
                {
                    if (property.Value is ManagerFieldString)
                    {
                        dataModel.Add(
                            property.Value.AttributeStorageLocationKey,
                            // Read out of metadata, the property.value, which will be a base schema object.  That object will have a AttributeStorageLocationKey
                            // this will be where the actual value of this data is stored.
                            folder.Read <string>(property.Value.AttributeStorageLocationKey)
                            );
                    }
                    if (property.Value is ManagerFieldInt)
                    {
                        dataModel.Add(
                            property.Value.AttributeStorageLocationKey,
                            folder.Read <int>(property.Value.AttributeStorageLocationKey)
                            );
                    }
                    if (property.Value is ManagerFieldBoolean)
                    {
                        dataModel.Add(
                            property.Value.AttributeStorageLocationKey,
                            folder.Read <bool>(property.Value.AttributeStorageLocationKey)
                            );
                    }
                    if (property.Value is ManagerFieldObject)
                    {
                        dataModel.Add(
                            property.Value.AttributeStorageLocationKey,
                            folder.Read <object>(property.Value.AttributeStorageLocationKey)
                            );
                    }
                    if (property.Value is ManagerFieldDecimal)
                    {
                        dataModel.Add(
                            property.Value.AttributeStorageLocationKey,
                            folder.Read <decimal>(property.Value.AttributeStorageLocationKey)
                            );
                    }
                }

                return(new DataViewModel
                {
                    DataModel = dataModel,
                    DataSchema = schema,
                    AllowedOperations = new List <AllowedOperation>()
                    {
                        AllowedOperation.GetAllowedOperationSave(folder.Identifier),
                    }
                });
            }
            else
            {
                return(null);
            }
        }
Beispiel #15
0
 public override bool IsModuleActive(FolderModel folder)
 {
     //First we need to determine based on metadata whether leo upload is active for this folder.
     return(folder.Read <bool>(MetadataKeyConstants.LEO_UPLOAD_ACTIVE_METAKEY));
 }
Beispiel #16
0
 private List <ManagerFieldsMetadataModel> ReadMetadataFields(FolderModel folderModel)
 {
     return(folderModel.Read <List <ManagerFieldsMetadataModel> >(ManagerFieldsMetadataModel.METADATA_KEY_LIST));
 }
Beispiel #17
0
 public override bool IsModuleActive(FolderModel folder)
 {
     //First we need to determine based on metadata whether eArraignment is active for this folder.
     return(folder.Read <bool>(E_ARRAIGNMENT_ACTIVE));
 }
Beispiel #18
0
 public override bool IsModuleActive(FolderModel folder)
 {
     //First we need to determine based on metadata whether E-Discovery is active for this folder.
     return(folder.Read <bool>(MetadataKeyConstants.E_DISCOVERY_ACTIVE_METAKEY));
 }