Skip to content

Commit 6af3d98

Browse files
authored
Merge pull request #33 from hasanpeal/develop
Fixed duplicate notifications
2 parents 7d40e0e + 55cb6c6 commit 6af3d98

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

server/Services/VaultService.cs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ public async Task<VaultResponseDTO> CreateVaultAsync(CreateVaultDTO dto, string
285285
// Check if release status changed from non-released to released
286286
if (oldReleaseStatus != ReleaseStatus.Released && vault.Policy.ReleaseStatus == ReleaseStatus.Released)
287287
{
288-
// Send notification to all vault members
288+
// Send email notification to all vault members
289+
// Note: Database trigger automatically creates notifications, so we only send emails here
289290
try
290291
{
291292
var members = await _dbContext.VaultMembers
@@ -302,15 +303,6 @@ await _emailService.SendVaultReleasedNotificationAsync(
302303
member.User.UserName ?? member.User.Email,
303304
vault.Name
304305
);
305-
306-
// Save notification (trigger also creates one, but this ensures it's created)
307-
await _notificationService.CreateNotificationAsync(
308-
member.User.Id,
309-
"Vault Released",
310-
$"The vault \"{vault.Name}\" has been released and is now accessible.",
311-
"VaultReleased",
312-
vaultId: vaultId
313-
);
314306
}
315307
}
316308
}
@@ -1422,7 +1414,8 @@ private async Task<bool> IsVaultAccessibleAsync(VaultPolicy policy)
14221414
policy.ReleasedAt = DateTime.UtcNow;
14231415
await _dbContext.SaveChangesAsync();
14241416

1425-
// Send notification to all vault members if status just changed to released
1417+
// Send email notification to all vault members if status just changed to released
1418+
// Note: Database trigger automatically creates notifications, so we only send emails here
14261419
if (!wasReleased)
14271420
{
14281421
try
@@ -1446,15 +1439,6 @@ await _emailService.SendVaultReleasedNotificationAsync(
14461439
member.User.UserName ?? member.User.Email,
14471440
vault.Name
14481441
);
1449-
1450-
// Save notification (trigger also creates one, but this ensures it's created)
1451-
await _notificationService.CreateNotificationAsync(
1452-
member.User.Id,
1453-
"Vault Released",
1454-
$"The vault \"{vault.Name}\" has been released and is now accessible.",
1455-
"VaultReleased",
1456-
vaultId: policy.VaultId
1457-
);
14581442
}
14591443
}
14601444
}
@@ -1612,6 +1596,8 @@ public async Task<bool> ReleaseVaultManuallyAsync(int vaultId, string userId)
16121596
vault.Policy.ReleaseStatus = ReleaseStatus.Released;
16131597
vault.Policy.ReleasedAt = DateTime.UtcNow;
16141598
vault.Policy.ReleasedById = userId;
1599+
// Change PolicyType to Immediate when vault is released
1600+
vault.Policy.PolicyType = PolicyType.Immediate;
16151601

16161602
await _dbContext.SaveChangesAsync();
16171603

@@ -1626,7 +1612,8 @@ public async Task<bool> ReleaseVaultManuallyAsync(int vaultId, string userId)
16261612
_dbContext.VaultLogs.Add(vaultLog);
16271613
await _dbContext.SaveChangesAsync();
16281614

1629-
// Send notification to all vault members
1615+
// Send email notification to all vault members
1616+
// Note: Database trigger automatically creates notifications, so we only send emails here
16301617
try
16311618
{
16321619
var members = await _dbContext.VaultMembers
@@ -1643,15 +1630,6 @@ await _emailService.SendVaultReleasedNotificationAsync(
16431630
member.User.UserName ?? member.User.Email,
16441631
vault.Name
16451632
);
1646-
1647-
// Save notification (trigger also creates one, but this ensures it's created)
1648-
await _notificationService.CreateNotificationAsync(
1649-
member.User.Id,
1650-
"Vault Released",
1651-
$"The vault \"{vault.Name}\" has been released and is now accessible.",
1652-
"VaultReleased",
1653-
vaultId: vaultId
1654-
);
16551633
}
16561634
}
16571635
}

0 commit comments

Comments
 (0)