/// <summary>
        /// Gets the bread crumbs.
        /// </summary>
        /// <param name="pageReference">The page reference.</param>
        /// <returns></returns>
        public override List <BreadCrumb> GetBreadCrumbs(PageReference pageReference)
        {
            var breadCrumbs = new List <BreadCrumb>();
            int?sectionId   = PageParameter(pageReference, PageParameterKey.SectionId).AsIntegerOrNull();

            if (sectionId != null)
            {
                string sectionName = new PersonalLinkSectionService(new RockContext())
                                     .Queryable().Where(b => b.Id == sectionId.Value)
                                     .Select(b => b.Name)
                                     .FirstOrDefault();

                if (!string.IsNullOrWhiteSpace(sectionName))
                {
                    breadCrumbs.Add(new BreadCrumb($"{sectionName.FixCase()} Link Section", pageReference));
                }
                else
                {
                    breadCrumbs.Add(new BreadCrumb("New Section", pageReference));
                }
            }
            else
            {
                // don't show a breadcrumb if we don't have a pageparam to work with
            }

            return(breadCrumbs);
        }
        /// <summary>
        /// Queries the database for all ids with context.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private static List <string> QueryDbForAllIds(RockContext rockContext)
        {
            var service = new PersonalLinkSectionService(rockContext);

            return(service.Queryable()
                   .Where(a => a.IsShared)
                   .Select(i => i.Id)
                   .ToList()
                   .ConvertAll(i => i.ToString()));
        }
Example #3
0
        /// <summary>
        /// Handles the Edit event of the gSectionList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gSectionList_Edit(object sender, RowEventArgs e)
        {
            var section = new PersonalLinkSectionService(new RockContext()).Get(e.RowKeyId);

            if (section == null)
            {
                return;
            }

            if (section.IsAuthorized(Rock.Security.Authorization.EDIT, this.CurrentPerson))
            {
                NavigateToLinkedPage(AttributeKey.DetailPage, PageParameterKey.SectionId, e.RowKeyId);
            }
        }
Example #4
0
        /// <summary>
        /// Get the personal link section
        /// </summary>
        /// <returns></returns>
        private PersonalLinkSection GetPersonalLinkSection(RockContext rockContext = null)
        {
            rockContext = rockContext ?? new RockContext();
            var personalLinkSectionService = new PersonalLinkSectionService(rockContext);

            var sectionId = PageParameter(PageParameterKey.SectionId).AsIntegerOrNull();

            if (!sectionId.HasValue)
            {
                return(null);
            }

            return(personalLinkSectionService.Queryable().FirstOrDefault(a => a.Id == sectionId.Value));
        }
 /// <summary>
 /// Handles the Click event of the btnCancel 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 btnCancel_Click(object sender, EventArgs e)
 {
     if (hfPersonalLinkSectionId.Value.Equals("0"))
     {
         // Canceling on Add
         Dictionary <string, string> qryString = new Dictionary <string, string>();
         qryString[PageParameterKey.SectionId] = hfPersonalLinkSectionId.Value;
         NavigateToParentPage(qryString);
     }
     else
     {
         var personalLinkSection = new PersonalLinkSectionService(new RockContext()).Get(hfPersonalLinkSectionId.Value.AsInteger());
         ShowReadonlyDetails(personalLinkSection);
     }
 }
        /// <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);
        }
Example #7
0
        /// <summary>
        /// Handles the Delete event of the gSectionList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gSectionList_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            var personalLinkSectionService = new PersonalLinkSectionService(rockContext);
            var personalLinkSection        = personalLinkSectionService.Get(e.RowKeyId);

            if (personalLinkSection != null)
            {
                string errorMessage;
                if (!personalLinkSectionService.CanDelete(personalLinkSection, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                personalLinkSectionService.Delete(personalLinkSection);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        /// <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);
        }
        /// <summary>
        /// Handles the Click event of the btnEdit 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 btnEdit_Click(object sender, EventArgs e)
        {
            var personalLinkSection = new PersonalLinkSectionService(new RockContext()).Get(hfPersonalLinkSectionId.Value.AsInteger());

            ShowEditDetails(personalLinkSection);
        }
Example #11
0
        /// <summary>
        /// Gets the grid data source list (ordered)
        /// </summary>
        /// <returns>List&lt;PersonalLinkSectionViewModel&gt;.</returns>
        private List <PersonalLinkSectionViewModel> GetGridDataSourceList(RockContext rockContext)
        {
            var limitToSharedSections = GetAttributeValue(AttributeKey.SharedSections).AsBoolean();
            List <PersonalLinkSection> personalLinkSectionList;
            Dictionary <int, PersonalLinkSectionOrder> currentPersonSectionOrderLookupBySectionId = null;

            if (limitToSharedSections)
            {
                // only show shared sections in this mode
                var sharedPersonalLinkSectionsQuery = new PersonalLinkSectionService(rockContext).Queryable().Where(a => a.IsShared);
                personalLinkSectionList = sharedPersonalLinkSectionsQuery.Include(a => a.PersonalLinks).OrderBy(a => a.Name).AsNoTracking().ToList();
            }
            else
            {
                // show both shared and non-shared, but don't let shared sections get deleted (even if authorized)
                var personalLinkService = new PersonalLinkService(rockContext);
                if (personalLinkService.AddMissingPersonalLinkSectionOrders(this.CurrentPerson))
                {
                    rockContext.SaveChanges();
                }

                var orderedPersonalLinkSectionsQuery = new PersonalLinkService(rockContext).GetOrderedPersonalLinkSectionsQuery(this.CurrentPerson);

                personalLinkSectionList = orderedPersonalLinkSectionsQuery
                                          .Include(a => a.PersonalLinks)
                                          .AsNoTracking()
                                          .ToList()
                                          .Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson))
                                          .ToList();

                // NOTE: We might be making changes when resorting this, so don't use AsNoTracking()
                var sectionOrderQuery = personalLinkService.GetSectionOrderQuery(this.CurrentPerson);
                currentPersonSectionOrderLookupBySectionId = sectionOrderQuery.ToDictionary(k => k.SectionId, v => v);
            }

            gSectionList.EntityTypeId = EntityTypeCache.GetId <PersonalLinkSection>();

            var viewModelList = personalLinkSectionList.Select(a =>
            {
                var personalLinkSectionViewModel = new PersonalLinkSectionViewModel
                {
                    Id        = a.Id,
                    Name      = a.Name,
                    LinkCount = a.PersonalLinks.Where(x => x.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson)).Count(),
                    IsShared  = a.IsShared,
                    PersonalLinkSectionOrder = currentPersonSectionOrderLookupBySectionId?.GetValueOrNull(a.Id)
                };

                if (limitToSharedSections)
                {
                    // if we are only showing shared sections, let them edit it if authorized edit
                    personalLinkSectionViewModel.CanEdit = a.IsAuthorized(Authorization.EDIT, CurrentPerson);
                }
                else
                {
                    // Don't allow shared sections to be deleted/edited if we showing both shared and non-shared sections
                    personalLinkSectionViewModel.CanEdit = !a.IsShared;
                }

                personalLinkSectionViewModel.CanDelete = personalLinkSectionViewModel.CanEdit;

                return(personalLinkSectionViewModel);
            }).ToList();

            return(viewModelList.OrderBy(a => a.PersonalLinkSectionOrder?.Order ?? 0).ThenBy(a => a.Name).ToList());
        }