Merge commit from fork

* Streaming: Ensure disabled users cannot connect to streaming

* Streaming: Disconnect when the user is disabled

---------

Co-authored-by: Emelia Smith <ThisIsMissEm@users.noreply.github.com>
This commit is contained in:
Claire 2025-10-13 14:19:14 +02:00 committed by GitHub
parent 5226b757fe
commit 4bd193cdfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View file

@ -180,6 +180,10 @@ class User < ApplicationRecord
def disable!
update!(disabled: true)
# This terminates all connections for the given account with the streaming
# server:
redis.publish("timeline:system:#{account.id}", Oj.dump(event: :kill))
end
def enable!

View file

@ -448,12 +448,15 @@ RSpec.describe User do
let(:current_sign_in_at) { Time.zone.now }
before do
user.disable!
end
it 'disables user' do
allow(redis).to receive(:publish)
user.disable!
expect(user).to have_attributes(disabled: true)
expect(redis)
.to have_received(:publish).with("timeline:system:#{user.account.id}", Oj.dump(event: :kill)).once
end
end

View file

@ -459,7 +459,7 @@ const startServer = async () => {
return;
}
client.query('SELECT oauth_access_tokens.id, oauth_access_tokens.resource_owner_id, users.account_id, users.chosen_languages, oauth_access_tokens.scopes, devices.device_id FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id LEFT OUTER JOIN devices ON oauth_access_tokens.id = devices.access_token_id WHERE oauth_access_tokens.token = $1 AND oauth_access_tokens.revoked_at IS NULL LIMIT 1', [token], (err, result) => {
client.query('SELECT oauth_access_tokens.id, oauth_access_tokens.resource_owner_id, users.account_id, users.chosen_languages, oauth_access_tokens.scopes, devices.device_id FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id LEFT OUTER JOIN devices ON oauth_access_tokens.id = devices.access_token_id WHERE oauth_access_tokens.token = $1 AND oauth_access_tokens.revoked_at IS NULL AND users.disabled IS FALSE LIMIT 1', [token], (err, result) => {
done();
if (err) {