Beispiel #1
0
        private void btnDelete_Click(Object sender, ImageClickEventArgs e)
        {
            if (lbPages.SelectedIndex > -1)
            {
                ContentMetaRespository metaRepository = new ContentMetaRespository();

                foreach (mojoSiteMapNode page in sitePages)
                {
                    if ((page.PageId.ToString() == lbPages.SelectedValue) && ((canEditAnything) || (WebUser.IsInRoles(page.EditRoles))))
                    {
                        if (WebConfigSettings.LogIpAddressForContentDeletions)
                        {
                            log.Info("user deleted page " + page.Url + " from ip address " + SiteUtils.GetIP4Address());
                        }

                        PageSettings pageSettings = new PageSettings(siteSettings.SiteId, page.PageId);
                        metaRepository.DeleteByContent(page.PageGuid);
                        Module.DeletePageModules(page.PageId);
                        PageSettings.DeletePage(page.PageId);
                        FriendlyUrl.DeleteByPageGuid(page.PageGuid);

                        mojoPortal.SearchIndex.IndexHelper.ClearPageIndexAsync(pageSettings);
                    }
                }

                CacheHelper.ResetSiteMapCache();

                WebUtils.SetupRedirect(this, Request.RawUrl);
            }
            else
            {
                // no page selected
                litWarning.Text = Resource.PagesNoSelectionWarning;
            }
        }
Beispiel #2
0
        private void HandleDelete()
        {
            PageActionResult result = new PageActionResult();

            if (!context.Request.IsAuthenticated)
            {
                result.Success = false;
                result.Message = PageManagerResources.InvalidRequest;
                RenderPageActionResult(result);
                log.Info("rejected page delete request for anonymous user");
                return;
            }

            int delNodeId = -1;

            if (context.Request.Form["delNode"] != null)
            {
                int.TryParse(context.Request.Form["delNode"], out delNodeId);
            }

            if (delNodeId == -1)
            {
                result.Success = false;
                result.Message = PageManagerResources.InvalidRequest;
                RenderPageActionResult(result);
                log.Info("no pageid provided for delete command");
                return;
            }

            //log.Info("node to delete " + delNodeId);

            LoadSiteMapSettings();

            mojoSiteMapNode deleteNode = SiteUtils.GetSiteMapNodeForPage(rootNode, delNodeId);

            if (deleteNode == null)
            {
                result.Success = false;
                result.Message = PageManagerResources.InvalidRequest;
                RenderPageActionResult(result);
                log.Info("node not found for delete command");
                return;
            }

            if (!WebUser.IsInRoles(deleteNode.EditRoles))
            {
                result.Success = false;
                result.Message = string.Format(
                    CultureInfo.InvariantCulture,
                    PageManagerResources.DeletePageNotAllowedFormat,
                    deleteNode.Title);

                RenderPageActionResult(result);

                if (logAllActions)
                {
                    log.Info(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            PageManagerResources.DeletePageDeniedLogFormat,
                            currentUserName,
                            deleteNode.Title, deleteNode.PageId
                            )
                        );
                }

                return;
            }


            if (deleteNode.ChildNodes.Count > 0)
            {
                if (!WebUser.IsInRoles(siteSettings.RolesThatCanCreateRootPages))
                {
                    // child pages would be orphaned to becomne root level
                    // but user does not have permission to create root pages

                    result.Success = false;
                    result.Message = PageManagerResources.CantOrphanPagesWarning;
                    RenderPageActionResult(result);
                    log.Info("delete would orphan child pages to root but user does not have permission");
                    return;
                }
            }

            ContentMetaRespository metaRepository = new ContentMetaRespository();

            PageSettings pageSettings = new PageSettings(siteSettings.SiteId, deleteNode.PageId);

            metaRepository.DeleteByContent(deleteNode.PageGuid);
            Module.DeletePageModules(deleteNode.PageId);
            PageSettings.DeletePage(deleteNode.PageId);
            FriendlyUrl.DeleteByPageGuid(deleteNode.PageGuid);

            mojoPortal.SearchIndex.IndexHelper.ClearPageIndexAsync(pageSettings);

            CacheHelper.ResetSiteMapCache();

            result.Success = true;
            result.Message = "Success";
            RenderPageActionResult(result);

            if (logAllActions)
            {
                log.Info(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        PageManagerResources.DeletePageSuccessLogFormat,
                        currentUserName,
                        deleteNode.Title, deleteNode.PageId
                        )
                    );
            }
        }