Пример #1
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);
        }
Пример #2
0
        private async Task ConfigureBackendAsync(OrganizationModel organizationModel, PCMSOrganizationModel pcms)
        {
            // create a private folder to store backend configuration
            var privateFolder = new FolderModel(new FolderIdentifier(organizationModel.Identifier, ":private"))
                                .InitializeEmptyMetadata()
                                .InitializeEmptyPrivileges();

            // write the backend configuration into the folder's metadata
            var backendConfiguration = new BackendConfiguration
            {
                DriverTypeName    = "Documents.Backends.Drivers.Encryption.Driver, Documents.Backends.Drivers.Encryption",
                ConfigurationJSON = JsonConvert.SerializeObject(new
                {
                    NextDriverTypeName          = "Documents.Backends.Drivers.S3.Driver, Documents.Backends.Drivers.S3",
                    MasterKey                   = pcms.MasterEncryptionKey,
                    NextDriverConfigurationJson = JsonConvert.SerializeObject(new
                    {
                        AWSRegion  = pcms.AWSS3Region,
                        BucketName = pcms.AWSS3BucketName,
                        pcms.AWSSecretAccessKey,
                        pcms.AWSAccessKeyID
                    })
                })
            };

            privateFolder.Write(MetadataKeyConstants.BACKEND_CONFIGURATION, backendConfiguration);
            privateFolder.WriteACLs("read", idSystem);
            privateFolder.WriteACLs("write", idSystem);
            privateFolder.WriteACLs("gateway", idSystem, idOrganizationMember);

            privateFolder.Write("synchronize", new
            {
                ConnectionString = pcms.PCMSDBConnectionString,
                pcms.CountyID,
                LastChangeLogID        = 0,
                LastAccountChangeLogID = 0
            });

            if (organizationModel.Read <bool?>("synchronize[isactive]") == null)
            {
                organizationModel.Write("synchronize[isactive]", true);
            }

            await api.Folder.PutAsync(privateFolder);
        }
Пример #3
0
        public static FolderModel UpdateFormData(
            Dictionary <string, object> dataModel,
            FolderModel model
            )
        {
            foreach (var item in dataModel)
            {
                model.Write(item.Key, item.Value);
            }

            return(model);
        }
Пример #4
0
        public async override Task <ManagerFolderModel> UpsertOneAsync(ManagerFolderModel model, CancellationToken cancellationToken = default(CancellationToken))
        {
            var folderModel = new FolderModel(model.Identifier);

            folderModel.InitializeEmptyMetadata();

            foreach (var field in model.Fields)
            {
                folderModel.Write(field.Key, field.Value);
            }

            folderModel = await Connection.Folder.PutAsync(folderModel, cancellationToken : cancellationToken);

            return(ModelConvert(folderModel));
        }
Пример #5
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,
            });
        }
Пример #6
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);
        }
Пример #7
0
        private async Task ConfigureBackendAsync(OrganizationModel organizationModel, BasicOrganizationModel configurationModel)
        {
            // create a private folder to store backend configuration
            var privateFolder = new FolderModel(new FolderIdentifier(organizationModel.Identifier, ":private"))
                                .InitializeEmptyMetadata()
                                .InitializeEmptyPrivileges();

            // write the backend configuration into the folder's metadata
            var backendConfiguration = new BackendConfiguration
            {
                DriverTypeName    = "Documents.Backends.Drivers.FileSystem.Driver, Documents.Backends.Drivers.FileSystem",
                ConfigurationJSON = JsonConvert.SerializeObject(new
                {
                    configurationModel.BasePath
                })
            };

            privateFolder.Write(MetadataKeyConstants.BACKEND_CONFIGURATION, backendConfiguration);
            privateFolder.WriteACLs("read", idSystem);
            privateFolder.WriteACLs("write", idSystem);
            privateFolder.WriteACLs("gateway", idSystem, idOrganizationMember);

            await api.Folder.PutAsync(privateFolder);
        }
Пример #8
0
 public static FolderModel MetaExternalUserListWrite(this FolderModel folder, List <ExternalUser> externalUsers, string metadataKeyLocation)
 {
     folder.Write(metadataKeyLocation, externalUsers);
     return(folder);
 }
Пример #9
0
        public void Write(FolderModel folder)
        {
            var pathList = this.PathMap.Keys.Select(k => k.PathKey).ToList();

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