summaryrefslogtreecommitdiff
path: root/app/services/keys
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
commit9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch)
tree70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/services/keys
parent4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff)
downloadgitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'app/services/keys')
-rw-r--r--app/services/keys/base_service.rb3
-rw-r--r--app/services/keys/create_service.rb3
-rw-r--r--app/services/keys/expiry_notification_service.rb42
3 files changed, 46 insertions, 2 deletions
diff --git a/app/services/keys/base_service.rb b/app/services/keys/base_service.rb
index 113e22b01ce..9b238e2f176 100644
--- a/app/services/keys/base_service.rb
+++ b/app/services/keys/base_service.rb
@@ -5,7 +5,8 @@ module Keys
attr_accessor :user, :params
def initialize(user, params = {})
- @user, @params = user, params
+ @user = user
+ @params = params
@ip_address = @params.delete(:ip_address)
end
diff --git a/app/services/keys/create_service.rb b/app/services/keys/create_service.rb
index c256de7b35d..c1c3ef8792f 100644
--- a/app/services/keys/create_service.rb
+++ b/app/services/keys/create_service.rb
@@ -5,7 +5,8 @@ module Keys
attr_accessor :current_user
def initialize(current_user, params = {})
- @current_user, @params = current_user, params
+ @current_user = current_user
+ @params = params
@ip_address = @params.delete(:ip_address)
@user = params.delete(:user) || current_user
end
diff --git a/app/services/keys/expiry_notification_service.rb b/app/services/keys/expiry_notification_service.rb
new file mode 100644
index 00000000000..b486f77ced2
--- /dev/null
+++ b/app/services/keys/expiry_notification_service.rb
@@ -0,0 +1,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