blob: b486f77ced2339dc2f522a6ddf6df5f84167e94d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# frozen_string_literal: true
module Keys
class ExpiryNotificationService < ::Keys::BaseService
attr_accessor :keys, :expiring_soon
def initialize(user, params)
@keys = params[:keys]
@expiring_soon = params[:expiring_soon]
super
end
def execute
return unless allowed?
if expiring_soon
trigger_expiring_soon_notification
else
trigger_expired_notification
end
end
private
def allowed?
user.can?(:receive_notifications)
end
def trigger_expiring_soon_notification
notification_service.ssh_key_expiring_soon(user, keys.map(&:fingerprint))
keys.update_all(before_expiry_notification_delivered_at: Time.current.utc)
end
def trigger_expired_notification
notification_service.ssh_key_expired(user, keys.map(&:fingerprint))
keys.update_all(expiry_notification_delivered_at: Time.current.utc)
end
end
end
|