public void ActionFramework_GetActionsForAContentWithoutSufficientPermissionsATest() { IEnumerable <ActionBase> actions; //set required permission for the test - each requirement one descriptor var pdescriptors = new List <TestEquipment.PermissionDescriptor> { new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample", AffectedUser = User.Visitor, PType = PermissionType.Publish, NewValue = PermissionValue.Deny } }; //actions using (new TestEquipment.ContextSimulator(pdescriptors, User.Visitor)) { var siteSample1 = Content.Load("/Root/TestSiteForActionFramework/Sample"); actions = ActionFramework.GetActions(siteSample1, "sc6", ""); } //asserts var app4 = actions.Where(action => action.Name == "App4"); Assert.IsTrue(app4.Count() == 1, "App4 should be returned (with true Forbidden attribute)."); Assert.IsTrue(app4.First().Forbidden, "The Forbidden attribute of App4 should be true."); }
public void ActionFramework_GetActionsWithoutSeePermissionTestA() { IEnumerable <ActionBase> actions; //set required permission for the test - each requirement one descriptor var pdescriptors = new List <TestEquipment.PermissionDescriptor> { new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/(apps)/Folder/App1", AffectedUser = User.Visitor, PType = PermissionType.See, NewValue = PermissionValue.Deny } }; //actions using (new TestEquipment.ContextSimulator(pdescriptors, User.Visitor)) { var siteSample1 = Content.Load("/Root/TestSiteForActionFramework/Sample"); actions = ActionFramework.GetActions(siteSample1, "sc5", ""); } //asserts var app1 = actions.Where(action => action.Name == "App1"); Assert.IsTrue(app1.Count() == 0, "SampleUser shouldn't have permission to get App1 application."); }
private static IEnumerable <ScenarioAction> GetActionsWithScenario(Content content, ODataRequest request) { // Use the back url provided by the client. If it is empty, use // the url of the caller page (the referrer provided by ASP.NET). // The back url can be omitted (switched off) by the client if it provides the // appropriate request parameter (includebackurl false). var backUrl = PortalContext.Current != null && (request == null || request.IncludeBackUrl) ? PortalContext.Current.BackUrl : null; if (string.IsNullOrEmpty(backUrl) && (request == null || request.IncludeBackUrl) && HttpContext.Current?.Request?.UrlReferrer != null) { backUrl = HttpContext.Current.Request.UrlReferrer.ToString(); } var scenario = request?.Scenario; var actions = ActionFramework.GetActions(content, scenario, null, string.IsNullOrEmpty(backUrl) ? null : backUrl, HttpContext.Current); return(actions.Select(action => new ScenarioAction { Action = action, Scenario = scenario })); }
public void ActionFramework_GetTheMostSpecificApplication2() { IEnumerable <ActionBase> actions; Application application; //set required permission for the test - each requirement one descriptor var pdescriptors = new List <TestEquipment.PermissionDescriptor> { new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample/SubFolder", AffectedUser = User.Visitor, PType = PermissionType.RecallOldVersion, NewValue = PermissionValue.Deny } }; using (new TestEquipment.ContextSimulator(pdescriptors, User.Visitor)) { var subFolder = Content.Load("/Root/TestSiteForActionFramework/Sample/SubFolder"); actions = ActionFramework.GetActions(subFolder, "sc24", ""); application = ApplicationStorage.Instance.GetApplication("App24", subFolder, null); } var action = actions.SingleOrDefault(act => act.Name == "App24"); Assert.IsTrue(actions.Count() == 1, "Only one application should be returned."); Assert.IsNotNull(action, "App24 should be in the resultset."); Assert.IsTrue(application.Path == "/Root/TestSiteForActionFramework/Sample/(apps)/Folder/App24"); Assert.IsTrue(action.Forbidden, "App24 should be forbidden."); }
public void ActionFramework_GetActionsForANotExistingScenarioTest() { var siteSample = Content.Load("/Root/TestSiteForActionFramework/Sample"); var actions = ActionFramework.GetActions(siteSample, "gfdhkjgjdfhkgdfghj", ""); Assert.IsTrue(actions.Count() == 0, "The returned action collection should be empty."); }
public void ActionFramework_GetActionsForAScenarioThatIsNotRelevantToTheGivenContentTest() { var siteSample = Content.Load("/Root/TestSiteForActionFramework/Sample"); var actions = ActionFramework.GetActions(siteSample, "sc3", ""); Assert.IsTrue(actions.Count() == 0, "The returned action collection should be empty."); }
//================================================================ Helper methods private void SetParameters() { if (ActionListView == null) { return; } ActionListView.ItemDataBound += ActionListView_ItemDataBound; ActionListView.DataSource = null; //refresh NodePath by contextinfo id if (!string.IsNullOrEmpty(ContextInfoID)) { var context = UITools.FindContextInfo(this, ContextInfoID); if (context != null) { var path = context.Path; if (!string.IsNullOrEmpty(path)) { NodePath = path; } } } if (!string.IsNullOrEmpty(NodePath)) { var actions = new List <ActionBase>(); if (string.IsNullOrEmpty(Scenario)) { actions = ActionFramework.GetActions(ContentRepository.Content.Load(NodePath), Scenario, PortalContext.Current.RequestedUri.PathAndQuery).ToList(); } else { var scParams = GetReplacedScenarioParameters(); var sc = ScenarioManager.GetScenario(Scenario, scParams); if (sc != null) { actions = sc.GetActions(ContentRepository.Content.Load(NodePath), PortalContext.Current.RequestedUri.PathAndQuery).ToList(); } } ActionListView.DataSource = actions.Count > 0 ? actions : null; } else if (!string.IsNullOrEmpty(ActionName) && !string.IsNullOrEmpty(ContentPathList)) { var actions = GetActionListFromPathList(); ActionListView.DataSource = actions.Count > 0 ? actions : null; } ActionListView.DataBind(); }
public void ActionFramework_GetActionsWithSimilarScenarioNames() { var siteSample2 = Content.Load("/Root/TestSiteForActionFramework/Sample2"); var actions = ActionFramework.GetActions(siteSample2, "Settings", ""); var application2 = actions.Where(action => action.Name == "App2"); Assert.IsTrue(actions.Count() == 1, "The returned action collection should contain only one element."); Assert.IsTrue(application2.Count() == 1, "One action related to the App2 application should be in the actions collection."); }
private static IEnumerable <ScenarioAction> GetActionsWithScenario(Content content, ODataRequest request, HttpContext httpContext) { var scenario = request?.Scenario; var actions = ActionFramework.GetActions(content, scenario, null, null, httpContext); return(actions.Select(action => new ScenarioAction { Action = action, Scenario = scenario })); }
public void ActionFramework_GetActionsForAGivenScenarioTest() { var siteSample = Content.Load("/Root/TestSiteForActionFramework/Sample"); var actions = ActionFramework.GetActions(siteSample, "sc2", ""); var application3 = actions.Where(action => action.Name == "App3"); var application4 = actions.Where(action => action.Name == "App4"); Assert.IsTrue(actions.Count() == 2, "Number of returned actions doesn't match the expected value."); Assert.IsTrue(application3.Count() == 1, "One action related to the App3 application should be in the actions collection."); Assert.IsTrue(application4.Count() == 1, "One action related to the App4 application should be in the actions collection."); }
public ActionResult GetActions(string path, string scenario, string back, string parameters) { path = HttpUtility.UrlDecode(path); scenario = HttpUtility.UrlDecode(scenario); parameters = HttpUtility.UrlDecode(parameters); //this line caused an error in back url encoding (multiple back //parameters when the user goes deep, through multiple actions) //back = HttpUtility.UrlDecode(back); var actions = ActionFramework.GetActions(SNCR.Content.Load(path), scenario, parameters, back).ToList(); return(Json(actions, JsonRequestBehavior.AllowGet)); }
public static string GetActions(Content content, string scenario, string back, string parameters) { var path = HttpUtility.UrlDecode(content.Path); scenario = HttpUtility.UrlDecode(scenario); parameters = HttpUtility.UrlDecode(parameters); // this line caused an error in back url encoding (multiple back // parameters when the user goes deep, through multiple actions) // back = HttpUtility.UrlDecode(back); var actions = ActionFramework.GetActions(Content.Load(path), scenario, parameters, back) .Select(IconHelper.AddIconTag).ToList(); return(JsonConvert.SerializeObject(actions)); }
public void ActionFramework_GetActionsForAContentMultiplePermissionsRequieredButNot() { IEnumerable <ActionBase> actions; //set required permission for the test - each requirement one descriptor var pdescriptors = new List <TestEquipment.PermissionDescriptor> { new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample", AffectedUser = User.Visitor, PType = PermissionType.Publish, NewValue = PermissionValue.Allow }, new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample", AffectedUser = User.Visitor, PType = PermissionType.RecallOldVersion, NewValue = PermissionValue.Allow }, new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample", AffectedUser = User.Visitor, PType = PermissionType.DeleteOldVersion, NewValue = PermissionValue.Deny } }; //actions using (new TestEquipment.ContextSimulator(pdescriptors, User.Visitor)) { var siteSample1 = Content.Load("/Root/TestSiteForActionFramework/Sample"); actions = ActionFramework.GetActions(siteSample1, "sc11", ""); } //asserts var app5 = actions.Where(action => action.Name == "App5"); Assert.IsTrue(actions.Count() == 1, "GetActions should return one action."); Assert.IsTrue(app5.Count() == 1, "One action related to the App5 application should be in the actions collection."); Assert.IsTrue(app5.First().Forbidden, "App5 should be Forbidden."); }
// ================================================================ Helper methods private void SetParameters() { if (ActionListView == null) { return; } ActionListView.ItemDataBound += ActionListView_ItemDataBound; ActionListView.DataSource = null; // refresh NodePath by contextinfo id if (!string.IsNullOrEmpty(ContextInfoID)) { var context = UITools.FindContextInfo(this, ContextInfoID); if (context != null) { var path = context.Path; if (!string.IsNullOrEmpty(path)) { NodePath = path; } } } if (!string.IsNullOrEmpty(NodePath)) { var actions = ActionFramework.GetActions(ContentRepository.Content.Load(NodePath), Scenario, GetReplacedScenarioParameters()).ToList(); ActionListView.DataSource = actions.Count > 0 ? actions : null; } else if (!string.IsNullOrEmpty(ActionName) && !string.IsNullOrEmpty(ContentPathList)) { var actions = GetActionListFromPathList(); ActionListView.DataSource = actions.Count > 0 ? actions : null; } ActionListView.DataBind(); }
public void ActionFramework_GetActionsWithTheSameScenarioWithTheSameApplicationNamesWithPermissionTest() { IEnumerable <ActionBase> actions; //set required permission for the test - each requirement one descriptor var pdescriptors = new List <TestEquipment.PermissionDescriptor> { new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample2", AffectedUser = User.Visitor, PType = PermissionType.DeleteOldVersion, NewValue = PermissionValue.Deny } }; var app6 = Content.Load("/Root/TestSiteForActionFramework/(apps)/ContentList/App6"); Application receivedApp; //actions using (new TestEquipment.ContextSimulator(pdescriptors, User.Visitor)) { var siteSample2 = Content.Load("/Root/TestSiteForActionFramework/Sample2"); receivedApp = ApplicationStorage.Instance.GetApplication("App6", siteSample2, null); actions = ActionFramework.GetActions(siteSample2, "sc12", ""); } Assert.AreEqual(app6.Id, receivedApp.Id, "Not the most specific App6 were returned (ContentList's App6 should be returned)."); //asserts var app6Action = actions.Where(action => action.Name == "App6"); Assert.IsTrue(app6Action.Count() == 1, "One action related to the App6 application should be in the actions collection."); Assert.IsTrue(app6Action.First().Forbidden, "App6 should be Forbidden."); }
public void ActionFramework_GetActionsForAContentWithSufficientPermissionsTest() { IEnumerable <ActionBase> actions; //set required permission for the test - each requirement one descriptor var pdescriptors = new List <TestEquipment.PermissionDescriptor> { new TestEquipment.PermissionDescriptor { AffectedPath = "/Root/TestSiteForActionFramework/Sample2", AffectedUser = User.Visitor, PType = PermissionType.Publish, NewValue = PermissionValue.Allow } }; //actions using (new TestEquipment.ContextSimulator(pdescriptors, User.Visitor)) { var siteSample2 = Content.Load("/Root/TestSiteForActionFramework/Sample2"); actions = ActionFramework.GetActions(siteSample2, "sc10", ""); } //asserts var app3 = actions.Where(action => action.Name == "App3"); var app4 = actions.Where(action => action.Name == "App4"); var clapp1 = actions.Where(action => action.Name == "ContentListApp1"); Assert.IsTrue(actions.Count() == 3, "GetActions should return 3 actions."); Assert.IsTrue(app3.Count() == 1, "One action related to the App3 application should be in the actions collection."); Assert.IsTrue(app4.Count() == 1, "One action related to the App4 application should be in the actions collection."); Assert.IsTrue(clapp1.Count() == 1, "One action related to the ContentListApp1 application should be in the actions collection."); Assert.IsTrue(app3.First().Forbidden == false, "App3 should not be Forbidden."); Assert.IsTrue(app4.First().Forbidden == false, "App4 should not be Forbidden."); Assert.IsTrue(clapp1.First().Forbidden == false, "ContentListApp1 should not be Forbidden."); }
public IEnumerable <ActionBase> GetActions(Content context, string scenario, string backUri) { return(ActionFramework.GetActions(context, scenario, null, backUri)); }
/// <summary> /// Sets the callback URL of the ActionMenu. It represents the service url with correct parameters for the actions. /// </summary> private void SetServiceUrl() { var scParams = GetReplacedScenarioParameters(); var context = UITools.FindContextInfo(this, ContextInfoID); var path = !string.IsNullOrEmpty(ContextInfoID) ? context.Path : NodePath; var encodedReturnUrl = Uri.EscapeDataString(PortalContext.Current.RequestedUri.PathAndQuery); var encodedParams = Uri.EscapeDataString(scParams ?? string.Empty); if (string.IsNullOrEmpty(path)) { path = ContentView.GetContentPath(this); } if (string.IsNullOrEmpty(path)) { this.Visible = false; return; } var head = NodeHead.Get(path); if (head == null || !SecurityHandler.HasPermission(head, PermissionType.See)) { this.Visible = false; return; } this.Content = Content.Load(path); // Pre-check action count. If empty, hide the action menu. if (CheckActionCount) { var actionCount = 0; if (!string.IsNullOrEmpty(Scenario)) { actionCount = ActionFramework.GetActions(this.Content, Scenario, scParams, null).Count(); } if (actionCount < 2 && string.Equals(Scenario, "new", StringComparison.CurrentCultureIgnoreCase)) { ClickDisabled = true; } else if (actionCount == 0) { this.Visible = false; return; } } // Pre-check required permissions var permissions = SenseNet.ContentRepository.Fields.PermissionChoiceField.ConvertToPermissionTypes(RequiredPermissions).ToArray(); if (permissions.Length > 0 && !SecurityHandler.HasPermission(head, permissions)) { this.Visible = false; return; } ServiceUrl = string.Format(ODataTools.GetODataOperationUrl(path, "SmartAppGetActions") + "?scenario={0}&back={1}¶meters={2}", Scenario, encodedReturnUrl, encodedParams); }
/// <summary> /// Sets the callback URL of the ActionMenu. It represents the service url with correct parameters for the actions. /// </summary> private void SetServiceUrl() { var scParams = GetReplacedScenarioParameters(); var context = UITools.FindContextInfo(this, ContextInfoID); var path = !String.IsNullOrEmpty(ContextInfoID) ? context.Path : NodePath; var encodedReturnUrl = Uri.EscapeDataString(PortalContext.Current.RequestedUri.PathAndQuery); var encodedParams = Uri.EscapeDataString(scParams ?? string.Empty); if (String.IsNullOrEmpty(path)) { path = GetPathFromContentView(this); } if (string.IsNullOrEmpty(path)) { this.Visible = false; return; } var head = NodeHead.Get(path); if (head == null || !SecurityHandler.HasPermission(head, PermissionType.See)) { this.Visible = false; return; } this.Content = Content.Load(path); //Pre-check action count. If empty, hide the action menu. if (CheckActionCount) { //var sc = ScenarioManager.GetScenario(Scenario, scParams); var actionCount = 0; if (!string.IsNullOrEmpty(Scenario)) { actionCount = ActionFramework.GetActions(this.Content, Scenario, scParams, null).Count(); } if (actionCount < 2 && string.Equals(Scenario, "new", StringComparison.CurrentCultureIgnoreCase)) { ClickDisabled = true; } else if (actionCount == 0) { this.Visible = false; return; } } //Pre-check required permissions var permissions = ActionFramework.GetRequiredPermissions(RequiredPermissions); if (permissions.Count > 0 && !SecurityHandler.HasPermission(head, permissions.ToArray())) { this.Visible = false; return; } var encodedPath = HttpUtility.UrlEncode(path); ServiceUrl = String.Format("/SmartAppHelper.mvc/GetActions?path={0}&scenario={1}&back={2}¶meters={3}", encodedPath, Scenario, encodedReturnUrl, encodedParams); }
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; } } }
protected override void Render(HtmlTextWriter writer) { // render nothing if the action does not exist if (Action == null) { return; } var actionClickable = true; if (CheckActionCount) { var am = ActionMenu.FindContainerActionMenu(this); List <ActionBase> scActions = null; var scenario = string.Empty; if (am != null) { scenario = am.Scenario; if (!string.IsNullOrEmpty(scenario)) { scActions = ActionFramework.GetActions(Content.Load(ContextPath), scenario, am.GetReplacedScenarioParameters()).ToList(); } } if (scActions != null) { if (scActions.Count > 1) { actionClickable = false; } else if (scActions.Count == 1 && string.Equals(scenario, "new", StringComparison.CurrentCultureIgnoreCase) && string.Equals(this.ActionName, "add", StringComparison.CurrentCultureIgnoreCase)) { // change action to the single "New" action found in the parent menu _action = scActions.First(); _actionChecked = true; this.Text = this.Text + " " + _action.Text; } } } if (actionClickable) { var claction = Action as ClientAction; if (claction != null && claction.Callback != null) { NavigateUrl = "javascript:"; this.Attributes["onclick"] = claction.Callback; } else { NavigateUrl = Action.Uri; } } // load html template (provided by the builder) string templateText = null; if (!string.IsNullOrEmpty(Template)) { templateText = HtmlTemplate.GetActionLinkTemplate(Template); } // load html template (by default names) if (string.IsNullOrEmpty(templateText)) { templateText = IconVisible ? (string.IsNullOrEmpty(IconUrl) ? HtmlTemplate.GetActionLinkTemplate(HtmlTemplate.Names.ActionButton) // icon is rendered as a <span> : HtmlTemplate.GetActionLinkTemplate(HtmlTemplate.Names.ActionImageButton)) // icon is rendered as an <image> tag : HtmlTemplate.GetActionLinkTemplate(HtmlTemplate.Names.ActionLink); // no icon } // add actionlinkbutton class only if there is no template if (string.IsNullOrEmpty(templateText)) { this.CssClass += " sn-actionlinkbutton"; } // fill control properties according to the current state of the action FillProperties(); // if a template was found, fill its parameters and render it if (!string.IsNullOrEmpty(templateText)) { writer.Write(TemplateManager.Replace(typeof(ActionTemplateReplacer), templateText, this)); return; } // backward compatibility (classic ASP.NET behavior, when there is no html template) base.Render(writer); }
protected override void Render(HtmlTextWriter writer) { //render nothing if the action does not exist if (Action == null) { return; } var actionClickable = true; if (CheckActionCount) { var am = ActionMenu.FindContainerActionMenu(this); List <ActionBase> scActions = null; var scenario = string.Empty; if (am != null) { scenario = am.Scenario; if (!string.IsNullOrEmpty(scenario)) { scActions = ActionFramework.GetActions(Content.Load(ContextPath), scenario, am.GetReplacedScenarioParameters()).ToList(); } } if (scActions != null) { if (scActions.Count > 1) { actionClickable = false; } else if (scActions.Count == 1 && string.Equals(scenario, "new", StringComparison.CurrentCultureIgnoreCase) && string.Equals(this.ActionName, "add", StringComparison.CurrentCultureIgnoreCase)) { //change action to the single "New" action found in the parent menu _action = scActions.First(); _actionChecked = true; this.Text = this.Text + " " + _action.Text; } } } if (actionClickable) { var claction = Action as ClientAction; if (claction != null && claction.Callback != null) { NavigateUrl = "javascript:"; this.Attributes["onclick"] = claction.Callback; } else { NavigateUrl = Action.Uri; } } this.CssClass += (string.IsNullOrEmpty(this.CssClass) ? "" : " ") + "sn-actionlinkbutton"; if (Action.Forbidden) { this.CssClass += " sn-disabled"; this.Enabled = false; this.NavigateUrl = string.Empty; } base.Render(writer); }