Skip to content

Commit

Permalink
+ (Finance) Fixed errors on the TransactionEntryV2 block that can occ…
Browse files Browse the repository at this point in the history
…ur when being used by a user that is not logged in. (Fixes #5474)
  • Loading branch information
ethan-sparkdevnetwork committed Jun 14, 2023
1 parent 51e6d99 commit f2a7255
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions RockWeb/Blocks/Finance/TransactionEntryV2.ascx.cs
Expand Up @@ -2240,27 +2240,16 @@ private bool SetInitialTargetPersonControls()
/// <returns></returns>
private Person GetTargetPerson( RockContext rockContext )
{
var targetPersonValue = Rock.Security.Encryption.DecryptString( ViewState[ViewStateKey.TargetPersonGuid] as string );
string personActionId = PageParameter( PageParameterKey.Person );
if ( personActionId.IsNullOrWhiteSpace() )
if ( personActionId.IsNullOrWhiteSpace() && targetPersonValue.IsNullOrWhiteSpace() )
{
// If there is no person action identifier, just use the currently logged in Person.
return CurrentPerson;
}

var targetPersonValue = Rock.Security.Encryption.DecryptString( ViewState[ViewStateKey.TargetPersonGuid] as string );
if ( targetPersonValue.IsNullOrWhiteSpace() )
{
return null;
}

var targetPersonGuid = targetPersonValue.AsGuidOrNull();
if ( targetPersonGuid == null )
{
return null;
}

var targetPerson = new PersonService( rockContext ).Get( targetPersonGuid.Value );
return targetPerson;
var targetPersonGuid = targetPersonValue?.AsGuidOrNull();
return targetPersonGuid != null ? new PersonService( rockContext ).Get( targetPersonGuid.Value ) : null;
}

/// <summary>
Expand Down Expand Up @@ -2518,11 +2507,18 @@ private void _updatePersonOrBusinessFromInputInformation( Person personOrBusines
private void BindPersonSavedAccounts()
{
ddlPersonSavedAccount.Visible = false;
var currentSavedAccountSelection = ddlPersonSavedAccount.SelectedValue;

ddlPersonSavedAccount.Items.Clear();
pnlSavedAccounts.Visible = false;

var rockContext = new RockContext();
var targetPerson = GetTargetPerson( rockContext );

// No person, no accounts
if ( targetPerson == null )
{
return;
}

var personSavedAccountsQuery = new FinancialPersonSavedAccountService( rockContext )
.GetByPersonId( targetPerson.Id )
.Where( a => !a.IsSystem )
Expand Down Expand Up @@ -2587,6 +2583,7 @@ private void BindPersonSavedAccounts()

ddlPersonSavedAccount.Items.Add( new ListItem( "Use a different payment method", 0.ToString() ) );

var currentSavedAccountSelection = ddlPersonSavedAccount.SelectedValue;
if ( currentSavedAccountSelection.IsNotNullOrWhiteSpace() )
{
ddlPersonSavedAccount.SetValue( currentSavedAccountSelection );
Expand Down Expand Up @@ -3100,7 +3097,7 @@ protected void ShowTransactionSummary()

// If target person does not have a login, have them create a UserName and password
var targetPerson = GetTargetPerson( rockContext );
var hasUserLogin = new UserLoginService( rockContext ).GetByPersonId( targetPerson.Id ).Any();
var hasUserLogin = targetPerson != null ? new UserLoginService( rockContext ).GetByPersonId( targetPerson.Id ).Any() : false;
pnlCreateLogin.Visible = !hasUserLogin;

NavigateToStep( EntryStep.ShowTransactionSummary );
Expand Down

0 comments on commit f2a7255

Please sign in to comment.