Skip to content

Commit

Permalink
+ (Group) Fixed issue with Group Requirement applying age classificat…
Browse files Browse the repository at this point in the history
…ion. (Fixes #5393)
  • Loading branch information
croske committed Apr 20, 2023
1 parent 9fd2e9b commit 3352ff8
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions Rock/Model/Group/GroupRequirement/GroupRequirement.Logic.cs
Expand Up @@ -80,17 +80,36 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
var result = personQry.Select( p => p.Id ).ToList().Select( a =>
new PersonGroupRequirementStatus
{
PersonId = Id,
PersonId = a,
GroupRequirement = this,
MeetsGroupRequirement = MeetsGroupRequirement.NotApplicable
} );

return result;
}

// Create a list of statuses so that not applicable status results can be included.
List<PersonGroupRequirementStatus> statusResults = new List<PersonGroupRequirementStatus>();

// If this GroupRequirement is not for 'All' age classifications, then calculate those statuses.
if ( this.AppliesToAgeClassification != AppliesToAgeClassification.All )
{
// If the requirement's Applies To Age Classification is not "All", filter the person query to the corresponding Age Classification.
// If the person's age classification we are comparing is not the one applied to this requirement,
// then mark that person's requirement status as 'Not Applicable'.
var notApplicablePersonQry = personQry.Where( p => ( int ) p.AgeClassification != ( int ) this.AppliesToAgeClassification );
var results = notApplicablePersonQry.Select( p => p.Id ).ToList().Select( a =>
new PersonGroupRequirementStatus
{
PersonId = a,
GroupRequirement = this,
MeetsGroupRequirement = MeetsGroupRequirement.NotApplicable
} );

if ( results != null )
{
statusResults.AddRange( results );
}

personQry = personQry.Where( p => ( int ) p.AgeClassification == ( int ) this.AppliesToAgeClassification );
}

Expand All @@ -102,20 +121,26 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
var appliesToDataViewWhereExpression = this.AppliesToDataView.GetExpression( appliesToDataViewPersonService, appliesToDataViewParamExpression );
var appliesToDataViewPersonIds = appliesToDataViewPersonService.Get( appliesToDataViewParamExpression, appliesToDataViewWhereExpression ).Select( p => p.Id );

// If the dataview does not contain anyone in the person query, return a "not applicable" status.
if ( !personQry.Where( p => appliesToDataViewPersonIds.Contains( p.Id ) ).Any() )
// If the dataview does not contain anyone in the person query, give the member a "not applicable" status.
var notApplicablePersonQry = personQry.Where( p => !appliesToDataViewPersonIds.Contains( p.Id ) );
{
var result = personQry.Select( p => p.Id ).ToList().Select( a =>
var results = notApplicablePersonQry.Select( p => p.Id ).ToList().Select( a =>
new PersonGroupRequirementStatus
{
PersonId = Id,
PersonId = a,
GroupRequirement = this,
MeetsGroupRequirement = MeetsGroupRequirement.NotApplicable
} );

return result;
if ( results != null )
{
statusResults.AddRange( results );
}

personQry = personQry.Where( p => appliesToDataViewPersonIds.Contains( p.Id ) );
}
}

var attributeValueService = new AttributeValueService( rockContext );

if ( this.GroupRequirementType.RequirementCheckType == RequirementCheckType.Dataview )
Expand Down Expand Up @@ -193,7 +218,12 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
return personGroupRequirementStatus;
} );

return result;
if ( result != null )
{
statusResults.AddRange( result );
}

return statusResults;
}
}
else
Expand All @@ -213,7 +243,12 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
return personGroupRequirementStatus;
} );

return result;
if ( result != null )
{
statusResults.AddRange( result );
}

return statusResults;
}
}
else if ( this.GroupRequirementType.RequirementCheckType == RequirementCheckType.Sql )
Expand Down Expand Up @@ -271,7 +306,12 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
return personGroupRequirementStatus;
} );

return result;
if ( result != null )
{
statusResults.AddRange( result );
}

return statusResults;
}
}
catch ( Exception ex )
Expand All @@ -287,7 +327,12 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
CalculationException = ex
} );

return result;
if ( result != null )
{
statusResults.AddRange( result );
}

return statusResults;
}
}
else
Expand Down Expand Up @@ -318,7 +363,12 @@ public IEnumerable<PersonGroupRequirementStatus> PersonQueryableMeetsGroupRequir
};
} );

return result;
if ( result != null )
{
statusResults.AddRange( result );
}

return statusResults;
}

// This shouldn't happen, since a requirement must have a dataview, SQL or manual origin.
Expand Down

0 comments on commit 3352ff8

Please sign in to comment.