Ejemplo n.º 1
0
        public async Task DeleteProjectAsync(string curUserId, string projectId)
        {
            string ptProjectId;

            using (IConnection conn = await RealtimeService.ConnectAsync(curUserId))
            {
                IDocument <SFProject> projectDoc = await conn.FetchAsync <SFProject>(projectId);

                if (!projectDoc.IsLoaded)
                {
                    throw new DataNotFoundException("The project does not exist.");
                }
                if (!IsProjectAdmin(projectDoc.Data, curUserId))
                {
                    throw new ForbiddenException();
                }

                ptProjectId = projectDoc.Data.ParatextId;
                // delete the project first, so that users get notified about the deletion
                string[] projectUserIds = projectDoc.Data.UserRoles.Keys.ToArray();
                await projectDoc.DeleteAsync();

                async Task removeUser(string projectUserId)
                {
                    IDocument <User> userDoc = await conn.FetchAsync <User>(projectUserId);

                    await RemoveUserFromProjectAsync(conn, projectDoc, userDoc);
                }

                var tasks = new List <Task>();
                foreach (string projectUserId in projectUserIds)
                {
                    tasks.Add(removeUser(projectUserId));
                }
                await Task.WhenAll(tasks);
            }

            await ProjectSecrets.DeleteAsync(projectId);

            await RealtimeService.DeleteProjectAsync(projectId);

            await _engineService.RemoveProjectAsync(projectId);

            string projectDir = Path.Combine(SiteOptions.Value.SiteDir, "sync", ptProjectId);

            if (FileSystemService.DirectoryExists(projectDir))
            {
                FileSystemService.DeleteDirectory(projectDir);
            }
            string audioDir = GetAudioDir(projectId);

            if (FileSystemService.DirectoryExists(audioDir))
            {
                FileSystemService.DeleteDirectory(audioDir);
            }
        }
Ejemplo n.º 2
0
        protected override async Task <bool> DeleteEntityAsync(string id)
        {
            bool result = await base.DeleteEntityAsync(id);

            if (result)
            {
                await SyncJobMapper.DeleteAllAsync(id);

                await TextMapper.DeleteAllAsync(id);

                await _engineService.RemoveProjectAsync(id);

                string syncDir = Path.Combine(_siteOptions.Value.SiteDir, "sync", id);
                if (Directory.Exists(syncDir))
                {
                    Directory.Delete(syncDir, true);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteAsync(string id)
        {
            Project project = await _projects.GetAsync(id);

            if (project == null)
            {
                return(NotFound());
            }
            if (!await AuthorizeAsync(project, Operations.Read))
            {
                return(StatusCode(StatusCodes.Status403Forbidden));
            }

            if (!await _engineService.RemoveProjectAsync(project.Id))
            {
                return(NotFound());
            }

            return(Ok());
        }