/// <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); // 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(upnlContent); canCheckInOnly = GetAttributeValue("CanCheckInOnly").AsBoolean(); ownerRoleGuid = GetAttributeValue("GroupType/RoleFilter").AsGuidOrNull() ?? Guid.Empty; // The 'owner' of the group is determined by built-in KnownRelationshipsOwner role or the role that is marked as IsLeader for the group var ownerRole = new GroupTypeRoleService(new RockContext()).Get(ownerRoleGuid); if (ownerRole != null) { ownerRole.LoadAttributes(); IsInverseRelationshipsOwner = ownerRole.Attributes.ContainsKey("InverseRelationship") && (ownerRole.Guid.Equals(Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid()) || ownerRole.IsLeader); } else { IsInverseRelationshipsOwner = false; } }
/// <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); ownerRoleGuid = GetAttributeValue("GroupType/RoleFilter").AsGuidOrNull() ?? Guid.Empty; // The 'owner' of the group is determined by built-in KnownRelationshipsOwner role or the role that is marked as IsLeader for the group var ownerRole = new GroupTypeRoleService(new RockContext()).Get(ownerRoleGuid); if (ownerRole != null) { ownerRole.LoadAttributes(); IsInverseRelationshipsOwner = ownerRole.Attributes.ContainsKey("InverseRelationship") && (ownerRole.Guid.Equals(Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid()) || ownerRole.IsLeader); } else { IsInverseRelationshipsOwner = false; } rGroupMembers.ItemDataBound += rGroupMembers_ItemDataBound; rGroupMembers.ItemCommand += rGroupMembers_ItemCommand; modalAddPerson.SaveClick += modalAddPerson_SaveClick; modalAddPerson.OnCancelScript = string.Format("$('#{0}').val('');", hfRoleId.ClientID); CanEdit = IsUserAuthorized(Authorization.EDIT); lbAdd.Visible = CanEdit && IsInverseRelationshipsOwner; string script = @" $('a.remove-relationship').click(function(){ return confirm('Are you sure you want to remove this relationship?'); }); "; ScriptManager.RegisterStartupScript(rGroupMembers, rGroupMembers.GetType(), "ConfirmRemoveRelationship", script, true); }
/// <summary> /// Binds the data. /// </summary> private void BindData() { ShowRole = GetAttributeValue("ShowRole").AsBoolean(); if (person != null && person.Id > 0) { if (ownerRoleGuid != Guid.Empty) { using (var rockContext = new RockContext()) { var memberService = new GroupMemberService(rockContext); var group = memberService.Queryable(true) .Where(m => m.PersonId == person.Id && m.GroupRole.Guid == ownerRoleGuid) .Select(m => m.Group) .FirstOrDefault(); if (group != null) { lGroupName.Text = group.Name.Pluralize(); lGroupTypeIcon.Text = string.Format("<i class='{0}'></i>", group.GroupType.IconCssClass); lGroupTypeIcon.Visible = !string.IsNullOrWhiteSpace(group.GroupType.IconCssClass); if (group.IsAuthorized(Authorization.VIEW, CurrentPerson)) { int?maxRelationshipsToDisplay = this.GetAttributeValue("MaxRelationshipsToDisplay").AsIntegerOrNull(); var roles = new List <int>(); if (canCheckInOnly) { foreach (var role in new GroupTypeRoleService(rockContext) .Queryable().AsNoTracking() .Where(r => r.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS)))) { role.LoadAttributes(rockContext); if (role.Attributes.ContainsKey("CanCheckin")) { bool canCheckIn = false; if (bool.TryParse(role.GetAttributeValue("CanCheckin"), out canCheckIn) && canCheckIn) { roles.Add(role.Id); } } if (role.Attributes.ContainsKey("InverseRelationship")) { var inverseRoleGuid = role.GetAttributeValue("InverseRelationship").AsGuidOrNull(); if (inverseRoleGuid != null) { var groupTypeRole = new GroupTypeRoleService(rockContext) .Queryable().AsNoTracking() .FirstOrDefault(r => r.Guid.Equals(( Guid )inverseRoleGuid)); if (groupTypeRole != null) { groupTypeRole.LoadAttributes(rockContext); if (groupTypeRole.Attributes.ContainsKey("CanCheckin")) { bool canCheckIn = false; if (bool.TryParse(groupTypeRole.GetAttributeValue("CanCheckin"), out canCheckIn) && canCheckIn) { roles.Add(role.Id); } } } } } } } else { foreach (var role in new GroupTypeRoleService(rockContext) .Queryable().AsNoTracking() .Where(r => r.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS)))) { roles.Add(role.Id); } } IQueryable <GroupMember> qryGroupMembers = new GroupMemberService(rockContext).GetByGroupId(group.Id, true) .Where(m => m.PersonId != person.Id) .Where(m => roles.Contains(m.GroupRoleId)) .OrderBy(m => m.Person.LastName) .ThenBy(m => m.Person.FirstName); if (maxRelationshipsToDisplay.HasValue) { qryGroupMembers = qryGroupMembers.Take(maxRelationshipsToDisplay.Value); } rGroupMembers.ItemDataBound += rptrMembers_ItemDataBound; rGroupMembers.DataSource = qryGroupMembers.ToList(); rGroupMembers.DataBind(); } else { lAccessWarning.Text = string.Format("<div class='alert alert-info'>You do not have security rights to view {0}.", group.Name.Pluralize()); } } } } } }