Пример #1
0
        public async Task <IActionResult> DeleteOlderThan(int days)
        {
            if (days < 0)
            {
                return(RedirectToAction("Index"));
            }

            var project = await ProjectService.GetCurrentProjectSettings();

            if (project == null)
            {
                Log.LogError("project settings not found");
                return(RedirectToAction("Index"));
            }

            var cutoffUtc    = DateTime.UtcNow.AddDays(-days);
            var canEditPosts = await User.CanEditBlog(project.Id, AuthorizationService);

            var canEditPages = await User.CanEditPages(project.Id, AuthorizationService);

            if (canEditPages && canEditPosts)
            {
                await HistoryCommands.DeleteOlderThan(project.Id, cutoffUtc).ConfigureAwait(false);
            }
            else
            {
                Log.LogWarning($"rejected request to delete content history older than {days} for user {User.Identity.Name} because this is only allowed if users can edit both pages and posts.");
            }



            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <IActionResult> DeleteHistory(Guid id, string returnUrl = null)
        {
            var project = await ProjectService.GetCurrentProjectSettings();

            if (project == null)
            {
                Log.LogError("project settings not found");
                return(RedirectToAction("Index"));
            }

            var hx = await HistoryQueries.Fetch(project.Id, id).ConfigureAwait(false);

            if (hx != null)
            {
                switch (hx.ContentSource)
                {
                case ContentSource.Blog:
                    var canEditPosts = await User.CanEditPages(project.Id, AuthorizationService);

                    if (canEditPosts)
                    {
                        await HistoryCommands.Delete(project.Id, id).ConfigureAwait(false);
                    }

                    break;

                case ContentSource.Page:
                    var canEditPages = await User.CanEditPages(project.Id, AuthorizationService);

                    if (canEditPages)
                    {
                        await HistoryCommands.Delete(project.Id, id).ConfigureAwait(false);
                    }

                    break;
                }
            }

            if (!string.IsNullOrEmpty(returnUrl))
            {
                return(LocalRedirect(returnUrl));
            }

            return(RedirectToAction("Index"));
        }