Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
rudream committed Jan 30, 2025
1 parent e6c6124 commit ab213d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/types/semaphore.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const SemaphoreKindUploadCompleter = "upload_completer"

// SemaphoreKindAccessListReminderLimiter is the semaphore kind used by
// the periodic check which creates access list reminder notifications.
const SemaphoreKindAccessListReminderLimiter = "access_monitoring_limiter"
const SemaphoreKindAccessListReminderLimiter = "access_list_reminder_limiter"

// Semaphore represents distributed semaphore concept
type Semaphore interface {
Expand Down
31 changes: 18 additions & 13 deletions lib/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6232,15 +6232,13 @@ func (a *Server) CreateAccessListReminderNotifications(ctx context.Context) {
days int
prefix string
notificationSubkind string
title string
overdue bool
}{
{14, types.NotificationIdentifierPrefixAccessListDueReminder14d, types.NotificationAccessListReviewDue14dSubKind, "You have access lists due for review in less than 14 days.", false},
{7, types.NotificationIdentifierPrefixAccessListDueReminder7d, types.NotificationAccessListReviewDue7dSubKind, "You have access lists due for review in less than 7 days.", false},
{3, types.NotificationIdentifierPrefixAccessListDueReminder3d, types.NotificationAccessListReviewDue3dSubKind, "You have access lists due for review in less than 3 days.", false},
{0, types.NotificationIdentifierPrefixAccessListDueReminder0d, types.NotificationAccessListReviewDue0dSubKind, "You have access lists due for review today.", false},
{3, types.NotificationIdentifierPrefixAccessListOverdue3d, types.NotificationAccessListReviewOverdue3dSubKind, "You have access lists that are more than 3 days overdue for review.", true},
{7, types.NotificationIdentifierPrefixAccessListOverdue7d, types.NotificationAccessListReviewOverdue7dSubKind, "You have access lists that are more than 7 days overdue for review.", true},
{14, types.NotificationIdentifierPrefixAccessListDueReminder14d, types.NotificationAccessListReviewDue14dSubKind},
{7, types.NotificationIdentifierPrefixAccessListDueReminder7d, types.NotificationAccessListReviewDue7dSubKind},
{3, types.NotificationIdentifierPrefixAccessListDueReminder3d, types.NotificationAccessListReviewDue3dSubKind},
{0, types.NotificationIdentifierPrefixAccessListDueReminder0d, types.NotificationAccessListReviewDue0dSubKind},
{-3, types.NotificationIdentifierPrefixAccessListOverdue3d, types.NotificationAccessListReviewOverdue3dSubKind},
{-7, types.NotificationIdentifierPrefixAccessListOverdue7d, types.NotificationAccessListReviewOverdue7dSubKind},
}

for _, threshold := range reminderThresholds {
Expand All @@ -6252,7 +6250,7 @@ func (a *Server) CreateAccessListReminderNotifications(ctx context.Context) {
timeDiff := dueDate.Sub(now)
daysDiff := int(timeDiff.Hours() / 24)

if threshold.overdue {
if threshold.days < 0 {
if daysDiff <= -threshold.days {
relevantLists = append(relevantLists, al)
}
Expand Down Expand Up @@ -6307,13 +6305,20 @@ func (a *Server) CreateAccessListReminderNotifications(ctx context.Context) {
}
}
}
// Deduplicate the owners list.
slices.Sort(owners)
owners = slices.Compact(owners)
owners = apiutils.Deduplicate(owners)

var title string
if threshold.days == 0 {
title = "You have access lists due for review today."
} else if threshold.days < 0 {
title = fmt.Sprintf("You have access lists that are more than %d days overdue for review", -threshold.days)
} else {
title = fmt.Sprintf("You have access lists due for review in less than %d days.", threshold.days)
}

// Create the notification for this reminder treshold for all relevant owners.
if needsNotification {
err := a.createAccessListReminderNotification(ctx, owners, threshold.notificationSubkind, threshold.title)
err := a.createAccessListReminderNotification(ctx, owners, threshold.notificationSubkind, title)
if err != nil {
a.logger.WarnContext(ctx, "Failed to create access list reminder notification", "error", err)
}
Expand Down

0 comments on commit ab213d3

Please sign in to comment.