public virtual bool CheckPermission() { if (TargetNode != null) { if (!SecurityHandler.HasPermission(TargetNode, PermissionType.See)) { ThrowNotFound(); } } if (_appNode != null) { if (!SecurityHandler.HasPermission(_appNode, PermissionType.RunApplication)) { return(false); } if (TargetNode != null) { Application appNode = null; // Elevation: we should check required permissions here, // regardless of the users permissions for the application. using (new SystemAccount()) { appNode = Node.Load <Application>(_appNode.Id); } if (!ActionFramework.HasRequiredPermissions(appNode, TargetNode)) { return(false); } } } return(true); }
public string GetActionUrl(string url, string actionName, string backUrl) { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(actionName)) { return(string.Empty); } Content content = null; try { content = Content.Load(RepositoryPath.Combine(PortalContext.Current.Site.Path, url)) ?? Content.Load(url); } catch (SenseNet.ContentRepository.Storage.Security.SenseNetSecurityException) { return(string.Empty); } var act = ActionFramework.GetAction(actionName, content, backUrl, null); var res = act == null ? string.Empty : act.Forbidden ? string.Empty : act.Uri; return(res); //return ActionFramework.GetActionUrl(RepositoryPath.Combine(PortalContext.Current.Site.Path, url), actionName, backUrl); }
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 virtual bool CheckPermission() { if (TargetNode != null) { if (!SecurityHandler.HasPermission(TargetNode, PermissionType.See)) { ThrowNotFound(); } if (!SecurityHandler.HasPermission(TargetNode, PermissionType.RunApplication)) { return(false); } } if (_appNode != null) { if (!SecurityHandler.HasPermission(_appNode, PermissionType.RunApplication)) { return(false); } if (TargetNode != null) { if (!ActionFramework.HasRequiredPermissions(Node.Load <Application>(_appNode.Id), TargetNode)) { return(false); } } } return(true); }
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 string ActionUrl(string ActionName) { var node = Node.LoadNode(Path); var content = Repo.Content.Create(node); return(ActionFramework.GetAction(ActionName, content, null, null).Uri); }
public void ProcessRequest(HttpContext context) { int code = 301; Int32.TryParse(StatusCode ?? "301", out code); HttpContext.Current.Response.StatusCode = code; if (code >= 300 && code < 400) { var action = ActionFramework.GetAction(PortalContext.Current.ActionName ?? "browse", Content.Create(PortalContext.Current.ContextNode), (this.AllowQueryString) ? HttpUtility.ParseQueryString(PortalContext.Current.RequestedUri.Query) : null); var actionUri = ActionFramework.GetActionUrl(PortalContext.Current.ContextNodePath, "Browse"); if (action == null) { HttpContext.Current.Response.StatusCode = 500; } else if (!string.IsNullOrEmpty(action.Uri)) { HttpContext.Current.Response.RedirectLocation = action.Uri; } else { HttpContext.Current.Response.StatusCode = 404; } } HttpContext.Current.Response.End(); }
protected override void CreateChildControls() { base.CreateChildControls(); Panel pnlContainer = new Panel(); pnlContainer.CssClass = CssClass; System.Web.UI.WebControls.Image cImage = new System.Web.UI.WebControls.Image(); //string imageid = string.Format("CaptchaImage.ashx?guid={0}&s=1", _captcha.UniqueId); //string currentPath = PortalContext.Current.RequestedUri.AbsoluteUri; //string imageid = string.Format("{0}?Action=GetCaptcha&guid={1}&s=1", currentPath, _captcha.UniqueId); cImage.ImageUrl = ActionFramework.GetActionUrl("/Root", "GetCaptcha", string.Empty) + string.Format("&guid={0}&s=1", _captcha.UniqueId); cImage.BorderStyle = BorderStyle.None; cImage.AlternateText = ToolTip; cImage.Width = _captcha.Width; cImage.Height = _captcha.Height; pnlContainer.Controls.Add(cImage); if (this.LayoutStyle == Layout.Vertical) { Literal lBr = new Literal(); lBr.Text = "<br />"; pnlContainer.Controls.Add(lBr); } else { Literal lSpace = new Literal(); lSpace.Text = " "; pnlContainer.Controls.Add(lSpace); } Label lblInstruct = new Label(); lblInstruct.ID = "lblInstructoin"; lblInstruct.Text = Text; lblInstruct.AccessKey = AccessKey; pnlContainer.Controls.Add(lblInstruct); tbUserEntry = new TextBox(); tbUserEntry.ID = "tbUserEntry"; tbUserEntry.AccessKey = AccessKey; tbUserEntry.Attributes.Add("size", _captcha.TextLength.ToString()); tbUserEntry.Attributes.Add("maxlength", _captcha.TextLength.ToString()); if (!Enabled) { tbUserEntry.Attributes.Add("disabled", "disabled"); } if (TabIndex > 0) { tbUserEntry.Attributes.Add("tabindex", TabIndex.ToString()); } pnlContainer.Controls.Add(tbUserEntry); // Set the style:: pnlContainer.Attributes.Add("style", this.CssStyle()); this.Controls.Add(pnlContainer); }
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."); }
/// <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; } 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 (sc != null) { actionCount = sc.GetActions(this.Content, PortalContext.Current.RequestedUri.PathAndQuery).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(NodeHead.Get(path), 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); }
/// <summary> /// This method can be used when no back url is given (e.g. in case of a Browse view). /// </summary> protected void RedirectToParent() { if (this.Content == null) { return; } Response.Redirect(ActionFramework.GetActionUrl(this.Content.ContentHandler.ParentPath, "Browse"), false); }
private static string GetOnClientClick(string nodePath, string actionName) { var result = new StringBuilder(); result.Append(@"javascript: window.location = '"); result.Append(ActionFramework.GetActionUrl(nodePath, actionName, HttpUtility.UrlEncode(HttpContext.Current.Request.RawUrl))); result.Append(@"';"); result.Append(@"return false;"); return(result.ToString()); }
public virtual void Execute(JobExecutionContext context) { logger.Debug("Execute Job: " + context.MergedJobDataMap.Get("JobName")); ActionContext actionContext = new ActionContext(context.MergedJobDataMap); ActionFramework actionFramework = ContainerFactory.GetContainer().GetInstance <ActionFramework>(); actionFramework.Execute(ActionId(), actionContext); }
private static string GetOnClientClick(string nodePath, string actionName) { var result = new StringBuilder(); result.Append(@"javascript: window.location = '"); result.Append(ActionFramework.GetActionUrl(nodePath, actionName)); result.Append(@"';"); result.Append(@"return false;"); return(result.ToString()); }
//================================================================ 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 })); }
private void SetHyperLink() { var hyperLinkFill = this.FindControl("HyperLinkFill") as HyperLink; if (hyperLinkFill == null) { return; } hyperLinkFill.NavigateUrl = ActionFramework.GetAction("Add", Content, new { ContentTypeName = "SurveyItem" }).Uri; hyperLinkFill.Visible = true; }
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."); }
private List <ActionBase> GetActionListFromPathList() { var actions = new List <ActionBase>(); if (string.IsNullOrEmpty(ActionName) || string.IsNullOrEmpty(ContentPathList)) { return(actions); } var pathList = ContentPathList.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); actions.AddRange(pathList.Select(SNCR.Content.Load).Select(content => ActionFramework.GetAction(ActionName, content, null)).Where(action => action != null)); foreach (var action in actions) { action.Text = action.GetContent().DisplayName; } return(actions); }
public static string ActionUrl(Content content, string actionName, bool?includeBackUrl, object parameters) { if (content == null || string.IsNullOrEmpty(actionName)) { return(string.Empty); } var action = ActionFramework.GetAction(actionName, content, parameters); if (action == null) { return(string.Empty); } if (includeBackUrl.HasValue) { action.IncludeBackUrl = includeBackUrl.Value; } return(action.Uri); }
// ================================================================ 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 static string Action(Content content, string actionName, bool?includeBackUrl) { if (content == null || string.IsNullOrEmpty(actionName)) { return(string.Empty); } var action = ActionFramework.GetAction(actionName, content, null); if (action == null) { return(string.Empty); } if (includeBackUrl.HasValue) { action.IncludeBackUrl = includeBackUrl.Value; } return("<a href='" + action.Uri + "'" + (string.IsNullOrEmpty(action.CssClass) ? string.Empty : " class='" + action.CssClass + "'") + ">" + content.DisplayName + "</a>"); }
protected void BtnEdit_Click(object sender, EventArgs e) { var templateName = (sender as Button).CommandArgument; var contextNode = PortalContext.Current.ContextNode; var templateNode = contextNode.GetReference <Node>(string.Concat(templateName, "Page")); var templateNodePath = templateNode.Path; if (templateNodePath.Contains("System/SystemPlugins")) { var targetPath = RepositoryPath.Combine(contextNode.Path, "configuration"); if (!Node.Exists(targetPath)) { var folder = new Folder(contextNode, "Folder") { Name = "configuration", DisplayName = "Configuration" }; folder.Save(); } var wcd = NodeType.CreateInstance("WebContentDemo", Node.LoadNode(targetPath)); wcd["Name"] = templateNode["Name"]; wcd["DisplayName"] = templateNode["DisplayName"]; wcd["Subtitle"] = templateNode["Subtitle"]; wcd["Body"] = templateNode["Body"]; wcd.Save(); templateNodePath = wcd.Path; contextNode.SetReference(string.Concat(templateName, "Page"), wcd); contextNode.Save(); } Response.Redirect(ActionFramework.GetActionUrl(templateNodePath, "EditSurveyTemplate", PortalContext.Current.BackUrl)); }