akkounts/app/services/user_manager/update_pgp_key.rb
Râu Cao 3042a02a17
All checks were successful
continuous-integration/drone/push Build is passing
Allow users to update their OpenPGP pubkey
2024-09-23 18:13:39 +02:00

25 lines
572 B
Ruby

module UserManager
class UpdatePgpKey < UserManagerService
def initialize(user:)
@user = user
end
def call
if @user.pgp_pubkey.blank?
@user.update! pgp_fpr: nil
else
result = GPGME::Key.import(@user.pgp_pubkey)
if result.imports.present?
@user.update! pgp_fpr: result.imports.first.fpr
else
# TODO notify Sentry, user
raise "Failed to import OpenPGP pubkey"
end
end
LdapManager::UpdatePgpKey.call(dn: @user.dn, pubkey: @user.pgp_pubkey)
end
end
end