Ejemplo n.º 1
0
        private void EnterEditMode()
        {
            var wpm = this.WPManager;

            if (wpm == null)
            {
                return;
            }

            var mode = wpm.SupportedDisplayModes[DisplayModeEdit];

            if (mode == null)
            {
                return;
            }

            wpm.DisplayMode = mode;

            if (SavingAction.HasCheckOut(Portal.Page.Current))
            {
                Portal.Page.Current.CheckOut();
            }

            ResetVersioningButtons();
        }
Ejemplo n.º 2
0
        public void SavingAction_Off_None_DifferentUsers_CheckOut1()
        {
            var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None);

            InitializeAsExisting(gc, 100, 111, "V2.0.L", true, RepositoryConfiguration.VisitorUserId, DateTime.Today.AddDays(-1));

            Assert.IsFalse(SavingAction.HasCheckOut(gc), "Node is locked by another user but has checkout!");
            Assert.IsFalse(SavingAction.HasCheckIn(gc), "Node is locked by another user but has checkin!");
            Assert.IsFalse(SavingAction.HasUndoCheckOut(gc), "Node is locked by another user but has undo checkout!");
        }
Ejemplo n.º 3
0
        public void SavingAction_Off_None_DifferentUsers_CheckOut1()
        {
            Test(true, () =>
            {
                var gc = CreateNodeInMemory(ApprovingType.False, VersioningType.None);

                InitializeAsExisting(gc, 1, 111, "V2.0.L", true, Identifiers.VisitorUserId, DateTime.Today.AddDays(-1));

                Assert.IsFalse(SavingAction.HasCheckOut(gc));
                Assert.IsFalse(SavingAction.HasCheckIn(gc));
                Assert.IsFalse(SavingAction.HasUndoCheckOut(gc));
            });
        }
Ejemplo n.º 4
0
        private static bool IsInvalidVersioningAction(Content context, string actionName)
        {
            if (string.IsNullOrEmpty(actionName) || context == null)
            {
                return(false);
            }

            actionName = actionName.ToLower();

            var generic = context.ContentHandler as GenericContent;

            if (generic == null)
            {
                return(false);
            }

            switch (actionName)
            {
            case "checkin":
                return(!SavingAction.HasCheckIn(generic));

            case "checkout":
                return((generic.VersioningMode <= VersioningType.None && !(generic is IFile || generic.NodeType.IsInstaceOfOrDerivedFrom("Page"))) || !SavingAction.HasCheckOut(generic));

            case "undocheckout":
                return(!SavingAction.HasUndoCheckOut(generic));

            case "forceundocheckout":
                return(!SavingAction.HasForceUndoCheckOutRight(generic));

            case "publish":
                return(generic.VersioningMode <= VersioningType.None || !SavingAction.HasPublish(generic));

            case "approve":
            case "reject":
                return(!generic.Approvable);

            default:
                return(false);
            }
        }
Ejemplo n.º 5
0
        private void InitializeControl()
        {
            Control c;
            var     app       = PortalContext.Current.GetApplicationContext();
            var     isExplore = PortalContext.Current.ActionName != null &&
                                PortalContext.Current.ActionName.ToLower() == "explore";

            var browseLink = _prcControl.FindControlRecursive("BrowseLink") as System.Web.UI.WebControls.HyperLink;

            if (browseLink != null)
            {
                if (PortalContext.Current.ActionName == null || PortalContext.Current.ActionName.ToLower() == "browse")
                {
                    browseLink.Visible = false;
                }
            }

            var browseAppLink = _prcControl.FindControlRecursive("BrowseApp") as ActionLinkButton;

            if (browseAppLink != null)
            {
                if (app != null)
                {
                    browseAppLink.Visible = false;
                }
                else if (isExplore)
                {
                    browseAppLink.ParameterString = browseAppLink.ParameterString.Replace("context={CurrentContextPath}", string.Empty);
                }
            }

            var wbpm = this.WPManager;

            if (wbpm != null)
            {
                if (wbpm.DisplayMode.Name == "Edit")
                {
                    SetControlVisibility("Rename", true);
                    SetControlVisibility("CopyTo", true);
                    SetControlVisibility("MoveTo", true);
                    SetControlVisibility("DeletePage", true);

                    var hyperLink = _prcControl.FindControlRecursive("Browse") as System.Web.UI.WebControls.HyperLink;
                    if (hyperLink != null)
                    {
                        hyperLink.Visible = false;
                    }

                    SetControlVisibility("Versions", false);
                    SetControlVisibility("EditPage", false);
                    SetControlVisibility("SetPermissions", false);
                }
                else if (wbpm.DisplayMode.Name == "Browse")
                {
                    SetControlVisibility("Versions", true);
                    SetControlVisibility("EditPage", true);
                    SetControlVisibility("SetPermissions", true);
                }

                var displayModeLink = _prcControl.FindControlRecursive("WebPartDisplayMode") as WebControl;
                if (displayModeLink != null)
                {
                    if (wbpm.DisplayMode == WebPartManager.BrowseDisplayMode)
                    {
                        var editModeVisible = IsApplicationMode &&
                                              (SavingAction.HasCheckOut(Portal.Page.Current) ||
                                               SavingAction.HasCheckIn(Portal.Page.Current) ||
                                               SavingAction.HasForceUndoCheckOutRight(Portal.Page.Current));

                        if (!editModeVisible)
                        {
                            displayModeLink.Visible = false;
                        }
                        else
                        {
                            displayModeLink.ToolTip = SR.GetString(SR.PRC.EditMode);
                        }
                    }
                    else
                    {
                        displayModeLink.ToolTip = SR.GetString(SR.PRC.BrowseMode);
                    }
                }
            }

            c = _prcControl.FindControlRecursive("CustomActionsHeader");
            if (c != null)
            {
                var context = app ?? PortalContext.Current.ContextNode;
                c.Visible = context != null && ActionFramework.GetActions(ContentRepository.Content.Create(context), "Prc", null).Any();
            }

            // hide or show Explore links, based on whether we are in Content Explorer or not
            SetControlVisibility("ExploreRootLink", isExplore);
            SetControlVisibility("BrowseRoot", !isExplore);
            SetControlVisibility("ExploreAdvancedLink", !isExplore);

            // show or hide the correct 'Back to content' action
            var btcPanel = _prcControl.FindControlRecursive("BackToContentPanel");
            var boAction = _prcControl.FindControlRecursive("BrowseOriginalContent");

            var urlNodePath = HttpContext.Current.Request.Params[PortalContext.ContextNodeParamName];

            if (!string.IsNullOrEmpty(urlNodePath))
            {
                var backUrl = PortalContext.Current.BackUrl;
                if (!string.IsNullOrEmpty(backUrl))
                {
                    btcPanel.Visible = true;
                }
                else
                {
                    boAction.Visible = true;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Main entry event for all buttons under the Portal Remote Control.
        /// </summary>
        /// <param name="sender">The sender. IButtonControl must be implemented by this control.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void LinkButtonClick(object sender, EventArgs e)
        {
            var b = sender as IButtonControl;

            if (b == null)
            {
                return;
            }
            var wpm = WebPartManager.GetCurrentWebPartManager(this.Page);

            var command = b.CommandName.ToLower();

            switch (command)
            {
            case "entereditmode":
                if (wpm == null)
                {
                    return;
                }
                var mode = wpm.SupportedDisplayModes["Edit"];
                if (mode == null)
                {
                    break;
                }

                wpm.DisplayMode = mode;
                var eButton = prcTemplateControl.FindControlRecursive("EditModeButton") as LinkButton;
                if (eButton != null)
                {
                    eButton.Visible = false;
                }

                if (SavingAction.HasCheckOut(PortalContext.Current.Page))
                {
                    PortalContext.Current.Page.CheckOut();
                }

                BindEvent("BrowseModeButton", true);
                ResetVersioningButtons();

                break;

            case "enterbrowsemode":
                if (wpm == null)
                {
                    return;
                }
                var mode2 = wpm.SupportedDisplayModes["Browse"];
                if (mode2 == null)
                {
                    break;
                }
                wpm.DisplayMode = mode2;
                var bmButton = prcTemplateControl.FindControlRecursive("BrowseModeButton") as LinkButton;
                if (bmButton != null)
                {
                    bmButton.Visible = false;
                }

                BindEvent("EditModeButton", true);
                ResetVersioningButtons();

                break;

            case "addportlet":

                var addPortletTextBox = prcTemplateControl.FindControlRecursive("AddPortletButtonTextBox") as TextBox;
                if (addPortletTextBox == null)
                {
                    break;
                }

                var addPortletInfo = addPortletTextBox.Text;
                // FIX: Bug 5539
                if (String.IsNullOrEmpty(addPortletInfo))
                {
                    var eventArgs = HttpContext.Current.Request.Form["__EVENTARGUMENT"];
                    addPortletInfo = eventArgs;
                }
                var portletParams = addPortletInfo.Split(';');
                System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(addPortletInfo), "I've must been losing my mind: AddPortletButtonTextBox has no valid value. (missing portlet info) ");
                this.AddPortlet(Int32.Parse(portletParams[0]), portletParams[1]);
                break;

            default:
                break;
            }
            InitializeControl();
        }
Ejemplo n.º 7
0
        private void InitializeControl()
        {
            Control c;

            var browseLink = prcTemplateControl.FindControlRecursive("BrowseLink") as System.Web.UI.WebControls.HyperLink;

            if (browseLink != null)
            {
                if (PortalContext.Current.ActionName == null || PortalContext.Current.ActionName.ToLower() == "browse")
                {
                    browseLink.Visible = false;
                }
            }

            var browseAppLink = prcTemplateControl.FindControlRecursive("BrowseApp") as ActionLinkButton;

            if (browseAppLink != null)
            {
                var app = PortalContext.Current.GetApplicationContext();
                if (app != null)
                {
                    browseAppLink.Visible = false;
                }
                else if (PortalContext.Current.ActionName != null && PortalContext.Current.ActionName.ToLower() == "explore")
                {
                    browseAppLink.ParameterString = browseAppLink.ParameterString.Replace("context={CurrentContextPath}", string.Empty);
                }
            }

            var wbpm = WebPartManager.GetCurrentWebPartManager(this.Page);

            if (wbpm != null)
            {
                if (wbpm.DisplayMode.Name == "Edit")
                {
                    c         = prcTemplateControl.FindControlRecursive("Rename");
                    c.Visible = true;
                    c         = prcTemplateControl.FindControlRecursive("CopyTo");
                    c.Visible = true;
                    c         = prcTemplateControl.FindControlRecursive("MoveTo");
                    c.Visible = true;
                    c         = prcTemplateControl.FindControlRecursive("DeletePage");
                    c.Visible = true;

                    var hyperLink =
                        prcTemplateControl.FindControlRecursive("Browse") as System.Web.UI.WebControls.HyperLink;
                    if (hyperLink != null)
                    {
                        hyperLink.Visible = false;
                    }

                    c         = prcTemplateControl.FindControlRecursive("Versions");
                    c.Visible = false;
                    c         = prcTemplateControl.FindControlRecursive("EditPage");
                    c.Visible = false;
                    c         = prcTemplateControl.FindControlRecursive("SetPermissions");
                    c.Visible = false;
                }
                else if (wbpm.DisplayMode.Name == "Browse")
                {
                    c         = prcTemplateControl.FindControlRecursive("Versions");
                    c.Visible = true;
                    c         = prcTemplateControl.FindControlRecursive("EditPage");
                    c.Visible = true;
                    c         = prcTemplateControl.FindControlRecursive("SetPermissions");
                    c.Visible = true;
                }

                BindEvent("AddPortletButton", true);
                if (wbpm.DisplayMode == WebPartManager.BrowseDisplayMode)
                {
                    BindEvent("BrowseModeButton", false);
                    BindEvent("EditModeButton", IsApplicationMode &&
                              (SavingAction.HasCheckOut(PortalContext.Current.Page) ||
                               SavingAction.HasCheckIn(PortalContext.Current.Page) ||
                               SavingAction.HasForceUndoCheckOutRight(PortalContext.Current.Page)));
                }

                if (wbpm.DisplayMode == WebPartManager.EditDisplayMode)
                {
                    BindEvent("BrowseModeButton", true);
                    BindEvent("EditModeButton", false);
                }
            }
        }
Ejemplo n.º 8
0
        protected virtual void SetButtonVisibility()
        {
            HideAllButtons();

            if (this.ContentView == null)
            {
                return;
            }

            SetButtonVisible(this.CancelButton, true);

            var contentType = this.ContentView.ContentHandler as ContentType;

            if (contentType != null)
            {
                if (SecurityHandler.HasPermission(contentType, PermissionType.Save))
                {
                    SetButtonVisible(this.CheckoutSaveCheckinButton, true);
                }

                return;
            }

            var genericContent = this.ContentView.ContentHandler as GenericContent;

            if (genericContent == null)
            {
                return;
            }

            switch (genericContent.Version.Status)
            {
            case VersionStatus.Approved:
            case VersionStatus.Rejected:
                if (SavingAction.HasCheckOut(genericContent))
                {
                    SetButtonVisible(this.CheckoutSaveButton, true);
                }
                if (SavingAction.HasSave(genericContent))
                {
                    SetButtonVisible(this.CheckoutSaveCheckinButton, true);
                }
                break;

            case VersionStatus.Locked:
                if (SavingAction.HasSave(genericContent))
                {
                    SetButtonVisible(this.SaveButton, true);
                }
                if (SavingAction.HasCheckIn(genericContent))
                {
                    SetButtonVisible(this.SaveCheckinButton, true);
                }
                break;

            case VersionStatus.Draft:
                if (genericContent.Id == 0)
                {
                    if (SavingAction.HasSave(genericContent))
                    {
                        SetButtonVisible(this.CheckoutSaveCheckinButton, true);
                    }
                }
                else
                {
                    if (SavingAction.HasCheckOut(genericContent))
                    {
                        SetButtonVisible(this.CheckoutSaveButton, true);
                    }
                    if (SavingAction.HasSave(genericContent))
                    {
                        SetButtonVisible(this.CheckoutSaveCheckinButton, true);
                    }
                }

                if (SavingAction.HasPublish(genericContent))
                {
                    SetButtonVisible(this.PublishButton, true);
                }

                break;

            case VersionStatus.Pending:
                if (genericContent.Id == 0)
                {
                    if (SavingAction.HasSave(genericContent))
                    {
                        SetButtonVisible(this.SaveButton, true);
                    }
                }
                else
                {
                    if (SavingAction.HasCheckOut(genericContent))
                    {
                        SetButtonVisible(this.CheckoutSaveButton, true);
                    }
                }
                break;
            }
        }
Ejemplo n.º 9
0
        public override Control CreateActionButtons(DefaultButtonType button)
        {
            var _isContentType        = false;
            var currentButtonsControl = CurrentControl as DefaultButtons;

            if (currentButtonsControl == null)
            {
                return(null);
            }
            if (currentButtonsControl.CurrentGC == null)
            {
                //
                //  ContentType is always being handled specially.
                //
                var nodeTypeName = currentButtonsControl.CurrentNode.GetType().Name;

                //
                // treat contenttype behaviour 'til the final solution
                //
                if (nodeTypeName.Equals("RuntimeContentHandler"))
                {
                    _isContentType = true;
                }
                else
                {
                    if (!nodeTypeName.Equals(typeof(ContentType).Name))
                    {
                        return(null);
                    }
                    _isContentType = true;
                }
            }

            var             currentGenericContent = currentButtonsControl.CurrentGC;
            SecurityHandler security = null;

            if (!_isContentType)
            {
                security = currentButtonsControl.NewContent ? currentGenericContent.Parent.Security : currentGenericContent.Security;
            }

            switch (button)
            {
            case DefaultButtonType.CheckIn:
                if (currentButtonsControl.VisibleCheckIn && !_isContentType && SavingAction.HasCheckIn(currentGenericContent))
                {
                    return(new Button
                    {
                        ID = "btnCheckIn",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "CheckIn") as
                             string),
                        CommandName = "checkin",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.CheckOut:
                var isInWorkspaceAction = PortalContext.Current.ContextWorkspace != null;

                if (currentButtonsControl.VisibleCheckOut && !_isContentType && SavingAction.HasCheckOut(currentGenericContent))
                {
                    //
                    //  TODO: checkout button must be displayed in the next release
                    //  In Beta 5 this function is not allowed. Check the Task 3978.
                    //
                    if (isInWorkspaceAction)
                    {
                        return(null);
                    }

                    return(new Button
                    {
                        ID = "btnCheckOut",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "CheckOut") as
                             string),
                        CommandName = "checkout",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.UndoCheckOut:
                if (currentButtonsControl.VisibleUndoCheckOut && !_isContentType && SavingAction.HasUndoCheckOut(currentGenericContent))
                {
                    return(new Button
                    {
                        ID = "btnUndoCheckOut",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "UndoCheckOut")
                             as string),
                        CommandName = "undocheckout",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.Save:
                var saveButton = new Button
                {
                    ID   = "btnSave",
                    Text =
                        (HttpContext.GetGlobalResourceObject("Portal", "Save") as string),
                    CommandName     = "save",
                    Enabled         = true,
                    EnableViewState = false
                };

                if (currentButtonsControl.VisibleSave && !_isContentType && SavingAction.HasSave(currentGenericContent))
                {
                    if (currentButtonsControl.NewContent
                                ? security.HasPermission(PermissionType.AddNew)
                                : security.HasPermission(PermissionType.Save))
                    {
                        return(saveButton);
                    }
                }

                if (_isContentType)
                {
                    return(saveButton);
                }

                break;

            case DefaultButtonType.Publish:
                if (currentButtonsControl.VisiblePublish && !_isContentType && SavingAction.HasPublish(currentGenericContent))
                {
                    return(new Button
                    {
                        ID = "btnPublish",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "Publish") as
                             string),
                        CommandName = "publish",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.Approve:
                if (currentButtonsControl.VisibleApprove && !_isContentType && SavingAction.HasApprove(currentGenericContent))
                {
                    return(new Button
                    {
                        ID = "btnApprove",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "Approve") as
                             string),
                        CommandName = "approve",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.Reject:
                if (currentButtonsControl.VisibleReject && !_isContentType && SavingAction.HasReject(currentGenericContent))
                {
                    return(new Button
                    {
                        ID = "btnReject",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "Reject") as string),
                        CommandName = "reject",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.Cancel:
                if (currentButtonsControl.VisibleCancel)
                {
                    return(new Button
                    {
                        ID = "btnCancel",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal", "Cancel") as string),
                        CommandName = "cancel",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.ForceUndoCheckOut:
                if (currentButtonsControl.VisibleForceUndoCheckOut && !_isContentType && SavingAction.HasForceUndoCheckOutRight(currentGenericContent))
                {
                    return(new Button
                    {
                        ID = "btnForceUndoCheckOut",
                        Text =
                            (HttpContext.GetGlobalResourceObject("Portal",
                                                                 "ForceUndoCheckOut")
                             as string),
                        CommandName = "forceundocheckout",
                        Enabled = true,
                        EnableViewState = false
                    });
                }
                break;

            case DefaultButtonType.None:
            case DefaultButtonType.Custom:
                break;

            default:
                throw new ArgumentOutOfRangeException("button");
            }
            return(null);
        }