Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,26 @@ public async Task ExecutePostUpsertSideEffectAsync(
Policy postUpsertedPolicyState,
Policy? previousPolicyState)
{
var policyUpdate = policyRequest.PolicyUpdate;
var organizationId = policyRequest.PolicyUpdate.OrganizationId;

// Step 1: sync DisableSend.Enabled -> SendControlsPolicy.Data.DisableSend
var sendControlsPolicy = await policyRepository.GetByOrganizationIdTypeAsync(
policyUpdate.OrganizationId, PolicyType.SendControls) ?? new Policy
organizationId, PolicyType.SendControls) ?? new Policy
{
Id = CoreHelpers.GenerateComb(),
OrganizationId = policyUpdate.OrganizationId,
OrganizationId = organizationId,
Type = PolicyType.SendControls,
};

var sendOptionsPolicy = await policyRepository.GetByOrganizationIdTypeAsync(
policyUpdate.OrganizationId, PolicyType.SendOptions) ?? new Policy
{
Id = CoreHelpers.GenerateComb(),
OrganizationId = policyUpdate.OrganizationId,
Type = PolicyType.SendOptions,
};

var sendControlsPolicyData =
sendControlsPolicy.GetDataModel<SendControlsPolicyData>();

var sendOptionsPolicyData = sendOptionsPolicy.GetDataModel<SendOptionsPolicyData>();

var sendControlsPolicyData = sendControlsPolicy.GetDataModel<SendControlsPolicyData>();
sendControlsPolicyData.DisableSend = postUpsertedPolicyState.Enabled;
sendControlsPolicyData.DisableHideEmail = sendOptionsPolicy.Enabled && sendOptionsPolicyData.DisableHideEmail;
sendControlsPolicy.Enabled = sendControlsPolicyData.DisableSend || sendControlsPolicyData.DisableHideEmail;
sendControlsPolicy.SetDataModel(sendControlsPolicyData);

// Step 2: sync Enabled status. SendControlsPolicy is enabled if either legacy policy is enabled
sendControlsPolicy.Enabled = postUpsertedPolicyState.Enabled ||
((await policyRepository.GetByOrganizationIdTypeAsync(
organizationId, PolicyType.SendOptions))?.Enabled ?? false);

await policyRepository.UpsertAsync(sendControlsPolicy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ public async Task ExecutePostUpsertSideEffectAsync(
Policy postUpsertedPolicyState,
Policy? previousPolicyState)
{
var policyUpdate = policyRequest.PolicyUpdate;
var organizationId = policyRequest.PolicyUpdate.OrganizationId;

// Step 1: sync SendOptionsPolicy.Data.DisableSend -> SendControlsPolicy.Data.DisableSend
var sendControlsPolicy = await policyRepository.GetByOrganizationIdTypeAsync(
policyUpdate.OrganizationId, PolicyType.SendControls) ?? new Policy
organizationId, PolicyType.SendControls) ?? new Policy
{
Id = CoreHelpers.GenerateComb(),
OrganizationId = policyUpdate.OrganizationId,
OrganizationId = organizationId,
Type = PolicyType.SendControls,
};

var sendControlsPolicyData =
sendControlsPolicy.GetDataModel<SendControlsPolicyData>();

var disableSendPolicyState = await policyRepository.GetByOrganizationIdTypeAsync(
policyUpdate.OrganizationId, PolicyType.DisableSend);

sendControlsPolicyData.DisableSend = disableSendPolicyState?.Enabled ?? false;
sendControlsPolicyData.DisableHideEmail = postUpsertedPolicyState.Enabled && postUpsertedPolicyState.GetDataModel<SendOptionsPolicyData>().DisableHideEmail;
sendControlsPolicy.Enabled = sendControlsPolicyData.DisableSend || sendControlsPolicyData.DisableHideEmail;
var sendControlsPolicyData = sendControlsPolicy.GetDataModel<SendControlsPolicyData>();
sendControlsPolicyData.DisableHideEmail = postUpsertedPolicyState.GetDataModel<SendOptionsPolicyData>().DisableHideEmail;
sendControlsPolicy.SetDataModel(sendControlsPolicyData);

// Step 2: sync Enabled status. SendControlsPolicy is enabled if either legacy policy is enabled
// Optimization: DisableSendPolicy.Enabled maps to SendControlsPolicy.Data.DisableSend - so we can use that
// as a proxy for that legacy policy state
sendControlsPolicy.Enabled = postUpsertedPolicyState.Enabled ||
sendControlsPolicyData.DisableSend;

Comment on lines +41 to +45
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization is not required if it's confusing. It could just follow the exact same pattern as the other file.

await policyRepository.UpsertAsync(sendControlsPolicy);
}
}
Loading