/// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="personalLinkSection">The personal link section.</param>
        public void ShowEditDetails(PersonalLinkSection personalLinkSection)
        {
            if (personalLinkSection.Id == 0)
            {
                lActionTitle.Text = ActionTitle.Add(PANEL_NAME);
                hlShared.Visible  = GetAttributeValue(AttributeKey.SharedSection).AsBoolean();
            }
            else
            {
                lActionTitle.Text = personalLinkSection.Name.FormatAsHtmlTitle() + PANEL_NAME;
                hlShared.Visible  = personalLinkSection.IsShared;
            }

            SetEditMode(true);

            tbName.Text = personalLinkSection.Name;
        }
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="personalLinkSection">The personal link section.</param>
        private void ShowReadonlyDetails(PersonalLinkSection personalLinkSection)
        {
            SetEditMode(false);

            if (personalLinkSection == null)
            {
                return;
            }

            lActionTitle.Text = personalLinkSection.Name.FormatAsHtmlTitle() + PANEL_NAME;

            var descriptionList = new DescriptionList();

            descriptionList.Add("Name", personalLinkSection.Name);
            lDescription.Text = descriptionList.Html;
            hlShared.Visible  = personalLinkSection.IsShared;
        }
예제 #3
0
        /// <summary>
        /// Save the section.
        /// </summary>
        private int SaveSection(string sectionName)
        {
            var rockContext = new RockContext();
            var personalLinkSectionService = new PersonalLinkSectionService(rockContext);
            var personalLinkSection        = new PersonalLinkSection()
            {
                Id            = 0,
                IsShared      = false,
                PersonAliasId = CurrentPersonAliasId.Value,
                Name          = sectionName
            };

            personalLinkSectionService.Add(personalLinkSection);
            rockContext.SaveChanges();

            personalLinkSection.MakePrivate(Authorization.VIEW, CurrentPerson, rockContext);
            personalLinkSection.MakePrivate(Authorization.EDIT, CurrentPerson, rockContext);
            personalLinkSection.MakePrivate(Authorization.ADMINISTRATE, CurrentPerson, rockContext);
            return(personalLinkSection.Id);
        }
예제 #4
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);

            _personalLinkSection = GetPersonalLinkSection();
            if (_personalLinkSection != null)
            {
                gfFilter.ApplyFilterClick   += gfFilter_ApplyFilterClick;
                gfFilter.ClearFilterClick   += gfFilter_ClearFilterClick;
                gfFilter.DisplayFilterValue += gfFilter_DisplayFilterValue;

                gLinkList.DataKeyNames = new string[] { "Id" };

                // anybody can add a non-shared link
                // EDIT auth users can add shared link
                gLinkList.Actions.ShowAdd = true;

                // edit and delete buttons will be enabled/disabled per row based on security
                gLinkList.IsDeleteEnabled = true;

                gLinkList.Actions.AddClick += gLinkList_Add;
                gLinkList.GridReorder      += gLinkList_GridReorder;
                gLinkList.GridRebind       += gLinkList_GridRebind;

                if (_personalLinkSection.IsShared)
                {
                    lTitle.Text = ("Links for " + _personalLinkSection.Name).FormatAsHtmlTitle();
                }
                else
                {
                    lTitle.Text = ("Personal Links for " + _personalLinkSection.Name).FormatAsHtmlTitle();
                }
            }

            // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it
            this.BlockUpdated += Block_BlockUpdated;
            this.AddConfigurationUpdateTrigger(upPanel);
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="personalLinkSectionId">The personal link section element identifier.</param>
        public void ShowDetail(int personalLinkSectionId)
        {
            var rockContext = new RockContext();
            var personalLinkSectionService          = new PersonalLinkSectionService(rockContext);
            PersonalLinkSection personalLinkSection = null;
            bool isNew = false;

            if (!personalLinkSectionId.Equals(0))
            {
                personalLinkSection = personalLinkSectionService.Get(personalLinkSectionId);
            }

            if (personalLinkSection == null)
            {
                personalLinkSection = new PersonalLinkSection {
                    Id = 0
                };
                isNew = true;
            }

            hfPersonalLinkSectionId.SetValue(personalLinkSection.Id);

            if (personalLinkSection != null && personalLinkSection.IsAuthorized(Authorization.VIEW, CurrentPerson))
            {
                hfPersonalLinkSectionId.Value = personalLinkSection.Id.ToString();

                bool readOnly    = false;
                bool editAllowed = isNew || personalLinkSection.IsAuthorized(Authorization.EDIT, CurrentPerson);
                nbEditModeMessage.Text = string.Empty;

                if (!editAllowed)
                {
                    readOnly = true;
                    nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(ContentChannel.FriendlyTypeName);
                }

                if (readOnly)
                {
                    btnEdit.Visible = false;
                    ShowReadonlyDetails(personalLinkSection);
                }
                else
                {
                    btnEdit.Visible = true;
                    if (personalLinkSection.Id > 0)
                    {
                        ShowReadonlyDetails(personalLinkSection);
                    }
                    else
                    {
                        ShowEditDetails(personalLinkSection);
                    }
                }

                btnSecurity.Visible  = personalLinkSection.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);
                btnSecurity.Title    = personalLinkSection.Name;
                btnSecurity.EntityId = personalLinkSection.Id;

                btnSave.Visible = !readOnly;
            }
            else
            {
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToView(ContentChannel.FriendlyTypeName);
                pnlEditDetails.Visible = false;
                pnlViewDetails.Visible = false;
                this.HideSecondaryBlocks(true);
            }
        }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var rockContext = new RockContext();
            var personalLinkSectionService          = new PersonalLinkSectionService(rockContext);
            var personalLinkSectionId               = hfPersonalLinkSectionId.Value.AsIntegerOrNull();
            PersonalLinkSection personalLinkSection = null;

            if (personalLinkSectionId.HasValue)
            {
                personalLinkSection = personalLinkSectionService.Get(personalLinkSectionId.Value);
            }

            var isNew = personalLinkSection == null;

            if (isNew)
            {
                var isShared = GetAttributeValue(AttributeKey.SharedSection).AsBoolean();
                personalLinkSection = new PersonalLinkSection()
                {
                    Id       = 0,
                    IsShared = isShared
                };

                if (!isShared)
                {
                    personalLinkSection.PersonAliasId = CurrentPersonAliasId.Value;
                }

                personalLinkSectionService.Add(personalLinkSection);
            }

            personalLinkSection.Name = tbName.Text;
            rockContext.SaveChanges();

            personalLinkSection = personalLinkSectionService.Get(personalLinkSection.Id);
            if (personalLinkSection != null)
            {
                if (personalLinkSection.IsShared)
                {
                    var groupService = new GroupService(rockContext);

                    var communicationAdministrators = groupService.Get(Rock.SystemGuid.Group.GROUP_COMMUNICATION_ADMINISTRATORS.AsGuid());
                    if (communicationAdministrators != null)
                    {
                        personalLinkSection.AllowSecurityRole(Authorization.VIEW, communicationAdministrators, rockContext);
                        personalLinkSection.AllowSecurityRole(Authorization.EDIT, communicationAdministrators, rockContext);
                        personalLinkSection.AllowSecurityRole(Authorization.ADMINISTRATE, communicationAdministrators, rockContext);
                    }

                    var webAdministrators = groupService.Get(Rock.SystemGuid.Group.GROUP_WEB_ADMINISTRATORS.AsGuid());
                    if (webAdministrators != null)
                    {
                        personalLinkSection.AllowSecurityRole(Authorization.VIEW, webAdministrators, rockContext);
                        personalLinkSection.AllowSecurityRole(Authorization.EDIT, webAdministrators, rockContext);
                        personalLinkSection.AllowSecurityRole(Authorization.ADMINISTRATE, webAdministrators, rockContext);
                    }

                    var rockAdministrators = groupService.Get(Rock.SystemGuid.Group.GROUP_ADMINISTRATORS.AsGuid());
                    if (rockAdministrators != null)
                    {
                        personalLinkSection.AllowSecurityRole(Authorization.VIEW, rockAdministrators, rockContext);
                        personalLinkSection.AllowSecurityRole(Authorization.EDIT, rockAdministrators, rockContext);
                        personalLinkSection.AllowSecurityRole(Authorization.ADMINISTRATE, rockAdministrators, rockContext);
                    }
                }
                else
                {
                    personalLinkSection.MakePrivate(Authorization.VIEW, CurrentPerson);
                    personalLinkSection.MakePrivate(Authorization.EDIT, CurrentPerson, rockContext);
                    personalLinkSection.MakePrivate(Authorization.ADMINISTRATE, CurrentPerson, rockContext);
                }
            }

            var pageReference = RockPage.PageReference;

            pageReference.Parameters.AddOrReplace(PageParameterKey.SectionId, personalLinkSection.Id.ToString());
            Response.Redirect(pageReference.BuildUrl(), false);
        }