/// <summary> /// Shows the detail. /// </summary> /// <param name="groupId">The group identifier.</param> public void ShowDetail(int personId) { var startDateTime = DateTime.SpecifyKind(RockDateTime.Now.AddYears(-10), DateTimeKind.Unspecified); hfStartDateTime.Value = startDateTime.ToString("o"); hfStopDateTime.Value = HistoricalTracking.MaxExpireDateTime.ToString("o"); hfPersonId.Value = personId.ToString(); List <int> groupTypeIds; if (gtGroupTypesFilter.SelectedGroupTypeIds.Any()) { // if group types are filtered on the user filter, use that groupTypeIds = gtGroupTypesFilter.SelectedGroupTypeIds; } else { // if no group types are selected in the user filter, restrict grouptypes to the ones in the block settings (if any) groupTypeIds = _blockSettingsGroupTypeIds; } hfGroupTypeIds.Value = groupTypeIds.AsDelimited(","); var legendGroupTypes = GroupTypeCache.All().Where(a => a.EnableGroupHistory); if (groupTypeIds.Any()) { legendGroupTypes = legendGroupTypes.Where(a => groupTypeIds.Contains(a.Id)); } rptGroupTypeLegend.DataSource = legendGroupTypes.OrderBy(a => a.Name); rptGroupTypeLegend.DataBind(); }
/// <summary> /// Binds the group type location grid. /// </summary> private void BindGroupTypeLocationGrid() { var groupTypeIds = rlbGroupTypes.SelectedValues.AsGuidList() ?? new List <Guid>(); var source = GroupTypeCache.All() .Where(gt => groupTypeIds.Contains(gt.Guid)) .ToList(); gGroupTypesLocationType.DataSource = source; gGroupTypesLocationType.DataBind(); rcwGroupTypesLocationType.Visible = source.Any(); }
/// <inheritdoc/> protected override void OnInit(EventArgs e) { base.OnInit(e); if (!IsPostBack) { GroupTypeCache.All() .ForEach(t => { rlbGroupTypes.Items.Add(new ListItem(t.Name, t.Guid.ToString())); }); } }
/// <summary> /// Applies the block settings. /// </summary> private void ApplyBlockSettings() { _blockSettingsGroupTypeIds = this.GetAttributeValue(AttributeKey.GroupTypes).SplitDelimitedValues().AsGuidList().Select(a => GroupTypeCache.Get(a)).Where(a => a != null).Select(a => a.Id).ToList(); IEnumerable <GroupTypeCache> groupTypes = GroupTypeCache.All(); if (_blockSettingsGroupTypeIds.Any()) { groupTypes = groupTypes.Where(a => _blockSettingsGroupTypeIds.Contains(a.Id)); } else { groupTypes = groupTypes.Where(a => a.EnableGroupHistory == true); } gtGroupTypesFilter.SetGroupTypes(groupTypes); }
/// <summary> /// Gets all checkin area that paths /// </summary> /// <returns></returns> public IEnumerable <CheckinAreaPath> GetAllCheckinAreaPaths() { List <CheckinAreaPath> result = new List <CheckinAreaPath>(); // limit to show only GroupTypes that have a group type purpose of Checkin Template int groupTypePurposeCheckInTemplateId = DefinedValueCache.Get(new Guid(Rock.SystemGuid.DefinedValue.GROUPTYPE_PURPOSE_CHECKIN_TEMPLATE)).Id; var checkinTemplates = GroupTypeCache.All().Where(a => a.GroupTypePurposeValueId == groupTypePurposeCheckInTemplateId).ToList(); foreach (var rootCheckinAreaGroupTypeId in checkinTemplates.Select(a => a.Id)) { var checkinAreaDescendantsPath = GetCheckinAreaDescendantsPath(rootCheckinAreaGroupTypeId); foreach (var checkinAreaDescendantPath in checkinAreaDescendantsPath) { // just in case multiple checkin areas share a child group type, check for duplicates var alreadyExists = result.Any(x => x.GroupTypeId == checkinAreaDescendantPath.GroupTypeId); if (!alreadyExists) { result.Add(checkinAreaDescendantPath); } } } return(result); }
/// <summary> /// Updates any Cache Objects that are associated with this entity /// </summary> /// <param name="entityState">State of the entity.</param> /// <param name="dbContext">The database context.</param> public void UpdateCache(EntityState entityState, Rock.Data.DbContext dbContext) { AttributeCache.UpdateCachedEntity(this.Id, entityState); AttributeCache.UpdateCacheEntityAttributes(this, entityState); int? entityTypeId; string entityTypeQualifierColumn; string entityTypeQualifierValue; if (entityState == EntityState.Deleted) { entityTypeId = originalEntityTypeId; entityTypeQualifierColumn = originalEntityTypeQualifierColumn; entityTypeQualifierValue = originalEntityTypeQualifierValue; } else { entityTypeId = this.EntityTypeId; entityTypeQualifierColumn = this.EntityTypeQualifierColumn; entityTypeQualifierValue = this.EntityTypeQualifierValue; } if ((!entityTypeId.HasValue || entityTypeId.Value == 0) && string.IsNullOrEmpty(entityTypeQualifierColumn) && string.IsNullOrEmpty(entityTypeQualifierValue)) { GlobalAttributesCache.Remove(); } if ((!entityTypeId.HasValue || entityTypeId.Value == 0) && entityTypeQualifierColumn == Attribute.SYSTEM_SETTING_QUALIFIER && string.IsNullOrEmpty(entityTypeQualifierValue)) { Rock.Web.SystemSettings.Remove(); } if (entityTypeId.HasValue) { if (entityTypeId == EntityTypeCache.GetId <Block>()) { // Update BlockTypes/Blocks that reference this attribute if (entityTypeQualifierColumn.Equals("BlockTypeId", StringComparison.OrdinalIgnoreCase)) { int?blockTypeId = entityTypeQualifierValue.AsIntegerOrNull(); if (blockTypeId.HasValue) { BlockTypeCache.FlushItem(blockTypeId.Value); foreach (var blockId in new BlockService(dbContext as RockContext).GetByBlockTypeId(blockTypeId.Value).Select(a => a.Id).ToList()) { BlockCache.FlushItem(blockId); } } } } else if (entityTypeId == EntityTypeCache.GetId <DefinedValue>()) { // Update DefinedTypes/DefinedValues that reference this attribute if (entityTypeQualifierColumn.Equals("DefinedTypeId", StringComparison.OrdinalIgnoreCase)) { int?definedTypeId = entityTypeQualifierValue.AsIntegerOrNull(); if (definedTypeId.HasValue) { DefinedTypeCache.FlushItem(definedTypeId.Value); foreach (var definedValueId in new DefinedValueService(dbContext as RockContext).GetByDefinedTypeId(definedTypeId.Value).Select(a => a.Id).ToList()) { DefinedValueCache.FlushItem(definedValueId); } } } } else if (entityTypeId == EntityTypeCache.GetId <WorkflowActivityType>()) { if (entityTypeQualifierColumn.Equals("ActivityTypeId", StringComparison.OrdinalIgnoreCase)) { int?activityTypeId = entityTypeQualifierValue.AsIntegerOrNull(); if (activityTypeId.HasValue) { WorkflowActivityTypeCache.FlushItem(activityTypeId.Value); } } } else if (entityTypeId == EntityTypeCache.GetId <GroupType>()) { if (entityTypeQualifierColumn.Equals("Id", StringComparison.OrdinalIgnoreCase)) { int?groupTypeId = entityTypeQualifierValue.AsIntegerOrNull(); if (groupTypeId.HasValue) { GroupTypeCache.FlushItem(groupTypeId.Value); } } else if (entityTypeQualifierColumn.Equals("GroupTypePurposeValueId", StringComparison.OrdinalIgnoreCase)) { int?groupTypePurposeValueId = entityTypeQualifierValue.AsIntegerOrNull(); if (groupTypePurposeValueId.HasValue) { foreach (var groupTypeId in GroupTypeCache.All().Where(a => a.GroupTypePurposeValueId == groupTypePurposeValueId.Value).Select(a => a.Id).ToList()) { GroupTypeCache.FlushItem(groupTypeId); } } } } else if (entityTypeId.HasValue) { // some other EntityType. If it the EntityType has a CacheItem associated with it, clear out all the CachedItems of that type to ensure they have a clean read of the Attributes that were Added, Changed or Removed EntityTypeCache entityType = EntityTypeCache.Get(entityTypeId.Value, dbContext as RockContext); if (entityType?.HasEntityCache() == true) { entityType.ClearCachedItems(); } } } }
/// <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 OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { SetAllowedGroupTypes(); if (string.IsNullOrWhiteSpace(_groupId)) { // If no group was selected, try to find the first group and redirect // back to current page with that group selected var group = FindFirstGroup(); { if (group != null) { _groupId = group.Id.ToString(); string redirectUrl = string.Empty; // redirect so that the group treeview has the first node selected right away and group detail shows the group if (hfPageRouteTemplate.Value.IndexOf("{groupId}", StringComparison.OrdinalIgnoreCase) >= 0) { redirectUrl = "~/" + hfPageRouteTemplate.Value.ReplaceCaseInsensitive("{groupId}", _groupId.ToString()); } else { if (this.Request.QueryString.Count == 0) { redirectUrl = this.Request.UrlProxySafe() + "?GroupId=" + _groupId.ToString(); } else { redirectUrl = this.Request.UrlProxySafe() + "&GroupId=" + _groupId.ToString(); } } this.Response.Redirect(redirectUrl, false); Context.ApplicationInstance.CompleteRequest(); } } } } bool canEditBlock = IsUserAuthorized(Authorization.EDIT); bool showAddChildGroupButton = false; if (!string.IsNullOrWhiteSpace(_groupId)) { string key = string.Format("Group:{0}", _groupId); var rockContext = new RockContext(); Group selectedGroup = RockPage.GetSharedItem(key) as Group; if (selectedGroup == null) { int id = _groupId.AsInteger(); selectedGroup = new GroupService(rockContext).Queryable("GroupType") .Where(g => g.Id == id) .FirstOrDefault(); RockPage.SaveSharedItem(key, selectedGroup); } // get the parents of the selected item so we can tell the treeview to expand those int? rootGroupId = hfRootGroupId.Value.AsIntegerOrNull(); List <string> parentIdList = new List <string>(); var group = selectedGroup; while (group != null) { if (!IsGroupTypeIncluded(group.GroupTypeId)) { group = null; selectedGroup = null; } else if (group.Id == rootGroupId) { // stop if we are at the root group group = null; } else { group = group.ParentGroup; } if (group != null) { if (!parentIdList.Contains(group.Id.ToString())) { parentIdList.Insert(0, group.Id.ToString()); } else { // The parent list already contains this node, so we have encountered a recursive loop. // Stop here and make the current node the root of the tree. group = null; } } } // also get any additional expanded nodes that were sent in the Post string postedExpandedIds = this.Request.Params["ExpandedIds"]; if (!string.IsNullOrWhiteSpace(postedExpandedIds)) { var postedExpandedIdList = postedExpandedIds.Split(',').ToList(); foreach (var id in postedExpandedIdList) { if (!parentIdList.Contains(id)) { parentIdList.Add(id); } } } if (selectedGroup != null) { var selectedGroupGroupType = GroupTypeCache.Get(selectedGroup.GroupTypeId); hfInitialGroupId.Value = selectedGroup.Id.ToString(); hfSelectedGroupId.Value = selectedGroup.Id.ToString(); // show the Add Child Group button if the selected Group's GroupType can have children and one or more of those child group types is allowed if (selectedGroupGroupType.AllowAnyChildGroupType || selectedGroupGroupType.ChildGroupTypes.Any(c => IsGroupTypeIncluded(c.Id))) { // if current person has Edit Auth on the block, then show the add child group button regardless of Group/GroupType security. // showAddChildGroupButton = canEditBlock; if (!showAddChildGroupButton) { // if block doesn't grant Edit auth, see if the person is authorized for the selected group showAddChildGroupButton = selectedGroup.IsAuthorized(Authorization.EDIT, CurrentPerson); if (!showAddChildGroupButton) { // if block doesn't grant Edit auth, and user isn't authorized for the selected group, // see if they have Edit auth on any of the child groups List <GroupTypeCache> allowedChildGroupTypes; if (selectedGroupGroupType.AllowAnyChildGroupType) { // If AllowAnyChildGroupType is enabled, check for Edit Auth on all GroupTypes allowedChildGroupTypes = GroupTypeCache.All().ToList(); } else { // If AllowAnyChildGroupType is not enabled, check for Edit Auth on the just the selected group's ChildGroupTypes allowedChildGroupTypes = selectedGroupGroupType.ChildGroupTypes; } foreach (var childGroupType in allowedChildGroupTypes) { if (childGroupType != null && childGroupType.IsAuthorized(Authorization.EDIT, CurrentPerson)) { showAddChildGroupButton = true; break; } } } } } } hfInitialGroupParentIds.Value = parentIdList.AsDelimited(","); } else { // let the Add button be visible if there is nothing selected (if authorized) lbAddGroupChild.Enabled = canEditBlock; } // NOTE that showAddChildGroupButton just controls if the button is shown. // The group detail block will take care of enforcing auth when they attempt to save a group. divAddGroup.Visible = canEditBlock || showAddChildGroupButton; lbAddGroupRoot.Enabled = canEditBlock; lbAddGroupChild.Enabled = showAddChildGroupButton; // disable add child group if no group is selected if (hfSelectedGroupId.ValueAsInt() == 0) { lbAddGroupChild.Enabled = false; } hfIncludeInactiveGroups.Value = (!tglHideInactiveGroups.Checked).ToTrueFalse(); hfLimitPublicGroups.Value = tglLimitPublicGroups.Checked.ToTrueFalse(); hfCountsType.Value = ddlCountsType.SelectedValue; hfCampusFilter.Value = ddlCampuses.SelectedValue; hfIncludeNoCampus.Value = tglIncludeNoCampus.Checked.ToTrueFalse(); }