/// <summary>
        /// Handles the OnSave event of the masterPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void masterPage_OnSave(object sender, EventArgs e)
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            if (Page.IsValid)
            {
                using (new Rock.Data.UnitOfWorkScope())
                {
                    var blockService = new Rock.Model.BlockService();
                    var block        = blockService.Get(_block.Id);

                    block.LoadAttributes();

                    block.Name = tbBlockName.Text;
                    block.OutputCacheDuration = Int32.Parse(tbCacheDuration.Text);
                    blockService.Save(block, CurrentPersonId);

                    Rock.Attribute.Helper.GetEditValues(phAttributes, _block);
                    _block.SaveAttributeValues(CurrentPersonId);

                    Rock.Web.Cache.BlockCache.Flush(_block.Id);
                }

                string script = "window.parent.closeModal()";
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", script, true);
            }
            else
            {
                Rock.Attribute.Helper.SetErrorIndicators(phAttributes, _block);
            }
        }
        //private BlockCache _block = null;
        //private string _zoneName = string.Empty;

        /// <summary>
        /// Raises the <see cref="E:Init" /> event.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogMasterPage masterPage = this.Page.Master as Rock.Web.UI.DialogMasterPage;
            if (masterPage != null)
            {
                masterPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int        blockId = Convert.ToInt32(PageParameter("BlockId"));
                BlockCache _block  = BlockCache.Read(blockId);

                if (_block.IsAuthorized("Administrate", CurrentPerson))
                {
                    phAttributes.Controls.Clear();
                    Rock.Attribute.Helper.AddEditControls(_block, phAttributes, !Page.IsPostBack);
                }
                else
                {
                    DisplayError("You are not authorized to edit this block");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
        /// <summary>
        /// Handles the OnSave event of the masterPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void masterPage_OnSave(object sender, EventArgs e)
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            if (Page.IsValid)
            {
                using (new Rock.Data.UnitOfWorkScope())
                {
                    var blockService = new Rock.Model.BlockService();
                    var block        = blockService.Get(_block.Id);

                    block.LoadAttributes();

                    block.Name                = tbBlockName.Text;
                    block.CssClass            = tbCssClass.Text;
                    block.PreHtml             = cePreHtml.Text;
                    block.PostHtml            = cePostHtml.Text;
                    block.OutputCacheDuration = Int32.Parse(tbCacheDuration.Text);
                    blockService.Save(block, CurrentPersonId);

                    Rock.Attribute.Helper.GetEditValues(phAttributes, _block);
                    if (phAdvancedAttributes.Controls.Count > 0)
                    {
                        Rock.Attribute.Helper.GetEditValues(phAdvancedAttributes, _block);
                    }
                    _block.SaveAttributeValues(CurrentPersonId);

                    Rock.Web.Cache.BlockCache.Flush(_block.Id);
                }

                string script = string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId);
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", script, true);
            }
        }
        public MobileBlockResponse BlockGetRequest(int id, string request = "")
        {
            var person = GetPerson();

            HttpContext.Current.Items.Add("CurrentPerson", person);
            var    blockCache = BlockCache.Read(id);
            var    pageCache  = PageCache.Read(blockCache.PageId ?? 0);
            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            if (blockCache.IsAuthorized(Authorization.VIEW, person))
            {
                var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);

                if (control is RockBlock && control is IMobileResource)
                {
                    control.SetBlock(pageCache, blockCache);
                    var mobileResource      = control as IMobileResource;
                    var mobileBlockResponse = mobileResource.HandleRequest(request, new Dictionary <string, string>());
                    HttpContext.Current.Response.Headers.Set("TTL", mobileBlockResponse.TTL.ToString());
                    return(mobileBlockResponse);
                }
            }
            HttpContext.Current.Response.Headers.Set("TTL", "0");
            return(new MobileBlockResponse());
        }
        public MobileBlockResponse BlockPostRequest(int id, string arg = "")
        {
            HttpContent requestContent = Request.Content;
            string      content        = requestContent.ReadAsStringAsync().Result;
            var         body           = JsonConvert.DeserializeObject <Dictionary <string, string> >(content);
            var         person         = GetPerson();

            HttpContext.Current.Items.Add("CurrentPerson", person);
            var    blockCache = BlockCache.Read(id);
            var    pageCache  = PageCache.Read(blockCache.PageId ?? 0);
            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            if (blockCache.IsAuthorized(Authorization.VIEW, person))
            {
                var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);

                if (control is RockBlock && control is IMobileResource)
                {
                    control.SetBlock(pageCache, blockCache);
                    var mobileResource      = control as IMobileResource;
                    var mobileBlockResponse = mobileResource.HandleRequest(arg, body);
                    mobileBlockResponse.TTL = 0;
                    return(mobileBlockResponse);
                }
            }
            return(new MobileBlockResponse());
        }
Exemple #6
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            if (!Page.IsPostBack && _block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                rptProperties.DataSource = GetTabs(_block.BlockType);
                rptProperties.DataBind();

                tbBlockName.Text = _block.Name;
                tbCssClass.Text  = _block.CssClass;
                cePreHtml.Text   = _block.PreHtml;
                cePostHtml.Text  = _block.PostHtml;

                // Hide the Cache duration block for now;
                tbCacheDuration.Visible = false;
                //tbCacheDuration.Text = _block.OutputCacheDuration.ToString();

                CustomGridColumnsConfigState = _block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey).FromJsonOrNull <CustomGridColumnsConfig>() ?? new CustomGridColumnsConfig();

                BindCustomColumnsConfig();
            }

            base.OnLoad(e);
        }
Exemple #7
0
        public MobilePage GetPage(int id, string parameter = "")
        {
            var person = GetPerson();

            if (!HttpContext.Current.Items.Contains("CurrentPerson"))
            {
                HttpContext.Current.Items.Add("CurrentPerson", person);
            }

            var pageCache = PageCache.Read(id);

            if (!pageCache.IsAuthorized(Authorization.VIEW, person))
            {
                return(new MobilePage());
            }

            SavePageViewInteraction(pageCache, person);

            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            MobilePage mobilePage = new MobilePage();

            mobilePage.Layout    = AvalancheUtilities.GetLayout(pageCache.Layout.Name);
            mobilePage.Title     = pageCache.PageTitle;
            mobilePage.ShowTitle = pageCache.PageDisplayTitle;
            foreach (var attribute in pageCache.AttributeValues)
            {
                mobilePage.Attributes.Add(attribute.Key, attribute.Value.ValueFormatted);
            }
            foreach (var block in pageCache.Blocks)
            {
                if (block.IsAuthorized(Authorization.VIEW, person))
                {
                    var blockCache = BlockCache.Read(block.Id);
                    try
                    {
                        var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);
                        if (control is RockBlock && control is IMobileResource)
                        {
                            control.SetBlock(pageCache, blockCache);
                            var mobileResource = control as IMobileResource;
                            var mobileBlock    = mobileResource.GetMobile(parameter);
                            mobileBlock.BlockId = blockCache.Id;
                            mobileBlock.Zone    = blockCache.Zone;
                            mobilePage.Blocks.Add(mobileBlock);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogService.LogException(e, HttpContext.Current);
                    }
                }
            }
            HttpContext.Current.Response.Headers.Set("TTL", pageCache.OutputCacheDuration.ToString());
            return(mobilePage);
        }
Exemple #8
0
        /// <summary>
        /// Renders a label and <see cref="T:System.Web.UI.WebControls.TextBox"/> control to the specified <see cref="T:System.Web.UI.HtmlTextWriter"/> object.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> that receives the rendered output.</param>
        public override void RenderControl(HtmlTextWriter writer)
        {
            if (this.Visible)
            {
                string cssClass = "";
                foreach (Control childControl in this.Controls)
                {
                    if (childControl.GetType().ToString().Contains("RockBlockWrapper"))
                    {
                        foreach (Control grandChildControl in childControl.Controls)
                        {
                            if (grandChildControl.GetType().ToString().Contains("org_secc_cms_sectionheader"))
                            {
                                var block        = BlockCache.Read((( RockBlock )grandChildControl).BlockId);
                                var definedValue = DefinedValueCache.Read(block.GetAttributeValue("SectionType"));
                                if (definedValue != null && definedValue.AttributeValues.ContainsKey("ClassName"))
                                {
                                    cssClass = definedValue.AttributeValues["ClassName"].ToString();
                                }
                                break;
                            }
                        }
                        if (cssClass != "")
                        {
                            break;
                        }
                    }
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);
                writer.RenderBeginTag("section");

                base.RenderControl(writer);
                writer.RenderEndTag();
            }
        }
Exemple #9
0
        /// <summary>
        /// Handles the user command to show custom settings.
        /// </summary>
        protected override void ShowSettings()
        {
            List <DashboardBlockType> blockTypes;

            //
            // Get the current configuration settings for the list of available blocks.
            //
            try
            {
                blockTypes = JsonConvert.DeserializeObject <List <DashboardBlockType> >(GetAttributeValue("AvailableBlocks"));

                if (blockTypes == null)
                {
                    blockTypes = new List <DashboardBlockType>();
                }
            }
            catch
            {
                blockTypes = new List <DashboardBlockType>();
            }

            //
            // Get all the known blocks and remove any blocks that no longer exist from the
            // configuration data.
            //
            var blocks           = GetAllBlocks();
            var removeBlockTypes = blockTypes.Where(b => !blocks.Any(bb => bb.Id == b.BlockId)).ToList();

            blockTypes.RemoveAll(b => removeBlockTypes.Any(rb => rb.BlockId == b.BlockId));

            //
            // Walk each block and either initialize the block type or load it from cache.
            //
            foreach (var block in blocks)
            {
                var blockType = blockTypes.Where(b => b.BlockId == block.Id).FirstOrDefault();

                if (blockType == null)
                {
                    blockType            = new DashboardBlockType();
                    blockType.BlockCache = block;
                    blockType.BlockId    = block.Id;

                    blockTypes.Add(blockType);
                }
                else
                {
                    blockType.BlockCache = BlockCache.Read(blockType.BlockId);
                }
            }

            rblSettingsDefaultLayout.SelectedValue = GetAttributeValue("DefaultLayout");

            AvailableBlocksLive        = blockTypes;
            gSettingsBlocks.DataSource = blockTypes;
            gSettingsBlocks.DataBind();

            mdlSettings.Show();
        }
Exemple #10
0
        /// <summary>
        /// Binds the custom columns configuration.
        /// </summary>
        private void BindCustomColumnsConfig()
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            rptCustomGridColumns.DataSource = CustomGridColumnsConfigState.ColumnsConfig;
            rptCustomGridColumns.DataBind();
        }
Exemple #11
0
        /// <summary>
        /// Get the list of available blocks that the user can enable on the dashboard.
        /// </summary>
        /// <returns>An enumerable list of block types available.</returns>
        private List <DashboardBlockType> GetAvailableBlocks()
        {
            List <DashboardBlockType> blockTypes;

            //
            // Get the current configuration settings for the list of available blocks.
            //
            try
            {
                blockTypes = JsonConvert.DeserializeObject <List <DashboardBlockType> >(GetAttributeValue("AvailableBlocks"));

                if (blockTypes == null)
                {
                    blockTypes = new List <DashboardBlockType>();
                }
            }
            catch
            {
                blockTypes = new List <DashboardBlockType>();
            }

            //
            // Get all the blocks the user can see.
            //
            var blocks = GetAllBlocks()
                         .Where(b => b.IsAuthorized(Authorization.VIEW, CurrentPerson) || b.IsAuthorized(Authorization.EDIT, CurrentPerson) || b.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                         .ToList();

            //
            // Filter the block types to those the user has permissions to view.
            //
            blockTypes = blockTypes.Where(bt => blocks.Any(b => b.Id == bt.BlockId)).ToList();

            //
            // Walk each block and either initialize the block type or load it from cache.
            //
            foreach (var block in blocks)
            {
                var blockType = blockTypes.Where(b => b.BlockId == block.Id).FirstOrDefault();

                if (blockType == null)
                {
                    blockType            = new DashboardBlockType();
                    blockType.BlockCache = block;
                    blockType.BlockId    = block.Id;

                    blockTypes.Add(blockType);
                }
                else
                {
                    blockType.BlockCache = BlockCache.Read(blockType.BlockId);
                }
            }

            return(blockTypes);
        }
Exemple #12
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            string name = BlockCache.Read(BlockId).BlockType.Path.Replace("~", "").Replace(".ascx", "");

            Id        = "bid_" + BlockId;
            Path      = name;
            Component = name.Replace("/", ".").Remove(0, 1);
        }
        public HttpResponseMessage Family(string param)
        {
            try
            {
                var Session = HttpContext.Current.Session;

                CurrentKioskId = ( int )Session["CheckInKioskId"];
                Guid       blockGuid           = ( Guid )Session["BlockGuid"];
                List <int> CheckInGroupTypeIds = (List <int>)Session["CheckInGroupTypeIds"];
                CurrentCheckInState = new CheckInState(CurrentKioskId, null, CheckInGroupTypeIds);
                CurrentCheckInState.CheckIn.UserEnteredSearch   = true;
                CurrentCheckInState.CheckIn.ConfirmSingleFamily = true;
                CurrentCheckInState.CheckIn.SearchType          = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER);
                CurrentCheckInState.CheckIn.SearchValue         = param;

                var    rockContext      = new Rock.Data.RockContext();
                var    block            = BlockCache.Read(blockGuid, rockContext);
                string workflowActivity = block.GetAttributeValue("WorkflowActivity");
                Guid?  workflowGuid     = block.GetAttributeValue("WorkflowType").AsGuidOrNull();

                List <string> errors;
                var           workflowTypeService = new WorkflowTypeService(rockContext);
                var           workflowService     = new WorkflowService(rockContext);
                var           workflowType        = workflowTypeService.Queryable("ActivityTypes")
                                                    .Where(w => w.Guid.Equals(workflowGuid.Value))
                                                    .FirstOrDefault();
                var CurrentWorkflow = Rock.Model.Workflow.Activate(workflowType, CurrentCheckInState.Kiosk.Device.Name, rockContext);

                var activityType = workflowType.ActivityTypes.Where(a => a.Name == workflowActivity).FirstOrDefault();
                if (activityType != null)
                {
                    WorkflowActivity.Activate(activityType, CurrentWorkflow, rockContext);
                    if (workflowService.Process(CurrentWorkflow, CurrentCheckInState, out errors))
                    {
                        // Keep workflow active for continued processing
                        CurrentWorkflow.CompletedDateTime = null;
                        SaveState(Session);
                        List <CheckInFamily> families = CurrentCheckInState.CheckIn.Families;
                        families = families.OrderBy(f => f.Caption).ToList();
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, families));
                    }
                }
                else
                {
                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, string.Format("Workflow type does not have a '{0}' activity type", workflowActivity)));
                }
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, String.Join("\n", errors)));
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, HttpContext.Current);
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.Forbidden, "Forbidden"));
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            if (!Page.IsPostBack && _block.IsAuthorized("Administrate", CurrentPerson))
            {
                tbBlockName.Text     = _block.Name;
                tbCacheDuration.Text = _block.OutputCacheDuration.ToString();
            }

            base.OnLoad(e);
        }
        /// <summary>
        /// Raises the <see cref="E:Init" /> event.
        /// </summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogMasterPage masterPage = this.Page.Master as Rock.Web.UI.DialogMasterPage;
            if (masterPage != null)
            {
                masterPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int        blockId = Convert.ToInt32(PageParameter("BlockId"));
                BlockCache _block  = BlockCache.Read(blockId);

                if (_block.IsAuthorized("Administrate", CurrentPerson))
                {
                    phAttributes.Controls.Clear();
                    phAdvancedAttributes.Controls.Clear();

                    if (_block.Attributes != null)
                    {
                        foreach (var attributeCategory in Rock.Attribute.Helper.GetAttributeCategories(_block))
                        {
                            if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("advanced", StringComparison.OrdinalIgnoreCase))
                            {
                                Rock.Attribute.Helper.AddEditControls(
                                    string.Empty, attributeCategory.Attributes.Select(a => a.Key).ToList(),
                                    _block, phAdvancedAttributes, string.Empty, !Page.IsPostBack, new List <string>());
                            }
                            else
                            {
                                Rock.Attribute.Helper.AddEditControls(
                                    attributeCategory.Category != null ? attributeCategory.Category.Name : string.Empty,
                                    attributeCategory.Attributes.Select(a => a.Key).ToList(),
                                    _block, phAttributes, string.Empty, !Page.IsPostBack, new List <string>());
                            }
                        }
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this block");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
Exemple #16
0
        /// <summary>
        /// Handles the Click event of the lbProperty control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbProperty_Click(object sender, EventArgs e)
        {
            LinkButton lb = sender as LinkButton;

            if (lb != null)
            {
                CurrentTab = lb.Text;

                int        blockId = Convert.ToInt32(PageParameter("BlockId"));
                BlockCache _block  = BlockCache.Read(blockId);
                rptProperties.DataSource = GetTabs(_block.BlockType);
                rptProperties.DataBind();
            }

            ShowSelectedPane();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            var blockControlType = System.Web.Compilation.BuildManager.GetCompiledType(_block.BlockType.Path);

            this.ShowCustomGridColumns = typeof(Rock.Web.UI.ICustomGridColumns).IsAssignableFrom(blockControlType);
            this.ShowCustomGridOptions = typeof(Rock.Web.UI.ICustomGridOptions).IsAssignableFrom(blockControlType);

            if (!Page.IsPostBack && _block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                rptProperties.DataSource = GetTabs(_block.BlockType);
                rptProperties.DataBind();

                tbBlockName.Text = _block.Name;
                tbCssClass.Text  = _block.CssClass;
                cePreHtml.Text   = _block.PreHtml;
                cePostHtml.Text  = _block.PostHtml;

                // Hide the Cache duration block for now;
                tbCacheDuration.Visible = false;
                //tbCacheDuration.Text = _block.OutputCacheDuration.ToString();

                rcwCustomGridColumns.Visible  = this.ShowCustomGridColumns;
                tglEnableStickyHeader.Visible = this.ShowCustomGridOptions;

                if (this.ShowCustomGridColumns)
                {
                    CustomGridColumnsConfigState = _block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey).FromJsonOrNull <CustomGridColumnsConfig>() ?? new CustomGridColumnsConfig();
                    BindCustomColumnsConfig();
                }
                else
                {
                    CustomGridColumnsConfigState = null;
                }

                if (this.ShowCustomGridOptions)
                {
                    tglEnableStickyHeader.Checked = _block.GetAttributeValue(CustomGridOptionsConfig.EnableStickerHeadersAttributeKey).AsBoolean();
                }
            }

            base.OnLoad(e);
        }
Exemple #18
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            int        blockId = Convert.ToInt32(PageParameter("BlockId"));
            BlockCache _block  = BlockCache.Read(blockId);

            if (!Page.IsPostBack && _block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                rptProperties.DataSource = _tabs;
                rptProperties.DataBind();

                tbBlockName.Text     = _block.Name;
                tbCssClass.Text      = _block.CssClass;
                cePreHtml.Text       = _block.PreHtml;
                cePostHtml.Text      = _block.PostHtml;
                tbCacheDuration.Text = _block.OutputCacheDuration.ToString();
            }

            base.OnLoad(e);
        }
Exemple #19
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            int?   entityTypeId   = PageParameter("EntityTypeId").AsIntegerOrNull();
            string entityTypeName = string.Empty;
            Type   type           = null;

            // Get Entity Type
            if (entityTypeId.HasValue)
            {
                var entityType = EntityTypeCache.Read(entityTypeId.Value);
                if (entityType != null)
                {
                    entityTypeName = entityType.FriendlyName;
                    type           = entityType.GetEntityType();
                }
            }

            // Get Entity Id
            int entityId = PageParameter("EntityId").AsIntegerOrNull() ?? 0;

            // Get object type
            if (type != null)
            {
                if (entityId == 0)
                {
                    iSecured = (ISecured)Activator.CreateInstance(type);
                }
                else
                {
                    // Get the context type since this may be for a non-rock core object
                    Type contextType = null;
                    var  contexts    = Rock.Reflection.SearchAssembly(type.Assembly, typeof(Rock.Data.DbContext));
                    if (contexts.Any())
                    {
                        contextType = contexts.First().Value;
                    }
                    else
                    {
                        contextType = typeof(RockContext);
                    }

                    Type   serviceType = typeof(Rock.Data.Service <>);
                    Type[] modelType   = { type };
                    Type   service     = serviceType.MakeGenericType(modelType);
                    var    getMethod   = service.GetMethod("Get", new Type[] { typeof(int) });

                    var context         = Activator.CreateInstance(contextType);
                    var serviceInstance = Activator.CreateInstance(service, new object[] { context });
                    iSecured = getMethod.Invoke(serviceInstance, new object[] { entityId }) as ISecured;
                }

                var block = iSecured as Rock.Model.Block;
                if (block != null)
                {
                    // If the entity is a block, get any actions that were updated or added by the block type using
                    // one or more SecurityActionAttributes.
                    var blockCache = BlockCache.Read(block.Id);
                    if (blockCache != null && blockCache.BlockType != null)
                    {
                        foreach (var action in BlockCache.Read(block.Id).BlockType.SecurityActions)
                        {
                            if (block.SupportedActions.ContainsKey(action.Key))
                            {
                                block.SupportedActions[action.Key] = action.Value;
                            }
                            else
                            {
                                block.SupportedActions.Add(action.Key, action.Value);
                            }
                        }
                    }

                    iSecured = block;
                }

                if (iSecured != null)
                {
                    if (iSecured.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                    {
                        if (iSecured.SupportedActions.Any())
                        {
                            lActionDescription.Text = iSecured.SupportedActions.FirstOrDefault().Value;
                        }

                        rptActions.DataSource = iSecured.SupportedActions;
                        rptActions.DataBind();

                        rGrid.DataKeyNames        = new string[] { "Id" };
                        rGrid.GridReorder        += new GridReorderEventHandler(rGrid_GridReorder);
                        rGrid.GridRebind         += new GridRebindEventHandler(rGrid_GridRebind);
                        rGrid.RowDataBound       += new GridViewRowEventHandler(rGrid_RowDataBound);
                        rGrid.ShowHeaderWhenEmpty = false;
                        rGrid.EmptyDataText       = string.Empty;
                        rGrid.ShowActionRow       = false;

                        rGridParentRules.DataKeyNames        = new string[] { "Id" };
                        rGridParentRules.ShowHeaderWhenEmpty = false;
                        rGridParentRules.EmptyDataText       = string.Empty;
                        rGridParentRules.ShowActionRow       = false;

                        BindRoles();

                        string scriptFormat = @"
                    Sys.Application.add_load(function () {{
                        $('#modal-popup div.modal-header h3 small', window.parent.document).html('{0}');
                    }});
                ";
                        string script       = string.Format(scriptFormat, HttpUtility.JavaScriptStringEncode(iSecured.ToString()));

                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("set-html-{0}", this.ClientID), script, true);
                    }
                    else
                    {
                        nbMessage.Text = "Unfortunately, you are not able to edit security because you do not belong to a role that has been configured to allow administration of this item.";
                    }
                }
                else
                {
                    nbMessage.Text = "The item you are trying to secure does not exist or does not implement ISecured.";
                }
            }
            else
            {
                nbMessage.Text = string.Format("The requested entity type ('{0}') could not be loaded to determine security attributes.", entityTypeName);
            }

            base.OnInit(e);
        }
Exemple #20
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            List <int>  expandedPageIds = new List <int>();
            RockContext rockContext     = new RockContext();
            PageService pageService     = new PageService(rockContext);

            var allPages = pageService.Queryable("PageContexts, PageRoutes");

            foreach (var page in allPages)
            {
                PageCache.Read(page);
            }

            foreach (var block in new BlockService(rockContext).Queryable())
            {
                BlockCache.Read(block);
            }

            foreach (var blockType in new BlockTypeService(rockContext).Queryable())
            {
                BlockTypeCache.Read(blockType);
            }

            if (Page.IsPostBack)
            {
                foreach (string expandedId in hfExpandedIds.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    int id = 0;
                    if (expandedId.StartsWith("p") && expandedId.Length > 1)
                    {
                        if (int.TryParse(expandedId.Substring(1), out id))
                        {
                            expandedPageIds.Add(id);
                        }
                    }
                }
            }
            else
            {
                string pageSearch = this.PageParameter("pageSearch");
                if (!string.IsNullOrWhiteSpace(pageSearch))
                {
                    foreach (Page page in pageService.Queryable().Where(a => a.InternalName.IndexOf(pageSearch) >= 0))
                    {
                        Page selectedPage = page;
                        while (selectedPage != null)
                        {
                            selectedPage = selectedPage.ParentPage;
                            if (selectedPage != null)
                            {
                                expandedPageIds.Add(selectedPage.Id);
                            }
                        }
                    }
                }
            }

            var sb = new StringBuilder();

            sb.AppendLine("<ul id=\"treeview\">");

            string rootPage = GetAttributeValue("RootPage");

            if (!string.IsNullOrEmpty(rootPage))
            {
                Guid pageGuid = rootPage.AsGuid();
                allPages = allPages.Where(a => a.ParentPage.Guid == pageGuid);
            }
            else
            {
                allPages = allPages.Where(a => a.ParentPageId == null);
            }

            foreach (var page in allPages.OrderBy(a => a.Order).ThenBy(a => a.InternalName).Include(a => a.Blocks).ToList())
            {
                sb.Append(PageNode(PageCache.Read(page), expandedPageIds, rockContext));
            }

            sb.AppendLine("</ul>");

            lPages.Text = sb.ToString();
        }
Exemple #21
0
        protected override void OnInit(EventArgs e)
        {
            string entityParam = PageParameter("EntityTypeId");
            Type   type        = null;

            // Get Entity Type
            int entityTypeId = 0;

            if (Int32.TryParse(entityParam, out entityTypeId))
            {
                var entityType = EntityTypeCache.Read(entityTypeId);
                if (entityType != null)
                {
                    entityParam = entityType.FriendlyName;
                    type        = entityType.GetEntityType();
                }
            }

            // Get Entity Id
            int entityId = 0;

            if (!Int32.TryParse(PageParameter("EntityId"), out entityId))
            {
                entityId = 0;
            }

            // Get object type
            if (type != null)
            {
                if (entityId == 0)
                {
                    iSecured = (ISecured)Activator.CreateInstance(type);
                }
                else
                {
                    // Get the context type since this may be for a non-rock core object
                    Type contextType = null;
                    var  contexts    = Rock.Reflection.SearchAssembly(type.Assembly, typeof(System.Data.Entity.DbContext));
                    if (contexts.Any())
                    {
                        contextType = contexts.First().Value;
                    }

                    Type   serviceType = typeof(Rock.Data.Service <>);
                    Type[] modelType   = { type };
                    Type   service     = serviceType.MakeGenericType(modelType);
                    var    getMethod   = service.GetMethod("Get", new Type[] { typeof(int) });

                    if (contextType != null)
                    {
                        var context         = Activator.CreateInstance(contextType);
                        var serviceInstance = Activator.CreateInstance(service, new object[] { context });
                        iSecured = getMethod.Invoke(serviceInstance, new object[] { entityId }) as ISecured;
                    }
                    else
                    {
                        var serviceInstance = Activator.CreateInstance(service);
                        iSecured = getMethod.Invoke(serviceInstance, new object[] { entityId }) as ISecured;
                    }
                }

                var block = iSecured as Rock.Model.Block;
                if (block != null)
                {
                    // If the entity is a block, get the cachedblock's supported action, as the RockPage may have
                    // added additional actions when the cache was created.
                    foreach (var action in BlockCache.Read(block.Id).SupportedActions)
                    {
                        if (!block.SupportedActions.Contains(action))
                        {
                            block.SupportedActions.Add(action);
                        }
                    }

                    iSecured = block;
                }

                if (iSecured != null && iSecured.IsAuthorized("Administrate", CurrentPerson))
                {
                    rptActions.DataSource = iSecured.SupportedActions;
                    rptActions.DataBind();

                    rGrid.DataKeyNames        = new string[] { "id" };
                    rGrid.GridReorder        += new GridReorderEventHandler(rGrid_GridReorder);
                    rGrid.GridRebind         += new GridRebindEventHandler(rGrid_GridRebind);
                    rGrid.RowDataBound       += new GridViewRowEventHandler(rGrid_RowDataBound);
                    rGrid.ShowHeaderWhenEmpty = false;
                    rGrid.EmptyDataText       = string.Empty;
                    rGrid.ShowActionRow       = false;

                    rGridParentRules.DataKeyNames        = new string[] { "id" };
                    rGridParentRules.ShowHeaderWhenEmpty = false;
                    rGridParentRules.EmptyDataText       = string.Empty;
                    rGridParentRules.ShowActionRow       = false;

                    BindRoles();

                    string script = string.Format(@"
                    Sys.Application.add_load(function () {{
                        $('#modal-popup div.modal-header h3 small', window.parent.document).html('{0}');
                    }});
                ", HttpUtility.JavaScriptStringEncode(iSecured.ToString()));
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("set-html-{0}", this.ClientID), script, true);
                }
                else
                {
                    rGrid.Visible            = false;
                    rGridParentRules.Visible = false;
                    nbMessage.Text           = "Unfortunately, you are not able to edit security because you do not belong to a role that has been configured to allow administration of this item.";
                    nbMessage.Visible        = true;
                }
            }
            else
            {
                rGrid.Visible            = false;
                rGridParentRules.Visible = false;
                nbMessage.Text           = string.Format("The requested entity type ('{0}') could not be loaded to determine security attributes.", entityParam);
                nbMessage.Visible        = true;
            }
            base.OnInit(e);
        }
Exemple #22
0
 public Block Read(SharpMedia.Database.Physical.Caching.BlockType type, ulong address)
 {
     return(new Block(provider.Read(type, address)));
 }