Skip to content

Commit 3b152ad

Browse files
authored
fix: add check for empty appeal duration (#376)
* refactor: add func to check if appeal duration is empty * fix: add check for empty appeal duration
1 parent 931558d commit 3b152ad

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

core/appeal/service.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
AuditKeyDeleteApprover = "appeal.deleteApprover"
2929

3030
RevokeReasonForExtension = "Automatically revoked for grant extension"
31+
PermanentDuration = "Permanent"
3132
)
3233

3334
var TimeNow = time.Now
@@ -785,6 +786,12 @@ func (s *Service) getPoliciesMap(ctx context.Context) (map[string]map[uint]*doma
785786
func getApprovalNotifications(appeal *domain.Appeal) []domain.Notification {
786787
notifications := []domain.Notification{}
787788
approval := appeal.GetNextPendingApproval()
789+
790+
duration := PermanentDuration
791+
if !appeal.IsDurationEmpty() {
792+
duration = appeal.Options.Duration
793+
}
794+
788795
if approval != nil {
789796
for _, approver := range approval.Approvers {
790797
notifications = append(notifications, domain.Notification{
@@ -804,7 +811,7 @@ func getApprovalNotifications(appeal *domain.Appeal) []domain.Notification {
804811
"approval_step": approval.Name,
805812
"actor": approver,
806813
"details": appeal.Details,
807-
"duration": appeal.Options.Duration,
814+
"duration": duration,
808815
},
809816
},
810817
})

domain/appeal.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ func (a *Appeal) Cancel() {
8383
func (a *Appeal) Approve() error {
8484
a.Status = AppealStatusApproved
8585

86-
if a.Options == nil || a.Options.Duration == "" {
87-
return nil
88-
}
89-
90-
duration, err := time.ParseDuration(a.Options.Duration)
86+
duration, err := a.GetDuration()
9187
if err != nil {
9288
return err
9389
}
@@ -102,6 +98,23 @@ func (a *Appeal) Approve() error {
10298
return nil
10399
}
104100

101+
func (a *Appeal) GetDuration() (time.Duration, error) {
102+
if a.IsDurationEmpty() {
103+
return 0 * time.Second, nil
104+
}
105+
106+
duration, err := time.ParseDuration(a.Options.Duration)
107+
if err != nil {
108+
return 0 * time.Second, err
109+
}
110+
111+
return duration, nil
112+
}
113+
114+
func (a *Appeal) IsDurationEmpty() bool {
115+
return a.Options == nil || a.Options.Duration == "" || a.Options.Duration == "0h"
116+
}
117+
105118
func (a *Appeal) Reject() {
106119
a.Status = AppealStatusRejected
107120
}

0 commit comments

Comments
 (0)