Example #1
0
        public Task <Either <ActionResult, Unit> > DeleteRelease(Guid releaseId)
        {
            return(_persistenceHelper
                   .CheckEntityExists <Release>(releaseId)
                   .OnSuccess(_userService.CheckCanDeleteRelease)
                   .OnSuccessDo(async() => await _releaseDataFileService.DeleteAll(releaseId))
                   .OnSuccessDo(async() => await _releaseFileService.DeleteAll(releaseId))
                   .OnSuccessVoid(async release =>
            {
                var roles = await _context
                            .UserReleaseRoles
                            .Where(r => r.ReleaseId == releaseId)
                            .ToListAsync();

                var invites = await _context
                              .UserReleaseInvites
                              .Where(r => r.ReleaseId == releaseId)
                              .ToListAsync();

                release.SoftDeleted = true;
                roles.ForEach(r => r.SoftDeleted = true);
                invites.ForEach(r => r.SoftDeleted = true);

                _context.Update(release);
                _context.UpdateRange(roles);
                _context.UpdateRange(invites);

                await _context.SaveChangesAsync();

                await _releaseSubjectService.SoftDeleteAllReleaseSubjects(releaseId);
            }));
        }
Example #2
0
        private async Task <Either <ActionResult, Unit> > DeleteContentAndStatsRelease(Guid releaseId)
        {
            var contentRelease = await _contentContext
                                 .Releases
                                 .AsQueryable()
                                 .SingleOrDefaultAsync(r => r.Id == releaseId);

            if (contentRelease == null)
            {
                // The Content Db Release may already be soft-deleted and therefore not visible.
                // Attempt to hard delete the Content Db Release by ignoring the query filter
                await DeleteSoftDeletedContentDbRelease(releaseId);
                await DeleteStatsDbRelease(releaseId);

                return(Unit.Instance);
            }

            return(await _releaseDataFileService.DeleteAll(releaseId, forceDelete : true)
                   .OnSuccessDo(() => _releaseFileService.DeleteAll(releaseId, forceDelete: true))
                   .OnSuccessDo(() => DeleteCachedReleaseContent(releaseId, contentRelease.PublicationId))
                   .OnSuccessVoid(async() =>
            {
                _contentContext.Releases.Remove(contentRelease);
                await _contentContext.SaveChangesAsync();

                await DeleteStatsDbRelease(releaseId);
            }));
        }
Example #3
0
        public Task <Either <ActionResult, Unit> > DeleteRelease(Guid releaseId)
        {
            return(_persistenceHelper
                   .CheckEntityExists <Release>(releaseId)
                   .OnSuccess(_userService.CheckCanDeleteRelease)
                   .OnSuccessDo(async release => await _cacheService.DeleteCacheFolder(
                                    new ReleaseContentFolderCacheKey(release.PublicationId, release.Id)))
                   .OnSuccessDo(async() => await _releaseDataFileService.DeleteAll(releaseId))
                   .OnSuccessDo(async() => await _releaseFileService.DeleteAll(releaseId))
                   .OnSuccessVoid(async release =>
            {
                release.SoftDeleted = true;
                _context.Update(release);

                var roles = await _context
                            .UserReleaseRoles
                            .AsQueryable()
                            .Where(r => r.ReleaseId == releaseId)
                            .ToListAsync();
                roles.ForEach(r => r.SoftDeleted = true);
                _context.UpdateRange(roles);

                var invites = await _context
                              .UserReleaseInvites
                              .AsQueryable()
                              .Where(r => r.ReleaseId == releaseId)
                              .ToListAsync();
                invites.ForEach(r => r.SoftDeleted = true);
                _context.UpdateRange(invites);

                var methodologiesScheduledWithRelease =
                    GetMethodologiesScheduledWithRelease(releaseId);

                // TODO EES-2747 - this should be looked at to see how best to reuse similar "set to draft" logic
                // in MethodologyApprovalService.
                methodologiesScheduledWithRelease.ForEach(m =>
                {
                    m.PublishingStrategy = Immediately;
                    m.Status = Draft;
                    m.ScheduledWithRelease = null;
                    m.ScheduledWithReleaseId = null;
                    m.InternalReleaseNote = null;
                    m.Updated = DateTime.UtcNow;
                });

                _context.UpdateRange(methodologiesScheduledWithRelease);

                await _context.SaveChangesAsync();

                await _releaseSubjectRepository.SoftDeleteAllReleaseSubjects(releaseId);
            }));
        }
        public async Task <Either <ActionResult, Unit> > DeleteTopic(Guid topicId)
        {
            return(await _userService.CheckCanManageAllTaxonomy()
                   .OnSuccess(
                       () => _persistenceHelper.CheckEntityExists <Topic>(
                           topicId,
                           q => q.Include(t => t.Publications)
                           .ThenInclude(p => p.Releases)
                           )
                       )
                   .OnSuccessDo(_userService.CheckCanManageAllTaxonomy)
                   .OnSuccessVoid(
                       async topic =>
            {
                // For now we only want to delete test topics as we
                // don't really have a mechanism to clean things up
                // properly across the entire application.
                // TODO: EES-1295 ability to completely delete releases
                if (!topic.Title.StartsWith("UI test topic"))
                {
                    return;
                }

                foreach (var release in topic.Publications.SelectMany(publication => publication.Releases))
                {
                    await _releaseDataFileService.DeleteAll(release.Id, forceDelete: true);
                    await _releaseFileService.DeleteAll(release.Id, forceDelete: true);
                    await _releaseSubjectService.DeleteAllReleaseSubjects(release.Id);
                }

                _statisticsContext.Release.RemoveRange(
                    _statisticsContext.Release.Where(r => r.Publication.TopicId == topic.Id)
                    );

                _statisticsContext.Topic.RemoveRange(
                    _statisticsContext.Topic.Where(t => t.Id == topic.Id)
                    );

                await _statisticsContext.SaveChangesAsync();

                _contentContext.Topics.RemoveRange(
                    _contentContext.Topics.Where(t => t.Id == topic.Id)
                    );

                await _contentContext.SaveChangesAsync();

                await _publishingService.TaxonomyChanged();
            }
                       ));
        }