Merge commit 'f79b96a5ef0f6c4f57eee7f44ce2579b28a22098' into glitch-soc/merge-upstream

Conflicts:
- `app/lib/feed_manager.rb`:
  Not a real conflict, but glitch-soc has an extra `populate_direct_feed` method.
  Added upstream's code.
- `app/models/user_settings.rb`:
  Not a real conflict, glitch-soc has an extra setting textually-adjacent to a
  setting added upstream.
  Added upstream's setting.
- `app/serializers/initial_state_serializer.rb`:
  Same.
- `app/services/precompute_feed_service.rb`:
  Not a real conflict, glitch-soc has extra code for the direct feed.
  Added upstream's new code for populating lists.
This commit is contained in:
Claire committed 2025-02-01 19:07:13 +01:00
commit c85616ee3a
92 files changed
+767 -328

No files matched your search

@@ -1,125 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::ReportsController do
render_views
let(:user) { Fabricate(:admin_user) }
before do
sign_in user, scope: :user
end
describe 'GET #index' do
it 'returns http success with no filters' do
specified = Fabricate(:report, action_taken_at: nil, comment: 'First report')
other = Fabricate(:report, action_taken_at: Time.now.utc, comment: 'Second report')
get :index
expect(response).to have_http_status(200)
expect(response.body)
.to include(specified.comment)
.and not_include(other.comment)
end
it 'returns http success with resolved filter' do
specified = Fabricate(:report, action_taken_at: Time.now.utc, comment: 'First report')
other = Fabricate(:report, action_taken_at: nil, comment: 'Second report')
get :index, params: { resolved: '1' }
expect(response).to have_http_status(200)
expect(response.body)
.to include(specified.comment)
.and not_include(other.comment)
end
end
describe 'GET #show' do
it 'renders report' do
report = Fabricate(:report, comment: 'A big problem')
get :show, params: { id: report }
expect(response).to have_http_status(200)
expect(response.body)
.to include(report.comment)
end
describe 'account moderation notes' do
let(:report) { Fabricate(:report) }
it 'includes moderation notes' do
note1 = Fabricate(:report_note, report: report)
note2 = Fabricate(:report_note, report: report)
get :show, params: { id: report }
expect(response).to have_http_status(200)
report_notes = assigns(:report_notes).to_a
expect(report_notes.size).to be 2
expect(report_notes).to eq [note1, note2]
end
end
end
describe 'POST #resolve' do
it 'resolves the report' do
report = Fabricate(:report)
put :resolve, params: { id: report }
expect(response).to redirect_to(admin_reports_path)
report.reload
expect(report.action_taken_by_account).to eq user.account
expect(report.action_taken?).to be true
expect(last_action_log.target).to eq(report)
end
end
describe 'POST #reopen' do
it 'reopens the report' do
report = Fabricate(:report, action_taken_at: 3.days.ago)
put :reopen, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.action_taken_by_account).to be_nil
expect(report.action_taken?).to be false
expect(last_action_log.target).to eq(report)
end
end
describe 'POST #assign_to_self' do
it 'reopens the report' do
report = Fabricate(:report)
put :assign_to_self, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.assigned_account).to eq user.account
expect(last_action_log.target).to eq(report)
end
end
describe 'POST #unassign' do
it 'reopens the report' do
report = Fabricate(:report, assigned_account_id: Account.last.id)
put :unassign, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.assigned_account).to be_nil
expect(last_action_log.target).to eq(report)
end
end
private
def last_action_log
Admin::ActionLog.last
end
end
@@ -1,102 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Auth::PasswordsController do
include Devise::Test::ControllerHelpers
describe 'GET #new' do
it 'returns http success' do
request.env['devise.mapping'] = Devise.mappings[:user]
get :new
expect(response).to have_http_status(200)
end
end
describe 'GET #edit' do
let(:user) { Fabricate(:user) }
before do
request.env['devise.mapping'] = Devise.mappings[:user]
end
context 'with valid reset_password_token' do
it 'returns http success' do
token = user.send_reset_password_instructions
get :edit, params: { reset_password_token: token }
expect(response).to have_http_status(200)
end
end
context 'with invalid reset_password_token' do
it 'redirects to #new' do
get :edit, params: { reset_password_token: 'some_invalid_value' }
expect(response).to redirect_to subject.new_password_path(subject.send(:resource_name))
end
end
end
describe 'POST #update' do
let(:user) { Fabricate(:user) }
let(:password) { 'reset0password' }
before do
request.env['devise.mapping'] = Devise.mappings[:user]
end
context 'with valid reset_password_token' do
let!(:session_activation) { Fabricate(:session_activation, user: user) }
let!(:access_token) { Fabricate(:access_token, resource_owner_id: user.id) }
let!(:web_push_subscription) { Fabricate(:web_push_subscription, access_token: access_token) }
before do
token = user.send_reset_password_instructions
post :update, params: { user: { password: password, password_confirmation: password, reset_password_token: token } }
end
it 'resets the password' do
expect(response)
.to redirect_to '/auth/sign_in'
# Change password
expect(User.find(user.id))
.to be_present
.and be_valid_password(password)
# Deactivate session
expect(user.session_activations.count)
.to eq 0
expect { session_activation.reload }
.to raise_error(ActiveRecord::RecordNotFound)
# Revoke tokens
expect(Doorkeeper::AccessToken.active_for(user).count)
.to eq 0
# Remove push subs
expect(Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count)
.to eq 0
expect { web_push_subscription.reload }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with invalid reset_password_token' do
before do
post :update, params: { user: { password: password, password_confirmation: password, reset_password_token: 'some_invalid_value' } }
end
it 'renders reset password and retains password' do
expect(response)
.to render_template(:new)
expect(User.find(user.id))
.to be_present
.and be_external_or_valid_password(user.password)
end
end
end
end
+2 -2
View File
@@ -153,7 +153,7 @@ RSpec.describe 'Notifications' do
it 'returns a notification group covering all notifications' do
subject
notification_ids = user.account.notifications.reload.pluck(:id)
notification_ids = user.account.notifications.order(id: :asc).pluck(:id)
expect(response).to have_http_status(200)
expect(response.content_type)
@@ -175,7 +175,7 @@ RSpec.describe 'Notifications' do
it 'returns a notification group covering all notifications' do
subject
notification_ids = user.account.notifications.reload.pluck(:id)
notification_ids = user.account.notifications.order(id: :asc).pluck(:id)
expect(response).to have_http_status(200)
expect(response.content_type)
+34
View File
@@ -0,0 +1,34 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Auth Passwords' do
describe 'GET /auth/password/edit' do
context 'with invalid reset_password_token' do
it 'redirects to #new' do
get edit_user_password_path, params: { reset_password_token: 'some_invalid_value' }
expect(response)
.to redirect_to new_user_password_path
end
end
end
describe 'PUT /auth/password' do
let(:user) { Fabricate(:user) }
let(:password) { 'reset0password' }
context 'with invalid reset_password_token' do
it 'renders reset password and retains password' do
put user_password_path, params: { user: { password: password, password_confirmation: password, reset_password_token: 'some_invalid_value' } }
expect(response.body)
.to include(I18n.t('auth.set_new_password'))
expect(User.find(user.id))
.to be_present
.and be_external_or_valid_password(user.password)
end
end
end
end
+56 -18
View File
@@ -7,31 +7,69 @@ RSpec.describe PrecomputeFeedService do
describe 'call' do
let(:account) { Fabricate(:account) }
let!(:list) { Fabricate(:list, account: account, exclusive: false) }
it 'fills a user timeline with statuses' do
account = Fabricate(:account)
status = Fabricate(:status, account: account)
context 'when no eligible status exist' do
it 'raises no error and results in an empty timeline' do
expect { subject.call(account) }.to_not raise_error
subject.call(account)
expect(redis.zscore(FeedManager.instance.key(:home, account.id), status.id)).to be_within(0.1).of(status.id.to_f)
expect(redis.zcard(FeedManager.instance.key(:home, account.id))).to eq(0)
end
end
it 'does not raise an error even if it could not find any status' do
account = Fabricate(:account)
expect { subject.call(account) }.to_not raise_error
end
context 'with eligible statuses' do
let(:muted_account) { Fabricate(:account) }
let!(:followed_account) { Fabricate(:account) }
let!(:requested_account) { Fabricate(:account) }
let!(:own_status) { Fabricate(:status, account: account) }
let!(:followed_status) { Fabricate(:status, account: followed_account) }
let!(:unreadable_dm_from_followed) { Fabricate(:status, account: followed_account, visibility: :direct) }
let!(:requested_status) { Fabricate(:status, account: requested_account) }
let!(:muted_status) { Fabricate(:status, account: muted_account) }
let!(:muted_reblog) { Fabricate(:status, account: followed_account, reblog: muted_status) }
let!(:known_reply) { Fabricate(:status, account: followed_account, in_reply_to_id: own_status.id) }
let!(:unknown_reply) { Fabricate(:status, account: followed_account, in_reply_to_id: requested_status.id) }
it 'filters statuses' do
account = Fabricate(:account)
muted_account = Fabricate(:account)
Fabricate(:mute, account: account, target_account: muted_account)
reblog = Fabricate(:status, account: muted_account)
Fabricate(:status, account: account, reblog: reblog)
before do
account.follow!(followed_account)
account.request_follow!(requested_account)
account.mute!(muted_account)
subject.call(account)
AddAccountsToListService.new.call(list, [followed_account])
end
expect(redis.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to be_nil
it "fills a user's home and list timelines with the expected posts" do
subject.call(account)
home_timeline_ids = redis.zrevrangebyscore(FeedManager.instance.key(:home, account.id), '(+inf', '(-inf', limit: [0, 30], with_scores: true).map { |id| id.first.to_i }
list_timeline_ids = redis.zrevrangebyscore(FeedManager.instance.key(:list, list.id), '(+inf', '(-inf', limit: [0, 30], with_scores: true).map { |id| id.first.to_i }
expect(home_timeline_ids).to include(
own_status.id,
followed_status.id,
known_reply.id
)
expect(list_timeline_ids).to include(
followed_status.id
)
expect(home_timeline_ids).to_not include(
requested_status.id,
unknown_reply.id,
unreadable_dm_from_followed.id,
muted_status.id,
muted_reblog.id
)
expect(list_timeline_ids).to_not include(
requested_status.id,
unknown_reply.id,
unreadable_dm_from_followed.id,
muted_status.id,
muted_reblog.id
)
end
end
end
end
+112
View File
@@ -0,0 +1,112 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Admin Reports' do
let(:user) { Fabricate(:admin_user) }
before { sign_in(user) }
describe 'Viewing existing reports' do
let!(:unresolved_report) { Fabricate(:report, action_taken_at: nil, comment: 'First report') }
let!(:resolved_report) { Fabricate(:report, action_taken_at: Time.now.utc, comment: 'Second report') }
let!(:report_note) { Fabricate :report_note, report: resolved_report, content: 'Note about resolved report' }
it 'Shows basic report details' do
visit admin_reports_path
expect(page)
.to have_content(unresolved_report.comment)
.and have_no_content(resolved_report.comment)
click_on I18n.t('admin.reports.resolved')
expect(page)
.to have_content(resolved_report.comment)
.and have_no_content(unresolved_report.comment)
click_on resolved_report.comment
expect(page)
.to have_title(I18n.t('admin.reports.report', id: resolved_report.id))
.and have_content(resolved_report.comment)
.and have_content(report_note.content)
end
end
describe 'Resolving reports' do
let!(:report) { Fabricate :report }
it 'resolves an open report' do
visit admin_report_path(report)
within '.content__heading__actions' do
click_on I18n.t('admin.reports.mark_as_resolved')
end
expect(page)
.to have_title(I18n.t('admin.reports.title'))
.and have_content(I18n.t('admin.reports.resolved_msg'))
report.reload
expect(report.action_taken_by_account)
.to eq user.account
expect(report)
.to be_action_taken
expect(last_action_log.target)
.to eq(report)
end
end
describe 'Reopening reports' do
let!(:report) { Fabricate :report, action_taken_at: 3.days.ago }
it 'reopens a resolved report' do
visit admin_report_path(report)
within '.content__heading__actions' do
click_on I18n.t('admin.reports.mark_as_unresolved')
end
expect(page)
.to have_title(I18n.t('admin.reports.report', id: report.id))
report.reload
expect(report.action_taken_by_account)
.to be_nil
expect(report)
.to_not be_action_taken
expect(last_action_log.target)
.to eq(report)
end
end
describe 'Assigning reports' do
let!(:report) { Fabricate :report }
it 'assigns report to user and then unassigns' do
visit admin_report_path(report)
click_on I18n.t('admin.reports.assign_to_self')
expect(page)
.to have_title(I18n.t('admin.reports.report', id: report.id))
report.reload
expect(report.assigned_account)
.to eq user.account
expect(last_action_log.target)
.to eq(report)
click_on I18n.t('admin.reports.unassign')
expect(page)
.to have_title(I18n.t('admin.reports.report', id: report.id))
report.reload
expect(report.assigned_account)
.to be_nil
expect(last_action_log.target)
.to eq(report)
end
end
private
def last_action_log
Admin::ActionLog.last
end
end
+83
View File
@@ -0,0 +1,83 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Auth Passwords' do
let(:user) { Fabricate :user }
let!(:session_activation) { Fabricate(:session_activation, user: user) }
let!(:access_token) { Fabricate(:access_token, resource_owner_id: user.id) }
let!(:web_push_subscription) { Fabricate(:web_push_subscription, access_token: access_token) }
describe 'Resetting a password', :inline_jobs do
let(:new_password) { 'New.Pass.123' }
before { allow(Devise).to receive(:pam_authentication).and_return(false) } # Avoid the "seamless external" path
it 'initiates reset, sends link, resets password from form, clears data' do
visit new_user_password_path
expect(page)
.to have_title(I18n.t('auth.reset_password'))
submit_email_reset
expect(page)
.to have_title(I18n.t('auth.set_new_password'))
set_new_password
expect(page)
.to have_title(I18n.t('auth.login'))
# Change password
expect(User.find(user.id))
.to be_present
.and be_valid_password(new_password)
# Deactivate session
expect(user_session_count)
.to eq(0)
expect { session_activation.reload }
.to raise_error(ActiveRecord::RecordNotFound)
# Revoke tokens
expect(user_token_count)
.to eq(0)
# Remove push subs
expect(push_subs_count)
.to eq(0)
expect { web_push_subscription.reload }
.to raise_error(ActiveRecord::RecordNotFound)
end
def submit_email_reset
fill_in 'user_email', with: user.email
click_on I18n.t('auth.reset_password')
open_last_email
visit_in_email(I18n.t('devise.mailer.reset_password_instructions.action'))
end
def set_new_password
fill_in 'user_password', with: new_password
fill_in 'user_password_confirmation', with: new_password
click_on I18n.t('auth.set_new_password')
end
def user_session_count
user
.session_activations
.count
end
def user_token_count
Doorkeeper::AccessToken
.active_for(user)
.count
end
def push_subs_count
Web::PushSubscription
.where(user: user)
.or(Web::PushSubscription.where(access_token: access_token))
.count
end
end
end