Пример #1
0
        public static IEnumerable <UserGroup> GetUserGroups(UserPrincipal principal)
        {
            IEnumerable <UserGroup> userGroups = UserGroupMember.FetchAllByPrincipalId(principal.Id).Select(mem => mem.Group);

            userGroups = userGroups.Concat(userGroups.SelectMany(group => Customisation.GetUserGroups(group.Principal)));
            return(userGroups);
        }
Пример #2
0
        private void BaseSecurePage_PreRender(Object sender, EventArgs e)
        {
            if (this.CurrentSession.User.SysAdmin.ConvertTo <Boolean>())
            {
                // Get all of the controls on the page and apply customisations.
                Customisation.Cache = null;
                UserGroup[] groupMembership = { };
                if (this.CurrentSession != null && this.CurrentSession.Expiry > DateTime.Now)
                {
                    groupMembership = Customisation.GetUserGroups(this.CurrentSession.User.Principal).ToArray();
                }
                CustomisationSecurity[] customisationSecurities = UserGroup.FetchAll().Select(group => new CustomisationSecurity(group.Principal)).ToArray();

                string pageLoc = GetPageLocation();

                Customisation[] customisations = Customisation.GetFromUI(this, pageLoc, groupMembership, customisationSecurities).ToArray();
                customisations.Execute(customisation => customisation.InitialiseControl(groupMembership));

                // Register the customisations with the client-side script.

                string sScript = @"    
                    consensus.web.customisation.data = " + RestHandler.Serializer.Serialize(customisations) + @";
                    consensus.web.customisation.url = " + HttpUtility.JavaScriptStringEncode(pageLoc, true) + @";
                    consensus.web.customisation.blockCustomFields = " + BlockCustomFields.ToString().ToLower() + @";
                ";

                // Get custom fields and prepare serialisation to exclude the CustomFieldValues element (which would get values for all records)
                if (!BlockCustomFields)
                {
                    object       baseObject;
                    PropertyInfo dataInfo  = getDataInfo(out baseObject);
                    string       dataURL   = GetDataUrl(dataInfo);
                    string       tableName = GetTableName(dataInfo, baseObject);

                    Dictionary <Type, List <string> > exclude = new Dictionary <Type, List <string> >();
                    exclude.Add(typeof(UserInterface.ScreenCustomField), new List <string>()
                    {
                        "CustomFieldValues"
                    });
                    var excludingSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    excludingSerializer.RegisterConverters(new System.Web.Script.Serialization.JavaScriptConverter[] { new RestSerializer()
                                                                                                                       {
                                                                                                                           Ignore = exclude
                                                                                                                       } });

                    sScript += @"
                    consensus.web.customisation.customFields = " + excludingSerializer.Serialize(CustomFields) + @";
                    consensus.web.customisation.page = " + HttpUtility.JavaScriptStringEncode(pageLoc, true) + @";
                    consensus.web.customisation.dataurl = " + HttpUtility.JavaScriptStringEncode(dataURL, true) + @";
                    consensus.web.customisation.tableName = " + HttpUtility.JavaScriptStringEncode(tableName, true) + @";
                    ";
                }

                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "CustomisationJS", sScript, true);
            }
        }
Пример #3
0
        /// <summary>
        ///     Gets the collection of customisations for the specified control.
        /// </summary>
        private static IEnumerable <Customisation> GetFromUI(Control control, string screenUrl, CustomisationSecurity[] customisationSecurities)
        {
            // Create the customisation for the specified control
            IEnumerable <Customisation> result = new Customisation[] { new Customisation(control, screenUrl, cloneSecurities(customisationSecurities)) };

            //result = result.Concat(control.Controls.OfType<Control>().SelectMany(GetFromUI, customisationSecurities));
            foreach (Control childControl in control.Controls)
            {
                if (control is IHaveNoChildren == false || childControl is CustomFieldInsertPointDiv)
                {
                    result = result.Concat(GetFromUI(childControl, screenUrl, customisationSecurities));
                }
            }
            return(result);
        }