예제 #1
0
        protected virtual string HideUnauthorizedDataViews(string content)
        {
            bool tryRoles = true;

            while (tryRoles)
            {
                Match m = Regex.Match(content, "\\s*\\bdata-roles\\s*=\\s*\"([\\S\\s]*?)\"");
                tryRoles = m.Success;
                if (tryRoles)
                {
                    string stringAfter = content.Substring((m.Index + m.Length));
                    if (DataControllerBase.UserIsInRole(m.Groups[1].Value))
                    {
                        content = (content.Substring(0, m.Index) + stringAfter);
                    }
                    else
                    {
                        int   startPos   = content.Substring(0, m.Index).LastIndexOf("<div");
                        Match closingDiv = Regex.Match(stringAfter, "</div>");
                        content = (content.Substring(0, startPos) + stringAfter.Substring((closingDiv.Index + closingDiv.Length)));
                    }
                }
            }
            return(content);
        }
예제 #2
0
        protected override void ConfigureDescriptor(ScriptBehaviorDescriptor descriptor)
        {
            Page.ClientScript.RegisterHiddenField(String.Format("{0}_{1}_SelectedValue", ClientID, Controller), SelectedValue);
            descriptor.AddProperty("appId", this.TargetControlID);
            descriptor.AddProperty("controller", this.Controller);
            descriptor.AddProperty("viewId", this.View);
            descriptor.AddProperty("pageSize", this.PageSize);
            if (!(ShowActionBar))
            {
                descriptor.AddProperty("showActionBar", false);
            }
            if (ShowActionButtons != ActionButtonLocation.TopAndBottom)
            {
                descriptor.AddProperty("showActionButtons", ShowActionButtons.ToString());
            }
            if (ShowPager != PagerLocation.Bottom)
            {
                descriptor.AddProperty("showPager", ShowPager.ToString());
            }
            if (!(ShowPageSize))
            {
                descriptor.AddProperty("showPageSize", false);
            }
            if (!(ShowDetailsInListMode))
            {
                descriptor.AddProperty("showDetailsInListMode", false);
            }
            if (SearchOnStart)
            {
                descriptor.AddProperty("searchOnStart", true);
            }
            if (_lookupMode)
            {
                descriptor.AddProperty("mode", "Lookup");
                descriptor.AddProperty("lookupValue", LookupValue);
                descriptor.AddProperty("lookupText", LookupText);
                if (!(String.IsNullOrEmpty(LookupPostBackExpression)))
                {
                    descriptor.AddProperty("lookupPostBackExpression", LookupPostBackExpression);
                }
                if (AllowCreateLookupItems)
                {
                    descriptor.AddProperty("newViewId", MyCompany.Data.Controller.LookupActionArgument(Controller, "New"));
                }
            }
            if (!(String.IsNullOrEmpty(FilterSource)))
            {
                Control source = NamingContainer.FindControl(FilterSource);
                if (source != null)
                {
                    descriptor.AddProperty("filterSource", source.ClientID);
                    if (source is DataViewExtender)
                    {
                        descriptor.AddProperty("appFilterSource", ((DataViewExtender)(source)).TargetControlID);
                    }
                }
                else
                {
                    descriptor.AddProperty("filterSource", this.FilterSource);
                }
            }
            if (!(String.IsNullOrEmpty(FilterFields)))
            {
                descriptor.AddProperty("filterFields", this.FilterFields);
            }
            descriptor.AddProperty("cookie", Guid.NewGuid().ToString());
            if (!(String.IsNullOrEmpty(StartCommandName)))
            {
                descriptor.AddProperty("startCommandName", StartCommandName);
            }
            if (!(String.IsNullOrEmpty(StartCommandArgument)))
            {
                descriptor.AddProperty("startCommandArgument", StartCommandArgument);
            }
            if (SelectionMode == DataViewSelectionMode.Multiple)
            {
                descriptor.AddProperty("selectionMode", "Multiple");
            }
            if (!(Enabled))
            {
                descriptor.AddProperty("enabled", false);
            }
            if (TabIndex > 0)
            {
                descriptor.AddProperty("tabIndex", TabIndex);
            }
            if (ShowInSummary)
            {
                descriptor.AddProperty("showInSummary", "true");
            }
            if (!(ShowDescription))
            {
                descriptor.AddProperty("showDescription", false);
            }
            if (!(ShowViewSelector))
            {
                descriptor.AddProperty("showViewSelector", false);
            }
            if (!(String.IsNullOrEmpty(Tag)))
            {
                descriptor.AddProperty("tag", Tag);
            }
            if (SummaryFieldCount != 5)
            {
                descriptor.AddProperty("summaryFieldCount", SummaryFieldCount);
            }
            if (SearchByFirstLetter)
            {
                descriptor.AddProperty("showFirstLetters", true);
            }
            if (!(ShowQuickFind))
            {
                descriptor.AddProperty("showQuickFind", false);
            }
            if (ShowRowNumber)
            {
                descriptor.AddProperty("showRowNumber", true);
            }
            if (AutoHide != AutoHideMode.Nothing)
            {
                descriptor.AddProperty("autoHide", Convert.ToInt16(AutoHide));
            }
            if (Properties.ContainsKey("StartupFilter"))
            {
                descriptor.AddProperty("startupFilter", Properties["StartupFilter"]);
            }
            if (Transaction != DataTransactionMode.NotSupported)
            {
                string t = Transaction.ToString();
                if (Transaction != DataTransactionMode.Supported || ((Page.Request.Params["_transaction"] == "true") && ((Page.Request.Params["_controller"] == this.Controller) && String.IsNullOrEmpty(this.FilterSource))))
                {
                    t = Guid.NewGuid().ToString();
                }
                descriptor.AddProperty("transaction", t);
            }
            string visibleWhenExpression = VisibleWhen;

            if (!(String.IsNullOrEmpty(Roles)) && !(DataControllerBase.UserIsInRole(Roles)))
            {
                if (String.IsNullOrEmpty(visibleWhenExpression))
                {
                    visibleWhenExpression = "false";
                }
                else
                {
                    visibleWhenExpression = String.Format("({0}) && false", visibleWhenExpression);
                }
            }
            if (!(String.IsNullOrEmpty(visibleWhenExpression)))
            {
                descriptor.AddProperty("visibleWhen", visibleWhenExpression);
            }
        }
예제 #3
0
        private void BuildNode(ref Match node, StringBuilder sb, bool first)
        {
            if (!(first))
            {
                sb.Append(",");
            }
            SortedDictionary <string, string> propList = new SortedDictionary <string, string>();
            Match prop = MenuItemPropRegex.Match(node.Groups["PropList"].Value);

            while (prop.Success)
            {
                propList[prop.Groups["Name"].Value.ToLower().Replace("-", String.Empty)] = prop.Groups["Value"].Value;
                prop = prop.NextMatch();
            }
            string roles = null;

            propList.TryGetValue("roles", out roles);
            string users = null;

            propList.TryGetValue("users", out users);
            string roleExceptions = null;

            propList.TryGetValue("roleexceptions", out roleExceptions);
            string userExceptions = null;

            propList.TryGetValue("userexceptions", out userExceptions);
            string url    = node.Groups["Url"].Value.Trim();
            string target = null;

            if (url.StartsWith("_blank:"))
            {
                target = "_blank:";
                url    = url.Substring(7);
            }
            url = ResolveUrl(url);
            if (!(String.IsNullOrEmpty(target)))
            {
                url = (target + url);
            }
            bool resourceAuthorized = true;

            if (!(String.IsNullOrEmpty(roles)))
            {
                if (!(ApplicationServices.UserIsAuthorizedToAccessResource(url, roles)))
                {
                    resourceAuthorized = false;
                }
            }
            if (resourceAuthorized && !(String.IsNullOrEmpty(users)))
            {
                if (!((users == "?")) && (Array.IndexOf(users.ToLower().Split(new char[] {
                    ','
                }, StringSplitOptions.RemoveEmptyEntries), Page.User.Identity.Name.ToLower()) == -1))
                {
                    resourceAuthorized = false;
                }
            }
            if (!(resourceAuthorized) && !(String.IsNullOrEmpty(roleExceptions)))
            {
                if (DataControllerBase.UserIsInRole(roleExceptions))
                {
                    resourceAuthorized = true;
                }
            }
            if (!(resourceAuthorized) && !(String.IsNullOrEmpty(userExceptions)))
            {
                if (!((Array.IndexOf(userExceptions.ToLower().Split(new char[] {
                    ','
                }, StringSplitOptions.RemoveEmptyEntries), Page.User.Identity.Name.ToLower()) == -1)))
                {
                    resourceAuthorized = true;
                }
            }
            sb.Append("{");
            if (resourceAuthorized)
            {
                string title = node.Groups["Title"].Value.Trim();
                string depth = node.Groups["Depth"].Value;
                sb.AppendFormat("title:\"{0}\"", BusinessRules.JavaScriptString(title));
                if (!((url == "about:blank")))
                {
                    sb.AppendFormat(",url:\"{0}\"", BusinessRules.JavaScriptString(url));
                }
                if (Page.Request.RawUrl == url)
                {
                    sb.Append(",selected:true");
                }
                string description = null;
                propList.TryGetValue("description", out description);
                if (!(String.IsNullOrEmpty(description)))
                {
                    sb.AppendFormat(",description:\"{0}\"", BusinessRules.JavaScriptString(description));
                }
                node = node.NextMatch();
                if (node.Success)
                {
                    string firstChildDepth = node.Groups["Depth"].Value;
                    if (firstChildDepth.Length > depth.Length)
                    {
                        sb.Append(",children:[");
                        first = true;
                        while (node.Success)
                        {
                            BuildNode(ref node, sb, first);
                            if (first)
                            {
                                first = false;
                            }
                            if (node.Success)
                            {
                                string nextDepth = node.Groups["Depth"].Value;
                                if (firstChildDepth.Length > nextDepth.Length)
                                {
                                    break;
                                }
                            }
                        }
                        sb.Append("]");
                    }
                }
            }
            else
            {
                node = node.NextMatch();
            }
            sb.Append("}");
        }