Skip to content

Commit bd05a01

Browse files
Chief-Rishabravisuhag
authored andcommitted
feat(appeal): add variables to approver notification message
1 parent 9bab6ad commit bd05a01

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

cli/job.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ func runJobCmd() *cobra.Command {
4040
Short: "Fire a specific job",
4141
Example: heredoc.Doc(`
4242
$ guardian job run fetch_resources
43-
$ guardian job run grant_expiration_reminder
44-
$ guardian job run grant_expiration_revocation
43+
$ guardian job run expiring_grant_notification
44+
$ guardian job run revoke_expired_grants
45+
$ guardian job run revoke_grants_by_user_criteria
4546
`),
4647
Args: cobra.ExactValidArgs(1),
4748
ValidArgs: []string{

core/appeal/service.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,14 @@ func (s *Service) AddApprover(ctx context.Context, appealID, approvalID, email s
663663
s.logger.Error("failed to record audit log", "error", err)
664664
}
665665

666+
duration := domain.PermanentDurationLabel
667+
if !appeal.IsDurationEmpty() {
668+
duration, err = utils.GetReadableDuration(appeal.Options.Duration)
669+
if err != nil {
670+
s.logger.Error("failed to get readable duration", "error", err, "appeal_id", appeal.ID)
671+
}
672+
}
673+
666674
if errs := s.notifier.Notify([]domain.Notification{
667675
{
668676
User: email,
@@ -677,6 +685,15 @@ func (s *Service) AddApprover(ctx context.Context, appealID, approvalID, email s
677685
"requestor": appeal.CreatedBy,
678686
"appeal_id": appeal.ID,
679687
"account_id": appeal.AccountID,
688+
"account_type": appeal.AccountType,
689+
"provider_type": appeal.Resource.ProviderType,
690+
"resource_type": appeal.Resource.Type,
691+
"created_at": appeal.CreatedAt,
692+
"approval_step": approval.Name,
693+
"actor": email,
694+
"details": appeal.Details,
695+
"duration": duration,
696+
"creator": appeal.Creator,
680697
},
681698
},
682699
},
@@ -873,6 +890,7 @@ func (s *Service) getApprovalNotifications(appeal *domain.Appeal) []domain.Notif
873890
"actor": approver,
874891
"details": appeal.Details,
875892
"duration": duration,
893+
"creator": appeal.Creator,
876894
},
877895
},
878896
})

plugins/notifiers/slack/client_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,26 @@ func (s *ClientTestSuite) TestNotify() {
7474

7575
func (s *ClientTestSuite) TestParseMessage() {
7676
s.setup()
77+
s.messages = domain.NotificationMessages{
78+
ApproverNotification: "[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"You have an appeal created by *{{.requestor}}* requesting access to *{{.resource_name}}* with role *{{.role}}*. User's manager: {{.creator.manager_email}} and belongs to {{.creator.org_name}}.\\n Appeal ID: *{{.appeal_id}}*\"}}]",
79+
}
7780
s.Run("should be able to parse message", func() {
81+
creator := map[string]interface{}{
82+
"manager_email": "user-manager@example.com",
83+
"org_name": "test-org",
84+
}
85+
7886
notificationMsg := domain.NotificationMessage{
79-
Type: domain.NotificationTypeAppealRejected,
87+
Type: domain.NotificationTypeApproverNotification,
8088
Variables: map[string]interface{}{
8189
"resource_name": "test-resource",
8290
"role": "test-role",
91+
"creator": creator,
92+
"appeal_id": "test-appeal-id",
93+
"requestor": "test-user",
8394
},
8495
}
85-
expectedMsg := `[{"type":"section","text":{"type":"mrkdwn","text":"Your appeal to test-resource with role test-role has been rejected"}}]`
96+
expectedMsg := `[{"type":"section","text":{"type":"mrkdwn","text":"You have an appeal created by *test-user* requesting access to *test-resource* with role *test-role*. User's manager: user-manager@example.com and belongs to test-org.\n Appeal ID: *test-appeal-id*"}}]`
8697
message, err := slack.ParseMessage(notificationMsg, s.messages, embed.FS{})
8798

8899
s.Nil(err)

0 commit comments

Comments
 (0)