CheckActionForNamespace() public static method

Checks whether an action is allowed for a namespace.
public static CheckActionForNamespace ( NamespaceInfo nspace, string action, string currentUser, string groups ) : bool
nspace NamespaceInfo The current namespace (null for the root).
action string The action the user is attempting to perform.
currentUser string The current user.
groups string The groups the user is member of.
return bool
コード例 #1
0
        /// <summary>
        /// Detects the permissions for the current user.
        /// </summary>
        /// <remarks><b>currentPage</b> should be set before calling this method.</remarks>
        private void DetectPermissions()
        {
            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            if (currentPage != null)
            {
                Pages.CanEditPage(currentPage.Provider.CurrentWiki, currentPage.FullName, currentUser, currentGroups, out canEdit, out canEditWithApproval);
                canCreateNewPages      = false;            // Least privilege
                canCreateNewCategories = authChecker.CheckActionForNamespace(Pages.FindNamespace(currentWiki, NameTools.GetNamespace(currentPage.FullName)),
                                                                             Actions.ForNamespaces.ManageCategories, currentUser, currentGroups);
                canManagePageCategories = authChecker.CheckActionForPage(currentPage.FullName, Actions.ForPages.ManageCategories, currentUser, currentGroups);
                canDownloadAttachments  = authChecker.CheckActionForPage(currentPage.FullName, Actions.ForPages.DownloadAttachments, currentUser, currentGroups);
            }
            else
            {
                NamespaceInfo ns = DetectNamespaceInfo();
                canCreateNewPages       = authChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.CreatePages, currentUser, currentGroups);
                canCreateNewCategories  = authChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.ManageCategories, currentUser, currentGroups);
                canManagePageCategories = canCreateNewCategories;
                canDownloadAttachments  = authChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.DownloadAttachments, currentUser, currentGroups);
            }
        }
コード例 #2
0
        /// <summary>
        /// Activates the page editor.
        /// </summary>
        private void ActivatePageEditor()
        {
            lblCurrentPage.Text = txtCurrentPage.Value;
            txtNewName.Text     = NameTools.GetLocalName(txtCurrentPage.Value);

            // Enable/disable page sections
            PageContent   page        = Pages.FindPage(currentWiki, txtCurrentPage.Value);
            NamespaceInfo nspace      = Pages.FindNamespace(currentWiki, NameTools.GetNamespace(page.FullName));
            string        currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            bool canApproveReject    = AdminMaster.CanApproveDraft(page.Provider.CurrentWiki, page.FullName, currentUser, currentGroups);
            bool canDeletePages      = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.DeletePages, currentUser, currentGroups);
            bool canManageAllPages   = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
            bool canManagePage       = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManagePage, currentUser, currentGroups);
            bool canManageDiscussion = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManageDiscussion, currentUser, currentGroups);
            bool namespaceAvailable  = PopulateTargetNamespaces(page);

            // Approve/reject
            // Rename
            // Migrate
            // Rollback
            // Delete Backups
            // Clear discussion
            // Delete

            pnlApproveRevision.Enabled = canApproveReject;
            pnlRename.Enabled          = canDeletePages;
            pnlMigrate.Enabled         = canManageAllPages && namespaceAvailable;
            pnlRollback.Enabled        = canManagePage;
            pnlDeleteBackups.Enabled   = canManagePage;
            pnlClearDiscussion.Enabled = canManageDiscussion;
            pnlDelete.Enabled          = canDeletePages;

            // Disable rename, migrate, delete for default page
            NamespaceInfo currentNamespace   = Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue);
            string        currentDefaultPage = currentNamespace != null ? currentNamespace.DefaultPageFullName : Settings.GetDefaultPage(currentWiki);

            if (txtCurrentPage.Value == currentDefaultPage)
            {
                btnRename.Enabled     = false;
                btnMigrate.Enabled    = false;
                btnDeletePage.Enabled = false;
            }

            LoadDraft(txtCurrentPage.Value);

            LoadBackups(txtCurrentPage.Value);

            btnRollback.Enabled      = lstRevision.Items.Count > 0;
            btnDeleteBackups.Enabled = lstBackup.Items.Count > 0;

            pnlList.Visible     = false;
            pnlEditPage.Visible = true;

            ClearResultLabels();
        }
コード例 #3
0
ファイル: Profile.aspx.cs プロジェクト: ahmedfe/screwturn
        /// <summary>
        /// Loads the page/discussion change notification data.
        /// </summary>
        private void LoadNotificationsStatus()
        {
            lstPageChanges.Items.Clear();
            lstDiscussionMessages.Items.Clear();

            bool pageChanges, discussionMessages;

            Users.GetEmailNotification(currentUser, null as ScrewTurn.Wiki.PluginFramework.NamespaceInfo,
                                       out pageChanges, out discussionMessages);

            lstPageChanges.Items.Add(new ListItem("&lt;root&gt;", ""));
            lstPageChanges.Items[0].Selected = pageChanges;
            lstDiscussionMessages.Items.Add(new ListItem("&lt;root&gt;", ""));
            lstDiscussionMessages.Items[0].Selected = discussionMessages;

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            foreach (ScrewTurn.Wiki.PluginFramework.NamespaceInfo ns in Pages.GetNamespaces(currentWiki))
            {
                Users.GetEmailNotification(currentUser, ns, out pageChanges, out discussionMessages);

                if (authChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.ReadPages, currentUser.Username, currentGroups))
                {
                    lstPageChanges.Items.Add(new ListItem(ns.Name, ns.Name));
                    lstPageChanges.Items[lstPageChanges.Items.Count - 1].Selected = pageChanges;
                }

                if (authChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.ReadDiscussion, currentUser.Username, currentGroups))
                {
                    lstDiscussionMessages.Items.Add(new ListItem(ns.Name, ns.Name));
                    lstDiscussionMessages.Items[lstPageChanges.Items.Count - 1].Selected = discussionMessages;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Populates the namespaces list for migration.
        /// </summary>
        /// <param name="page">The selected page.</param>
        /// <returns><c>true</c> if there is at least one valid target namespace, <c>false</c> otherwise.</returns>
        private bool PopulateTargetNamespaces(PageInfo page)
        {
            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames();

            lstTargetNamespace.Items.Clear();

            NamespaceInfo pageNamespace = Pages.FindNamespace(NameTools.GetNamespace(page.FullName));

            if (pageNamespace != null)
            {
                // Try adding Root as target namespace
                bool canManagePages = AuthChecker.CheckActionForNamespace(null, Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
                if (canManagePages)
                {
                    lstTargetNamespace.Items.Add(new ListItem("<root>", ""));
                }
            }

            // Try adding all other namespaces
            foreach (NamespaceInfo nspace in Pages.GetNamespaces().FindAll(n => n.Provider == page.Provider))
            {
                if (pageNamespace == null || (pageNamespace != null && nspace.Name != pageNamespace.Name))
                {
                    bool canManagePages = AuthChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
                    if (canManagePages)
                    {
                        lstTargetNamespace.Items.Add(new ListItem(nspace.Name, nspace.Name));
                    }
                }
            }

            return(lstTargetNamespace.Items.Count > 0);
        }
コード例 #5
0
        protected void btnDeletePage_Click(object sender, EventArgs e)
        {
            PageInfo page = Pages.FindPage(txtCurrentPage.Value);

            if (!AuthChecker.CheckActionForNamespace(Pages.FindNamespace(NameTools.GetNamespace(page.FullName)), Actions.ForNamespaces.DeletePages,
                                                     SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()))
            {
                return;
            }

            Log.LogEntry("Page deletion requested for " + txtCurrentPage.Value, EntryType.General, Log.SystemUsername);

            bool done = Pages.DeletePage(page);

            if (done)
            {
                ResetPageList();

                RefreshList();
                lblDeleteResult.CssClass = "resultok";
                lblDeleteResult.Text     = Properties.Messages.PageDeleted;
                ReturnToList();
            }
            else
            {
                lblDeleteResult.CssClass = "resulterror";
                lblDeleteResult.Text     = Properties.Messages.CouldNotDeletePage;
            }
        }
コード例 #6
0
        /// <summary>
        /// Returns a value indicating whether the current user can manage categories in the selected namespace.
        /// </summary>
        /// <returns><c>true</c> if the user can manage categories, <c>false</c> otherwise.</returns>
        private bool CanManageCategoriesInCurrentNamespace()
        {
            NamespaceInfo nspace = Pages.FindNamespace(lstNamespace.SelectedValue);
            bool          canManageCategories = AuthChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManageCategories,
                                                                                    SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());

            return(canManageCategories);
        }
コード例 #7
0
        protected void rptPages_DataBinding(object sender, EventArgs e)
        {
            NamespaceInfo nspace = Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue);

            if (currentPages == null)
            {
                currentPages = GetPages(nspace);
            }

            List <PageRow> result = new List <PageRow>(PageSize);

            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker       = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));
            bool        canSetPermissions = AdminMaster.CanManagePermissions(currentUser, currentGroups);
            bool        canDeletePages    = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.DeletePages, currentUser, currentGroups);

            var orphanPages = new List <string>(Pages.GetOrphanedPages(currentWiki, nspace));

            for (int i = rangeBegin; i <= rangeEnd; i++)
            {
                PageContent page = currentPages[i];

                // The page can be selected if the user can either manage or delete the page or manage the discussion
                // Repeat checks for enabling/disabling sections when a page is selected
                bool canEdit             = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ModifyPage, currentUser, currentGroups);
                bool canManagePage       = false;
                bool canManageDiscussion = false;
                if (!canDeletePages)
                {
                    canManagePage = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManagePage, currentUser, currentGroups);
                }
                if (!canDeletePages && !canManagePage)
                {
                    canManageDiscussion = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManageDiscussion, currentUser, currentGroups);
                }
                bool canSelect = canManagePage | canDeletePages | canManageDiscussion;

                PageContent firstContent = null;
                List <int>  baks         = Pages.GetBackups(page);
                if (baks.Count == 0)
                {
                    firstContent = page;
                }
                else
                {
                    firstContent = Pages.GetBackupContent(page, baks[0]);
                }

                result.Add(new PageRow(page, firstContent,
                                       Pages.GetMessageCount(page), baks.Count, orphanPages.Contains(page.FullName),
                                       canEdit, canSelect, canSetPermissions, txtCurrentPage.Value == page.FullName));
            }

            rptPages.DataSource = result;
        }
コード例 #8
0
        protected void rptPages_DataBinding(object sender, EventArgs e)
        {
            if (currentPages == null)
            {
                currentPages = GetPages();
            }
            NamespaceInfo nspace = DetectNamespaceInfo();

            var result = new List <PageRow>(PageSize);

            var currentUser   = SessionFacade.GetCurrentUsername();
            var currentGroups = SessionFacade.GetCurrentGroupNames();

            var canSetPermissions = AdminMaster.CanManagePermissions(currentUser, currentGroups);
            var canDeletePages    = AuthChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.DeletePages, currentUser, currentGroups);

            var orphanPages = Pages.GetOrphanedPages(currentPages);

            for (var i = rangeBegin; i <= rangeEnd; i++)
            {
                PageInfo page = currentPages[i];

                PageContent currentContent = Content.GetPageContent(page, false);

                // The page can be selected if the user can either manage or delete the page or manage the discussion
                // Repeat checks for enabling/disabling sections when a page is selected
                var canEdit             = AuthChecker.CheckActionForPage(page, Actions.ForPages.ModifyPage, currentUser, currentGroups);
                var canManagePage       = false;
                var canManageDiscussion = false;
                if (!canDeletePages)
                {
                    canManagePage = AuthChecker.CheckActionForPage(page, Actions.ForPages.ManagePage, currentUser, currentGroups);
                }
                if (!canDeletePages && !canManagePage)
                {
                    canManageDiscussion = AuthChecker.CheckActionForPage(page, Actions.ForPages.ManageDiscussion, currentUser, currentGroups);
                }
                var canSelect = canManagePage | canDeletePages | canManageDiscussion;

                PageContent firstContent = null;
                List <int>  baks         = Pages.GetBackups(page);
                if (baks.Count == 0)
                {
                    firstContent = currentContent;
                }
                else
                {
                    firstContent = Pages.GetBackupContent(page, baks[0]);
                }

                result.Add(new PageRow(page, currentContent, firstContent,
                                       Pages.GetMessageCount(page), baks.Count, orphanPages.Contains(page.FullName),
                                       canEdit, canSelect, canSetPermissions, txtCurrentPage.Value == page.FullName));
            }

            rptPages.DataSource = result;
        }
コード例 #9
0
        /// <summary>
        /// Determines whether a user can manage pages in at least one namespace.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="groups">The groups.</param>
        /// <returns><c>true</c> if the the user can manage pages in at least one namespace, <c>false</c> otherwise.</returns>
        public static bool CanManagePages(string username, string[] groups)
        {
            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(Tools.DetectCurrentWiki()));

            if (authChecker.CheckActionForNamespace(null, Actions.ForNamespaces.ManagePages, username, groups))
            {
                return(true);
            }

            foreach (NamespaceInfo ns in Pages.GetNamespaces(Tools.DetectCurrentWiki()))
            {
                if (authChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.ManagePages, username, groups))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #10
0
        /// <summary>
        /// Returns a value indicating whether the current user can manage categories in the selected namespace.
        /// </summary>
        /// <returns><c>true</c> if the user can manage categories, <c>false</c> otherwise.</returns>
        private bool CanManageCategoriesInCurrentNamespace()
        {
            string        currentWiki         = DetectWiki();
            NamespaceInfo nspace              = Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue);
            AuthChecker   authChecker         = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));
            bool          canManageCategories = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManageCategories,
                                                                                    SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki));

            return(canManageCategories);
        }
コード例 #11
0
        /// <summary>
        /// Detects the permissions for the current user.
        /// </summary>
        /// <remarks><b>currentPage</b> should be set before calling this method.</remarks>
        private void DetectPermissions()
        {
            // Sueetie Modified - Bug fix for session expiring and user not known
            if (!Page.User.Identity.IsAuthenticated)
            {
                Response.Redirect("accessdenied.aspx");
                return;
            }

            MembershipUser _user       = Membership.GetUser();
            var            currentUser = _user.UserName;
            UserInfo       user        = Users.FindUser(_user.UserName);

            if (user == null)
            {
                Response.Redirect("/members/message.aspx?msgid=2");
                return;
            }

            var currentGroups = SessionFacade.GetCurrentGroupNames();

            currentGroups = UserGroups(user);
            if (HttpContext.Current.Session == null)
            {
                if (user == null)
                {
                    user = Users.FindUser(_user.UserName);
                }
                SessionFacade.LoginKey        = ConfigurationManager.AppSettings["SUEETIE.WikiLoginKey"].ToString();
                SessionFacade.CurrentUsername = user.Username;
                Session["Logout"]             = null;
                Log.LogEntry("User " + user.Username + " auto-logged in through edit bug fix session restart", EntryType.General, "SUEETIE");
            }
            // END - Bug fix for session expiring and user not known

            if (currentPage != null)
            {
                Pages.CanEditPage(currentPage, currentUser, currentGroups, out canEdit, out canEditWithApproval);
                canCreateNewPages      = false; // Least privilege
                canCreateNewCategories = AuthChecker.CheckActionForNamespace(Pages.FindNamespace(NameTools.GetNamespace(currentPage.FullName)),
                                                                             Actions.ForNamespaces.ManageCategories, currentUser, currentGroups);
                canManagePageCategories = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ManageCategories, currentUser, currentGroups);
                canDownloadAttachments  = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.DownloadAttachments, currentUser, currentGroups);
            }
            else
            {
                NamespaceInfo ns = DetectNamespaceInfo();
                canCreateNewPages       = AuthChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.CreatePages, currentUser, currentGroups);
                canCreateNewCategories  = AuthChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.ManageCategories, currentUser, currentGroups);
                canManagePageCategories = canCreateNewCategories;
                canDownloadAttachments  = AuthChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.DownloadAttachments, currentUser, currentGroups);
            }
        }
コード例 #12
0
        /// <summary>
        /// Loads target namespaces for bulk migration.
        /// </summary>
        private void LoadTargetNamespaces()
        {
            // Load valid namespaces, filtering the current one
            lstBulkMigrateTargetNamespace.Items.Clear();

            bool   canManageAllPages = false;
            string currentUser       = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            if (!string.IsNullOrEmpty(lstNamespace.SelectedValue))
            {
                // Root namespace
                canManageAllPages = authChecker.CheckActionForNamespace(null,
                                                                        Actions.ForNamespaces.ManagePages, currentUser, currentGroups);

                if (canManageAllPages)
                {
                    lstBulkMigrateTargetNamespace.Items.Add(new ListItem("<root>", "."));
                }
            }

            foreach (NamespaceInfo ns in Pages.GetNamespaces(currentWiki).FindAll(n => n.Provider.GetType().FullName == providerSelector.SelectedProvider))
            {
                // All sub-namespaces
                if (ns.Name != lstNamespace.SelectedValue)
                {
                    canManageAllPages = authChecker.CheckActionForNamespace(ns,
                                                                            Actions.ForNamespaces.ManagePages, currentUser, currentGroups);

                    if (canManageAllPages)
                    {
                        lstBulkMigrateTargetNamespace.Items.Add(new ListItem(ns.Name, ns.Name));
                    }
                }
            }
        }
コード例 #13
0
        protected void btnMigrate_Click(object sender, EventArgs e)
        {
            lblMigrateResult.CssClass = "";
            lblMigrateResult.Text     = "";

            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            PageContent   page              = Pages.FindPage(currentWiki, txtCurrentPage.Value);
            NamespaceInfo targetNamespace   = Pages.FindNamespace(currentWiki, lstTargetNamespace.SelectedValue);
            AuthChecker   authChecker       = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));
            bool          canManageAllPages = authChecker.CheckActionForNamespace(Pages.FindNamespace(currentWiki, NameTools.GetNamespace(page.FullName)),
                                                                                  Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
            bool canManageAllPagesInTarget = authChecker.CheckActionForNamespace(targetNamespace,
                                                                                 Actions.ForNamespaces.ManagePages, currentUser, currentGroups);

            if (canManageAllPages && canManageAllPagesInTarget)
            {
                bool done = Pages.MigratePage(page, targetNamespace, chkCopyCategories.Checked);
                if (done)
                {
                    chkCopyCategories.Checked = false;

                    ResetPageList();

                    RefreshList();
                    lblRenameResult.CssClass = "resultok";
                    lblRenameResult.Text     = Properties.Messages.PageRenamed;
                    ReturnToList();
                }
                else
                {
                    lblMigrateResult.CssClass = "resulterror";
                    lblMigrateResult.Text     = Properties.Messages.CouldNotMigratePage;
                }
            }
        }
コード例 #14
0
ファイル: Admin.master.cs プロジェクト: sehurry/ScrewTurnWiki
        /// <summary>
        /// Determines whether a user can manage pages in at least one namespace.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="groups">The groups.</param>
        /// <returns><c>true</c> if the the user can manage pages in at least one namespace, <c>false</c> otherwise.</returns>
        public static bool CanManagePages(string username, string[] groups)
        {
            if (AuthChecker.CheckActionForNamespace(null, Actions.ForNamespaces.ManagePages, username, groups))
            {
                return(true);
            }

            foreach (NamespaceInfo ns in Pages.GetNamespaces())
            {
                if (AuthChecker.CheckActionForNamespace(ns, Actions.ForNamespaces.ManagePages, username, groups))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #15
0
        protected void lstNamespace_SelectedIndexChanged(object sender, EventArgs e)
        {
            currentPages           = GetPages();
            pageSelector.ItemCount = currentPages.Count;
            pageSelector.SelectPage(0);

            rptPages.DataBind();

            var currentUser   = SessionFacade.GetCurrentUsername();
            var currentGroups = SessionFacade.GetCurrentGroupNames();

            var canManageAllPages = AuthChecker.CheckActionForNamespace(
                Pages.FindNamespace(lstNamespace.SelectedValue),
                Actions.ForNamespaces.ManagePages, currentUser, currentGroups);

            btnBulkMigrate.Enabled = canManageAllPages;
        }
コード例 #16
0
        /// <summary>
        /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found.
        /// </summary>
        public static void VerifyReadPermissionsForCurrentNamespace()
        {
            var currentUsername = SessionFacade.GetCurrentUsername();
            var currentGroups   = SessionFacade.GetCurrentGroupNames();

            var canViewNamespace = AuthChecker.CheckActionForNamespace(
                Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages,
                currentUsername, currentGroups);

            if (!canViewNamespace)
            {
                if (SessionFacade.CurrentUsername == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                }
                else
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                }
            }
        }
コード例 #17
0
        protected void lstNamespace_SelectedIndexChanged(object sender, EventArgs e)
        {
            NamespaceInfo nspace = Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue);

            currentPages           = GetPages(nspace);
            pageSelector.ItemCount = currentPages.Count;
            pageSelector.SelectPage(0);

            rptPages.DataBind();

            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker       = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));
            bool        canManageAllPages = authChecker.CheckActionForNamespace(
                Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue),
                Actions.ForNamespaces.ManagePages, currentUser, currentGroups);

            btnBulkMigrate.Enabled = canManageAllPages;
        }
コード例 #18
0
        /// <summary>
        /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found.
        /// </summary>
        public static void VerifyReadPermissionsForCurrentNamespace()
        {
            string currentUsername = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames();

            bool canViewNamespace = AuthChecker.CheckActionForNamespace(
                Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages,
                currentUsername, currentGroups);

            if (!canViewNamespace)
            {
                if (SessionFacade.CurrentUsername == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(HttpContext.Current.Request.Url.ToString()));
                }
                else
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        public static void VerifyReadPermissionsForCurrentNamespace(string wiki)
        {
            string currentUsername = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(wiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(wiki));

            bool canViewNamespace = authChecker.CheckActionForNamespace(
                Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages,
                currentUsername, currentGroups);

            if (!canViewNamespace)
            {
                if (SessionFacade.CurrentUsername == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                }
                else
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                }
            }
        }
コード例 #20
0
        protected void btnMigrate_Click(object sender, EventArgs e)
        {
            lblMigrateResult.CssClass = "";
            lblMigrateResult.Text     = "";

            var currentUser   = SessionFacade.GetCurrentUsername();
            var currentGroups = SessionFacade.GetCurrentGroupNames();

            PageInfo      page              = Pages.FindPage(txtCurrentPage.Value);
            NamespaceInfo targetNamespace   = Pages.FindNamespace(lstTargetNamespace.SelectedValue);
            var           canManageAllPages = AuthChecker.CheckActionForNamespace(Pages.FindNamespace(NameTools.GetNamespace(page.FullName)),
                                                                                  Actions.ForNamespaces.ManagePages, currentUser, currentGroups);
            var canManageAllPagesInTarget = AuthChecker.CheckActionForNamespace(targetNamespace,
                                                                                Actions.ForNamespaces.ManagePages, currentUser, currentGroups);

            if (canManageAllPages && canManageAllPagesInTarget)
            {
                var done = Pages.MigratePage(page, targetNamespace, chkCopyCategories.Checked);
                if (done)
                {
                    chkCopyCategories.Checked = false;

                    ResetPageList();

                    RefreshList();
                    lblRenameResult.CssClass = "resultok";
                    lblRenameResult.Text     = Properties.Messages.PageRenamed;
                    ReturnToList();
                }
                else
                {
                    lblMigrateResult.CssClass = "resulterror";
                    lblMigrateResult.Text     = Properties.Messages.CouldNotMigratePage;
                }
            }
        }
コード例 #21
0
        protected void btnRename_Click(object sender, EventArgs e)
        {
            // Check name for change, validity and existence of another page with same name
            // Perform rename
            // Create shadow page, if needed

            PageInfo page = Pages.FindPage(txtCurrentPage.Value);

            if (!AuthChecker.CheckActionForNamespace(Pages.FindNamespace(NameTools.GetNamespace(page.FullName)), Actions.ForNamespaces.DeletePages,
                                                     SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()))
            {
                return;
            }

            txtNewName.Text = txtNewName.Text.Trim();

            string currentNamespace = NameTools.GetNamespace(txtCurrentPage.Value);
            string currentPage      = NameTools.GetLocalName(txtCurrentPage.Value);

            if (!Page.IsValid)
            {
                return;
            }

            if (txtNewName.Text.ToLowerInvariant() == currentPage.ToLowerInvariant())
            {
                return;
            }

            if (Pages.FindPage(NameTools.GetFullName(currentNamespace, txtNewName.Text)) != null)
            {
                lblRenameResult.CssClass = "resulterror";
                lblRenameResult.Text     = Properties.Messages.PageAlreadyExists;
                return;
            }

            Log.LogEntry("Page rename requested for " + txtCurrentPage.Value, EntryType.General, Log.SystemUsername);

            PageInfo    oldPage    = Pages.FindPage(txtCurrentPage.Value);
            PageContent oldContent = Content.GetPageContent(oldPage, false);

            bool done = Pages.RenamePage(oldPage, txtNewName.Text);

            if (done)
            {
                if (chkShadowPage.Checked)
                {
                    done = Pages.CreatePage(currentNamespace, currentPage);

                    if (done)
                    {
                        done = Pages.ModifyPage(Pages.FindPage(txtCurrentPage.Value),
                                                oldContent.Title, oldContent.User, oldContent.LastModified,
                                                oldContent.Comment, ">>> [" + txtNewName.Text + "]",
                                                new string[0], oldContent.Description, SaveMode.Normal);

                        if (done)
                        {
                            ResetPageList();

                            RefreshList();
                            lblRenameResult.CssClass = "resultok";
                            lblRenameResult.Text     = Properties.Messages.PageRenamed;
                            ReturnToList();
                        }
                        else
                        {
                            lblRenameResult.CssClass = "resulterror";
                            lblRenameResult.Text     = Properties.Messages.PageRenamedCouldNotSetShadowPageContent;
                        }
                    }
                    else
                    {
                        lblRenameResult.CssClass = "resulterror";
                        lblRenameResult.Text     = Properties.Messages.PageRenamedCouldNotCreateShadowPage;
                    }
                }
                else
                {
                    RefreshList();
                    lblRenameResult.CssClass = "resultok";
                    lblRenameResult.Text     = Properties.Messages.PageRenamed;
                    ReturnToList();
                }
            }
            else
            {
                lblRenameResult.CssClass = "resulterror";
                lblRenameResult.Text     = Properties.Messages.CouldNotRenamePage;
            }
        }