Notify user about new RS authorizations
This commit is contained in:
@@ -245,44 +245,69 @@ RSpec.describe RemoteStorageAuthorization, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
# describe "auth notifications" do
|
||||
# context "with auth notifications enabled" do
|
||||
# before do
|
||||
# ResqueSpec.reset!
|
||||
# user.push(mailing_lists: "rs-auth-notifications-#{Rails.env}")
|
||||
# auth = user.remote_storage_authorizations.create!(
|
||||
# :permissions => %w(documents photos contacts:rw videos:r tasks/work:r),
|
||||
# :client_id => "example.com",
|
||||
# :redirect_uri => "https://example.com"
|
||||
# )
|
||||
# end
|
||||
#
|
||||
# it "notifies the user via email" do
|
||||
# expect(enqueued_jobs.size).to eq(1)
|
||||
# job = enqueued_jobs.first
|
||||
# expect(job).to eq(
|
||||
# job: ActionMailer::DeliveryJob,
|
||||
# args: ['StorageAuthorizationMailer', 'authorized_rs_app', 'deliver_now',
|
||||
# auth.id.to_s],
|
||||
# queue: 'mailers'
|
||||
# )
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# context "with auth notifications disabled" do
|
||||
# before do
|
||||
# ResqueSpec.reset!
|
||||
# user.pull(mailing_lists: "rs-auth-notifications-#{Rails.env}")
|
||||
# auth = user.remote_storage_authorizations.create!(
|
||||
# :permissions => %w(documents photos contacts:rw videos:r tasks/work:r),
|
||||
# :client_id => "example.com",
|
||||
# :redirect_uri => "https://example.com"
|
||||
# )
|
||||
# end
|
||||
#
|
||||
# it "does not notify the user via email about new RS app" do
|
||||
# expect(enqueued_jobs.size).to eq(0)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe "notifications" do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
after(:each) { clear_enqueued_jobs }
|
||||
after(:all) { redis_rs_delete_keys("authorizations:*") }
|
||||
|
||||
before { allow(user).to receive(:display_name).and_return("Jimmy") }
|
||||
|
||||
context "with notifications disabled" do
|
||||
before do
|
||||
user.preferences.merge!({ remotestorage_notify_auth_created: "off" })
|
||||
user.save!
|
||||
user.remote_storage_authorizations.create!(
|
||||
:permissions => %w(photos), :client_id => "app.example.com",
|
||||
:redirect_uri => "https://app.example.com"
|
||||
)
|
||||
end
|
||||
|
||||
it "does not notify the user via email about new RS app" do
|
||||
expect(enqueued_jobs.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "with email notifications enabled" do
|
||||
before do
|
||||
user.preferences.merge!({ remotestorage_notify_auth_created: "email" })
|
||||
user.save!
|
||||
user.remote_storage_authorizations.create!(
|
||||
:permissions => %w(photos), :client_id => "app.example.com",
|
||||
:redirect_uri => "https://app.example.com"
|
||||
)
|
||||
end
|
||||
|
||||
it "notifies the user via email" do
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
job = enqueued_jobs.select{|j| j['job_class'] == "ActionMailer::MailDeliveryJob"}.first
|
||||
expect(job['arguments'][0]).to eq('NotificationMailer')
|
||||
expect(job['arguments'][1]).to eq('remotestorage_auth_created')
|
||||
expect(job['arguments'][3]['params']['user']['_aj_globalid']).to eq('gid://akkounts/User/1')
|
||||
expect(job['arguments'][3]['params']['auth']['_aj_globalid']).to eq('gid://akkounts/RemoteStorageAuthorization/1')
|
||||
end
|
||||
end
|
||||
|
||||
context "with XMPP notifications enabled" do
|
||||
before do
|
||||
Setting.xmpp_notifications_from_address = "botka@kosmos.org"
|
||||
user.preferences.merge!({ remotestorage_notify_auth_created: "xmpp" })
|
||||
user.save!
|
||||
user.remote_storage_authorizations.create!(
|
||||
:permissions => %w(photos), :client_id => "app.example.com",
|
||||
:redirect_uri => "https://app.example.com"
|
||||
)
|
||||
end
|
||||
|
||||
it "sends an XMPP message to the account owner's JID" do
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
expect(enqueued_jobs.first["job_class"]).to eq("XmppSendMessageJob")
|
||||
msg = enqueued_jobs.first["arguments"].first
|
||||
expect(msg["type"]).to eq("normal")
|
||||
expect(msg["from"]).to eq("botka@kosmos.org")
|
||||
expect(msg["to"]).to eq(user.address)
|
||||
expect(msg["body"]).to match(/granted 'app\.example\.com' access to your Kosmos Storage/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user